Consider the following program
#include <stdio.h> #include <stdbool.h> int main(void) { int z, s; printf("int z: %p\nint s: %p\n", &z, &s); bool x, y; printf("bool x: %p\nbool y: %p\n", &x, &y); return 0; }
Exit:
int z: 0028FF3C int s: 0028FF38 bool x: 0028FF37 bool y: 0028FF36
Now there is a 4 byte difference between z and s , which is the size of int in my case.
There is a difference of 1 byte between x and y .
Now with this line:
scanf("%d", &y);
From %d to scanf you indicate that you need a 4-byte long input, int .
This int will be stored in case y at address 0028FF36 and with input 0x0001 second byte, which is 0 , will be stored in 0028FF37 . And this is the address x .
You can check this with a different input value. For example, if you give 65535 in y , which is 0xFFFF , then x will be 0xF , which is 255 decimal.
Bence kaulics
source share