Test pointer with the gdb tool in linux.
# To use gdb, we should use gcc -g main.c -o main.out
# The type gdb main.out
# in gdb
# l[list] list the source code.
# n next
# p print
# s step
# bt print backtrace of all stack frames, or innermost COUNT frames.
# f Select and print a stack frame.
#include <stdio.h>
int change(int *a, int *b)
{
int tmp = *a;
*a = *b;
*b = tmp;
}
int main()
{
int a = 1;
int b = 2;
change(&a, &b);
printf("a = %d\nb = %d\n", a, b);
return 0;
}
#include <stdio.h>
int change(int a, int b)
{
int tmp = a;
a = b;
b = tmp;
}
int main()
{
int a = 1;
int b = 2;
change(a, b);
printf("a = %d\nb = %d\n", a, b);
return 0;
}