一、指针变量作为参数
void set_time(int *time);
void set_time_copy(int time);
void main()
{
int *ptr, time;
ptr = &time;
int time_copy = 3;
time = 3;
set_time(ptr);
set_time_copy(time_copy);
printf("%d,%d",ptr[0],time_copy);
}
void set_time(int *time)
{
*time = 4;
}
void set_time_copy(int time)
{
time = 4;
}
二、指针和数组变量一样都是一个内存地址,所以C语言可以用指针来表示数组,太灵活了,呵呵
正如《The C Programming Language》里说的:
In C, there is a strong relationship between pointer and arrays, strong enough that pointers and arrays should be discussed simultanesly. Any operation that can be achieved by array subscripting can also be done with pointers.
void main()
{
int list[] = {1,2,3};
void *ptr;
ptr = &list;
printf("0x%x,0x%x,0x%x\n",list,ptr,&list);
}
本文通过示例代码详细介绍了C语言中指针变量作为函数参数的应用,并探讨了指针与数组之间的紧密关系,展示了如何利用指针操作数组。
352

被折叠的 条评论
为什么被折叠?



