Is there a way to change the "address" of the two pointers?

Asked 2 years ago, Updated 2 years ago, 55 views

The way to change the 'value' that the two pointers point to can be found with just a little search... I can't find a way to change the 'address' that the two pointers point to... Even if I try to do it alone, there are errors or compiles, the results are weird...crying For example, when changing the value,

void swap(int *a, int *b){
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
}

You can do it like this, but if you try to change the address, A = b; In this part, only the error "Address cannot be substituted for address" appears repeatedly. How can I change the addresses? Please I beg you.

pointer address

2022-09-22 18:17

2 Answers

int swap(int ** a, int ** b) {
    int * temp;
    ...
}

I'll have to do this.


2022-09-22 18:17

Try initializing pointer variables a and b (assigning actual address values).

For example,

int main(void) {
int *a, *b;
int c = 1;
int d = 2;
a = &c;
b = &d;
a = b;
printf("%d", *a);
}


2022-09-22 18:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.