Difficulty: Easy
Correct Answer: Hello
Explanation:
Introduction / Context:In C, a pointer declared as const char * may point to a character array, and you are allowed to move the pointer and read characters through it; the const qualifier forbids writing through the pointer, not reassigning the pointer itself. This question checks understanding of pointer iteration over a NUL-terminated string using a simple while loop that stops at the terminating '\0'.
Given Data / Assumptions:
Concept / Approach:
Step-by-Step Solution:
Start: s points to 'H' → print 'H', advance to 'e'.Next: print 'e', advance to 'l'.Then: print 'l', advance to second 'l'.Then: print 'l', advance to 'o'.Finally: print 'o', advance to '\0' → loop ends.Verification / Alternative check:
Replacing the loop with puts(str) would also print 'Hello' followed by a newline; our loop prints without adding a newline.Why Other Options Are Wrong:
Common Pitfalls:
Final Answer:
Hello
Discussion & Comments