当前位置: 代码迷 >> 综合 >> C语言中类型转换问题:assignment to ‘float *’ from incompatible pointer type ‘int *’
  详细解决方案

C语言中类型转换问题:assignment to ‘float *’ from incompatible pointer type ‘int *’

热度:82   发布时间:2024-02-21 07:03:22.0

BUG:

code:

        例如:

               

#include <stdio.h>
#include <string.h>

int main()
{
   float *a = NULL;
   int b[]= {1,2,3,4,5};
   a = b;
   printf("Hello, World! %f\n",a[1]); 
   return 0;
}

warning: assignment to ‘float *’ from incompatible pointer type ‘int *’

Solution method:

#include <stdio.h>
#include <string.h>

int main()
{
   /* 我的第一个 C 程序 */
   float *a = NULL;
   int b[]= {1,2,3,4,5};
   a =(float *)b;
   printf("Hello, World! %f\n",a[1]);
   
   return 0;
}
 

  相关解决方案