I have a question about the pointer operation.

Asked 2 years ago, Updated 2 years ago, 42 views

In a 32-bit architecture, how does this code output?

#include <stdio.h>

int main(void) {
    int x[4];
    printf("%p\n", (void*) (x));
    printf("%p\n", (void*) (x + 1));
    printf("%p\n", (void*) (&x));
    printf("%p\n", (void*) (&x + 1));
}

c array pointer

2022-09-21 20:22

1 Answers

printf("%p\n", (void*) (x));
printf("%p\n", (void*) (x + 1));
printf("%p\n", (void*) (&x));
printf("%p\n", (void*) (&x + 1));

Assuming that n = x is the address of the first element, the code above is

respectively

I don't think it's necessary to explain 1-3 separately, and if you explain 4

&x is the int (*)[4] type, so you can call it 4 *sizeof(int).


2022-09-21 20:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.