我有一个C程序:错误: '一元*' 的无效类型参数(有 '诠释')
#include <stdio.h>
int main(){
int b = 10; //assign the integer 10 to variable 'b'
int *a; //declare a pointer to an integer 'a'
a=(int *)&b; //Get the memory location of variable 'b' cast it
//to an int pointer and assign it to pointer 'a'
int *c; //declare a pointer to an integer 'c'
c=(int *)&a; //Get the memory location of variable 'a' which is
//a pointer to 'b'. Cast that to an int pointer
//and assign it to pointer 'c'.
printf("%d",(**c)); //ERROR HAPPENS HERE.
return 0;
}
编译器产生一个错误:
error: invalid type argument of ‘unary *’ (have ‘int’)
有人能解释这个错误手段?
还要注意答案中缺少演员。问题中的强制转义隐藏了将'int **'分配给'int *'的行上的问题。 ('c =(int *)&a;') – Thanatos 2013-09-30 22:54:21