C | String | Question 6

#include<stdio.h>
int main()
{
    char str[] = "GeeksQuiz";
    printf("%s %s %s\n", &str[5], &5[str], str+5);
    printf("%c %c %c\n", *(str+6), str[6], 6[str]);
    return 0;
}

(A) Runtime Error
(B) Compiler Error
(C) uiz uiz uiz
u u u
(D) Quiz Quiz Quiz
u u u


Answer: (D)

Explanation: The program has no error. All of the following expressions mean same thing
&str[5]
&5[str]
str+5
Since compiler converts the array operation in pointers before accessing the array elements, all above result in same address.

Similarly, all of the following expressions mean same thing.
*(str+6)
str[6]
6[str]



My Personal Notes arrow_drop_up



Practice Tags :
Article Tags :
Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.

Recommended Posts:



3 Average Difficulty : 3/5.0
Based on 1 vote(s)






User Actions