code:

Stu* pStu = malloc(sizeof(Stu));

改为
Stu* pStu = (Stu*)malloc(sizeof(Stu));

code

#include <stdio.h>
#include <stdlib.h>typedef struct {int a;int b;
}Stu;Stu* getStu(int x, int y)
{Stu* pStu = (Stu*)malloc(sizeof(Stu));pStu->a = x;pStu->b = y;return pStu;
}int main()
{int x = 2, y = 3;Stu *pStu = getStu(x, y);printf("%d %d\n", pStu->a, pStu->b);free(pStu);return 0;
}

输出

2 3
Program ended with exit code: 0

https://blog.csdn.net/weixin_34221332/article/details/86981433

转载于:https://www.cnblogs.com/sea-stream/p/11129947.html

Cannot initialize a variable of type 'Stu *' with an rvalue of type 'void *'相关推荐

  1. C++ stack pop()返回值 error: cannot initialize a variable of type ‘int‘ with an rvalue of type ‘void‘

    LeetCode一道链表倒置题目 struct ListNode {int val;ListNode *next;ListNode(int x) : val(x), next(NULL) {} };c ...

  2. QT之error: cannot bind non-const lvalue reference of type ‘CBaowen’ to an rvalue of type ‘CBaowen

    问题描述:QT中自己编写了一个结构体变量CBaowen,报文中含有函数重载部分(如下所示), 之后定义一个队列变量 QQueue<CBaowen>  queue; 当给队列变量赋值时que ...

  3. cannot bind non-const lvalue reference of type ‘xxx‘ to an rvalue of type ‘xxx‘

    文章目录 报错代码 报错 原因 解决方案 报错代码 #include<iostream> using namespace std; class Complex{private:double ...

  4. C++之error: cannot bind non-const lvalue reference of type ‘myString’ to an rvalue of type ‘myString

    先看代码(不想看代码可以直接看代码后的问题描述) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ...

  5. C++之invalid initialization of non-const reference of type ‘int’ from an rvalue of type ‘int’

    1.看代码 2.编译结果 3.分析和解决 就拿f(a + b)来说,a+b的值会存在一个临时变量中,当把这个临时变量传给f时,由于f的声明中,参数是int&,不是常量引用,因为c++编译器的一 ...

  6. cannot bind non-const lvalue reference of type ‘***‘ to an rvalue of type ‘***‘解决方法

    在写C++作业的时候,我发现使用 #include <iostream> class complex{public:int real;int imaginary;public:comple ...

  7. 【C++---const引用】数组进行指针引用传递给函数error: non-const lvalue reference of type ‘int*‘ to an rvalue

    目录 原因 类型转换 手动转换 自动转换 关于临时量 关于常量引用(const的引用) const引用的对象不是不能被修改了吗,这里为什么被修改了? 不是说是const引用吗?为什么又变成了引用所绑定 ...

  8. Format specifies type 'id' but the argument has type 'NSError *__autoreleasing *

    我想打印error,但是出现了标题中的错误,代码如下: -(id)yobee_responseObjectForResponse:(NSURLResponse *)response data:(NSD ...

  9. R语言使用plot函数和lines函数可视化线图(line plot)时、图之间的主要区别是由选项type产生的、type参数常用参数说明、不同type生成的可视化图像对比

    R语言使用plot函数和lines函数可视化线图(line plot)时.图之间的主要区别是由选项type产生的.type参数常用参数说明.不同type生成的可视化图像对比 目录

最新文章

  1. win运行pycharm找不到要加载的model.pkl文件是workingspace设置路径与文件路径位置不对应
  2. php中单引号和双引号的区别,哪个速度更快?为什么?
  3. 举例说明html语言的结构,HTML语言的结构
  4. MediaSource 缓存
  5. Android的数据存储
  6. 坐标上升算法(Coordinate Ascent)及C++编程实现
  7. 数据结构 递归讲解
  8. reactor设计模式 1
  9. 常见字符编码 java
  10. Python框架篇之Django(Template模版:标签tag、自定义filter、extend模板继承)
  11. XP框架的另外选择→太极
  12. YOLOv5数据集标注工具
  13. Verilog HDL实现智能药盒
  14. pip下载太慢?聪明人都这样
  15. 放不下的原理_通俗易懂,几张图看懂大数据存储和计算原理
  16. GKCTF2020 逆向部分题的复现
  17. 2021下半年中小学教资考试教育知识与能力试题(中学)——主观题
  18. 2017年的端午节祝福语
  19. vue获取一个月有多少天
  20. PC企业微信hook接口,通过查询添加外部联系人教程

热门文章

  1. 计算机测评,笔记本电脑评测
  2. web前端渲染和后端渲染(web front-end and back-end rendering)
  3. 在WIN2003安装TD8,问题汇总
  4. Unity插件:UFPS
  5. js选出给定数组中所有的偶数/奇数/n的倍数(filter)
  6. Javascript JS 网页分享到QQ空间QQ,java实现qq分享,url带参数的方法
  7. CF1660C Get an Even String(贪心)
  8. 【程序】STM32H743ZI用SDMMC2驱动88W8801 WiFi模块
  9. 一个CPP程序猿的第一篇博客
  10. 【课程】大气对流参数