Under what circumstances, the pointer in the C language function will change after the function is executed, and under what circumstances will not change.
I am learning pointers now, but I am having some trouble now.
The first code
#include<stdio.h>
#include<stdlib.h>
void test(int* p);
int main()
{
int a[] = {2, 4, 6, 8, 0};
int* p = a;
printf("before p = %p, *p = %d\n", p, *p);
test(p);
printf("after p = %p, *p = %d\n", p, *p);
system("pause");
return 0;
}
void test(int* p)
{
p++;
printf("In test p = %p, *p = %d\n", p, *p);
}
The second code
#include<stdio.h>
#include<stdlib.h>
void swap (int* a, int* b);
int main()
{
int a, b;
scanf("%d %d", &a, &b);
swap(&a, &b);
printf("%d %d\n", a, b);
system("pause");
return 0;
}
void swap (int* a, int* b)
{
int t;
t = *a;
*a = *b;
*b = t;
}
I want to know why p has not changed in the first program after the execution of the function, and the second program a, b has changed.