Skip to content
Related Articles

Related Articles

Improve Article
GATE | Quiz for Sudo GATE 2021 | Question 18
  • Last Updated : 15 Dec, 2020

Consider the following C program :

#include <stdio.h>
#include <string.h>
struct s {
    int i;
    char *c;
} str[] = {100, "eclasses", 200, "geeks",300, "data",400,"structure",500,"students"};
int main()
    struct s *p = str;
    p += 1;
    printf("%s", p -> c);
    printf("%s,", ++p -> c);
    printf(" %d, ", p[1].i);
    printf("%s", p -> c);

Which of the string(s) will be in the final output of the above C program ?

Note – This question is multiple select questions (MSQ).
(A) geeksclasses
(B) 100
(C) students
(D) 200

Answer: (A) (C) (D)

Explanation: Here structure is the data type contains integer type and string. Base address of strings,


p contains the base address of the str data type.


means jump to index 0 to index 1 <200,2000>in array str.

First print statement, p->c points to the base address of the string and print statement print till null found in the string.


Second print statement
p– means back to index 0,
++p -> c means traverse the string one byte and print the remaining string


Third print statement
p[1].i prints the integer stored at 1 index.


Fourth print statement
p=p+4 means go to index 4
p->c print string stored at index 4


Therefore, options (A), (C), and (D) are correct.

Quiz of this Question
Please comment below if you find anything wrong in the above post

Attention reader! Don’t stop learning now. Learn all GATE CS concepts with Free Live Classes on our youtube channel.

My Personal Notes arrow_drop_up
Recommended Articles
Page :