1,343 views
7 votes
7 votes
#include <stdio.h>
void f(char**);
int main()
{
    char *argv[] = { "ab", "cd", "ef", "gh", "ij", "kl" };
    f(argv);
    return 0;
}
void f(char **p)
{
    char *t;
    t = (p += sizeof(int))[-1];
    printf("%s\n", t);
}

(a) ab (b) cd (c) ef (d) gh

In GATE Exam, if not specified What should be size of integer?

1 Answer

Best answer
6 votes
6 votes

Answer will be D) gh

Here p will initially point to the "ab"

p += sizeof(int)

This will translate into p = p + 4; // Consider size of int is 4 

Now p will point "ij".

(p)[-1];

will translate into *(p - 1), then it will return the address of "gh"

//Why address of "gh", because p is double pointer, hence single pointer will return the address its element.

Then t will have the address of "gh". Hence "gh" will be printed. 

selected by

Related questions

0 votes
0 votes
1 answer
1
Desert_Warrior asked May 16, 2016
521 views
#include<stdio.h int a = 10; int main() { fun(); fun(); return 0; } int fun() { static int a = 1; printf("%d ",a); a++; return 0; }
0 votes
0 votes
1 answer
2
Desert_Warrior asked May 16, 2016
604 views
#include<stdio.h #include<stdlib.h int main() { char s[] = "Opendays2012"; int i = 0; while(*(s++)) i++; printf("%d",i); return 0; }(a) Segmentation Fault (b) Compile Err...
1 votes
1 votes
1 answer
3
0 votes
0 votes
1 answer
4