C | String | Question 6

filter_none

edit
close

play_arrow

link
brightness_4
code

#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;
}

chevron_right


(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


Article Tags :
Practice Tags :


Be the First to upvote.


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