本文介绍了错误:“一元*'的无效类型参数(有'廉政')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一个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;
}

编译器产生一个错误:

Compiler produces an error:

error: invalid type argument of ‘unary *’ (have ‘int’)

有人能解释一下这个错误意味着什么?

Can someone explain what this error means?

推荐答案

由于 C 持有整数指针的地址,它的类型应该是 INT **

Since c is holding the address of an integer pointer, its type should be int**:

int **c;
c = &a;

整个程序就变成了:

The entire program becomes:

#include <stdio.h>
int main(){
    int b=10;
    int *a;
    a=&b;
    int **c;
    c=&a;
    printf("%d",(**c));   //successfully prints 10
    return 0;
}

这篇关于错误:“一元*'的无效类型参数(有'廉政')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 08:47