在以下代码中:
#include<stdio.h>
int main(int argc,char *argv[]){
int index;
for(index = 0; index < argc; index++) {
printf("The %d is %s\n",index,argv[index]);
}
return 0;
}
从声明char *argv[]
中,cdecl说这意味着
declare argv as array of pointer to char
,所以我认为代码应该这样写:
printf("The %d is %s\n",index,*argv[index]);
如以下代码:
void give_me_ptr(int *ptr){
printf("the value of ptr is %p\n", ptr);
printf("the value of ptr is %d\n", *ptr);
}
int main(void){
int a = 10,index;
give_me_ptr(&a);
return 0;
}
事实证明
the value of ptr is 0x7fff76010b48
the value of ptr is 10
对我来说,这意味着我应该在指针变量之前添加 *。