6 6 votes What is the output of the following code?#include <stdio.h> int main() { char str[] = "GATE"; char *p = str; printf("%c %c %s", str[1], *(p + 2), p + 1); return 0; }$\texttt{G A GATE}$ $\texttt{A T ATE}$ $\texttt{A T TE}$ $\texttt{T A ATE}$ Programming in C goclasses goclasses-cs-dpp goclasses-cs-dpp-day-305 programming-in-c c-programming goclasses-c-programming-practice-questions pointers array + – GO Classes 225 views answer comment Share Follow Print See 1 comment 1 1 comment reply Prashant-G commented 4 hours ago reply Follow flag Ya to Practice kr kr k Problem solving skill bad gai ya fir ... Quality Question nhi dal rhe Go classes wale DPP me ,but practice k liye resource available krwa diya ye prasansniya hai, thanks sir 0 0 replyShare Please log in or register to add a comment.
0 0 votes The string is:$\texttt{str = "GATE"}$So, the characters are:$\texttt{str[0] = 'G'}$$\texttt{str[1] = 'A'}$$\texttt{str[2] = 'T'}$$\texttt{str[3] = 'E'}$Now,$\texttt{p = str}$So, $\texttt{p}$ points to the first character of the string.First expression:$\texttt{str[1]}$This gives $\texttt{'A'}$.Second expression:$\texttt{*(p + 2)}$Since $\texttt{p}$ points to $\texttt{str[0]}$, $\texttt{p + 2}$ points to $\texttt{str[2]}$.So,$\texttt{*(p + 2) = 'T'}$Third expression:$\texttt{p + 1}$This points to $\texttt{str[1]}$.When printed using $\texttt{\%s}$, it prints the string from that position.So, it prints:$\texttt{"ATE"}$ $\therefore$ Output : $\texttt{A T ATE}$Answer: B GO Classes answered Jun 23 • edited Jun 23 by GO Classes GO Classes comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes Explanation Prashant-G answered 4 hours ago Prashant-G comment Share Follow 0 reply Please log in or register to add a comment.