Consider the C program given below and fill the blank in the output of the sentence.
I love to visit ________ times every year.

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

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


Answer: (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 

Hence, Sanghai 2-3 is the correct answer.


Quiz of this Question


  • Last Updated : 18 Dec, 2018

Share your thoughts in the comments