edited by
723 views
2 votes
2 votes
main(){

    int S[6] = {126,256,512,1024,2048,4096};

    int *x=(int *) (&S+1);

    printf (“%d”,x);

}

int is 4 bytes; array starts from 2000 .

The answer is 2024 I am getting 2004.

Please explain the concept. If possible provide a resource.

edited by

2 Answers

4 votes
4 votes
int *x=(int *) (&S+1);

size of S is $4 \times 6 = 24$ bytes 

(&S + 1) == (2000 + 1 * 24) == 2024

1 votes
1 votes
When you do &S + 1 than it will work as follows

&S + 1*sizeof(S)

= 2000 + 24

=2024

This address will be referred by x and on print we get 2024

Related questions

5 votes
5 votes
1 answer
1
Markzuck asked Dec 22, 2018
1,199 views
someone please explain this:how does a+1 differs from &a+1 in above code?detailed explanation would be of great help as they incremented &a by 6 and NOT 1
2 votes
2 votes
0 answers
2
srestha asked Jan 28, 2019
621 views
void foo(int n) { for(i1=1;i1<=n;i1++) { for(i2=1;i2<=i1;i2++) { ....... { for(i6=1;i6<=i5;i6++) { count++; } } } } }Count initially 0.What is value returned by foo(8)?
3 votes
3 votes
2 answers
3
Shamim Ahmed asked Dec 11, 2018
549 views
char *a = “MADEEASY”;char *b = “GATECSIT2019”;char *r = a;char *s = b;printf(“%d”, (int) strlen (b+3[r] – 1[s]));return 0; Whats the output? Answer given 8