1,295 views
5 5 votes

Answer given is D "gh" . how??

1 Answer

Best answer
3 3 votes

old compilers the size of integer is 2bytes and new compilers the size of integer is 4B.

 If nothing is mention in the question about size of a integer then consider size of int is 4B.if they mention we have to consider that value.

Here size of int is 2B.

char *t;

t=(p+=sizeof(int))[-1] 

t=(p+2)[-1]   // p+2 it skips 2 positions from start.and p is pointing to array position 2.

p[-1] again it goes back then p points to p[1].

print all characters in that string and output is cd.

So option should be B.

Suppose if we execute this programme on new compilers it gives 'gh' as outpot.

• selected by
Position:
Show:

Related questions

8 8 votes
1 1 answer
299
299 views
GO Classes asked Jun 19
299 views
What is the output of the following code?#include <stdio.h void fun(int a[], int *p) { a = a + 5; *(p + 2) = *(p + 2) + 10; p++; *p = *p + 1; } int main() { int arr[] =...
6 6 votes
1 1 answer
242
242 views
GO Classes asked Jun 19
242 views
What is the output of the following code?#include <stdio.h int main() { int arr[] = {10, 20, 30}; int *p = arr; printf("%d %d", *p, *(arr + 2)); return 0; }$\texttt{10 20...
8 8 votes
1 1 answer
241
241 views
GO Classes asked Jun 6
241 views
What is the output of the following code?#include <stdio.h void change(int *p, int *q) { *p = *p + 4; *q = *p + *q; p = q; *p = *p - 3; } int main() { int a = 6, b = 10; ...
8 8 votes
1 1 answer
247
247 views
GO Classes asked Jun 6
247 views
What is the output of the following code?#include <stdio.h int main() { int a = 8, b = 12; int *p = &a; int *q = &b; *p = *p + *q; q = p; *q = *q - 5; printf("%d %d", a, ...