Skip to content
Related Articles

Related Articles

GATE | Quiz for Sudo GATE 2021 | Question 19
  • Last Updated : 15 Dec, 2020

Consider the C program given below.

int main()
    char *s1[]={"Dubai","Singapore","Paris","Sanghai","HongKong"};
    char **s2[]={(s1+2),(s1+1),(s1+3),(s1+4),(s1+0)};
    char ***s3=s2;
    char str1[]="I love to visit ";
    char str2[]="times every year.";
    printf("%s ",**++s3);
    printf("%d-%d ",s3-s2,*s3-s1);
    return  0;

Which of the following string(s) is/are part of output of above C program ?

Note – This question is multiple select questions (MSQ).

(A) Dubai
(B) Sanghai
(C) 2-3
(D) 3-4

Answer: (B) (C)

Explanation: Let
Base Address s1=1000
Base Address s2=2000
s1 pointer array contains the base addresses of the strings.
s2=1000 double pointer array contains the addresses of the pointer array s1.
s3=2000 triple pointer contains the base address of the address array s2.

s3++ means increment to next index value by 4 which means 2000 + 4 =2004
In first print statement
**++s3 again s3 incremented to 2008.
At 2008 (s2) contains to s1+3 and (s1+3) points to “Sanghai”.

In second print statement

s3-s2 = 2008 - 2000 / 4(size of the data type) = 2
*s3 - s1= 1012-1000/4 = 3 

So, output of given C program is : I love to visit Sanghai 2-3 times every year.
Hence, ‘Sanghai’ and ‘2-3’ are strings part of the output.

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :