型「ボイド*」の右辺値を型「ステュー*」の変数を初期化できません

 

コード:

意志

STU * pStu = malloc関数(はsizeof(STU))。

改为
このPSTU * =(この*)はmalloc(はsizeof(本))。

 

コード

#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

 

 

 

 

おすすめ

転載: www.cnblogs.com/sea-stream/p/11129947.html