1,917 views
8 8 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
5 5 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
Position:
Show:

Related questions

0 0 votes
1 answers 1 answer
941
941 views
Desert_Warrior asked May 16, 2016
941 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 0 votes
1 answers 1 answer
962
962 views
Desert_Warrior asked May 16, 2016
962 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 1 vote
1 answers 1 answer
2.9k
2.9k views
Desert_Warrior asked May 16, 2016
2,866 views
#include<stdio.h void foo(char *); int main() { char *string = "Hello"; foo(string); printf("%s",string); return 0; } void foo(char *a) { while(*a) { *a += 1; a++; } }(a)...
0 0 votes
1 1 answer
736
736 views
Desert_Warrior asked May 16, 2016
736 views
#include <stdio.h int main(void) { char a[5] = { 1, 2, 3, 4, 5 }; char *ptr = (char*)(&a + 1); printf("%d %d\n", *(a + 1), *(ptr - 1)); return 0; }options are : (a) Compi...