【发布时间】:2016-11-29 06:56:56
【问题描述】:
我的问题是关于取消引用 char 指针
这是我的代码 -
#define MAX 10
char s[80]="Hello";
int main(){
char *stackValue;
stackValue=&s;//here I assined the address of s to stackValue
if(!stackValue){
printf("No place for Value");
exit(1);
}
else{
printf("\n%s",*stackValue);//This doesn't work with * before it
printf("\n%s",stackValue);//This works properly
}
return 0;
}
在上面的代码中,我已将 S[] 的地址分配给 stackValue,当我打印 *stackValue 时它不起作用,
但如果我只打印 'stackValue' 就可以了。
当我用整数做同样的事情时
int main(){
int i=10, *a;
a=&i;
printf("%d",*a);//this gives the value
printf("%d",a)//this gives the address
return 0;
}
打印字符指针和整数指针是不同的。当我在 int 值中使用 * 时,它会给出值,但当我将它用作 char 指针时会给出错误。
帮帮我?
【问题讨论】:
标签: c pointers char char-pointer