int main(void) {
int x = 0;
int* p = &x;
char* q = p;
while (*p == *q) { //What happens here?
x = x + 1;
}
printf(“%d\n”, x);
}
Well I have this simple program here. I am confused on how this works. I would be obliged if you can help me.
I have a test and would like to learn how this works. Thank you in advance.
Q Pointer Question
|—————————-|
0x00<————-Q points here?
|—————————-|
0x00
|—————————-|
0x00
|—————————-|
0x00<————-Q points here?
|—————————-|
So after x = x+1. Is it?
|—————————-|
0x00<————-0x01 here?
|—————————-|
0x00
|—————————-|
0x00
|—————————-|
0x00<————-0x01 here?
|—————————-|
It depends on endianness, but it’s essentially:
The loop will terminate once
((int) x) != ((int) lowest byte of x)