425 views
0 votes
0 votes
#include <stdio.h>

int main(void) {
    int s[6]={128,256,512,1024,2048,4096};
    int *x=(int*)(&s+1);
    printf("%d",x);
    return 0;
}
#include <stdio.h>

int main(void) {
    int s[6]={128,256,512,1024,2048,4096};
    int *x=(int*)(&s+1);
    printf("%u",x);
    return 0;
}

Why both are printing different address? Is it not a fixed address of memory??

1 Answer

0 votes
0 votes

Though the array s is of fixed size i.e, 6.

x is a pointer which is pointed to array's first element.

Ans also, we are printing the value stored in x i.e, address to which it is pointed to but not the value stored at that address.

When we run these programs, the array will be allocated in memory. and x prints the address. so each time you run it, it will print different address. %d and %u both prints the address.

Related questions

0 votes
0 votes
1 answer
1
srestha asked May 6, 2019
432 views
Can someone tell me, why these two same program giving different output?Is there any problem in code or compiler not producing right?Program1Program2
1 votes
1 votes
1 answer
2
Na462 asked Jan 8, 2019
1,402 views
#include <stdio.h>main (){unsigned x = -10;int X = 20;if (X x) printf ("Hello");else{ printf ("%d",x); printf ("Jello"); }}
0 votes
0 votes
1 answer
4