Code: char *ptr; char myString[] = "abcdefg"; ptr = myString; ptr += 5; What string does ptr point to in the sample code above?

  1. efg

  2. cdefg

  3. fg

  4. None of the above


Correct Option: C
Explanation:

To solve this question, the user needs to understand the concept of pointers in C programming. In this case, ptr is a pointer variable that points to the first character of the myString array. The statement ptr += 5 increments the pointer by 5, so that it now points to the sixth character in the array.

Option A is incorrect because ptr is pointing to the sixth character in the array, not the third.

Option B is incorrect because ptr is pointing to the sixth character in the array, not the first.

Option C is correct because ptr is pointing to the sixth character in the array, which is "f", and continues to the end of the string, "g". Therefore, the string that ptr points to is "fg".

Option D is incorrect because an answer was provided above.

Therefore, the answer is: C. fg

Find more quizzes: