Consider the C program given below.
#include<stdio.h>
#include<string.h>
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." ;
s3++;
printf ( "%s" ,str1);
printf ( "%s " ,**++s3);
printf ( "%d-%d " ,s3-s2,*s3-s1);
printf ( "%s" ,str2);
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
Level Up Your GATE Prep!
Embark on a transformative journey towards GATE success by choosing
Data Science & AI as your second paper choice with our specialized course. If you find yourself lost in the vast landscape of the GATE syllabus, our program is the compass you need.