c++中的struct关键字详解

时间:2020-08-19 19:42:50   收藏:0   阅读:65

struct关键字是用来定义一个新的类型,这个新类型里面可以包含各种其他类型,称为结构体。

 

#include <stdio.h>

typedef struct {
        int a;
        int b;
}Stu;

Stu getStu(int x, int y)
{
        Stu result;
        result.a = x;
        result.b = y;
        return result;
}

int main()
{
        int a = 2, b = 3;
        Stu test = getStu(a, b);
        printf("%d %d\n", test.a, test.b);
        return 0;
}

 

 

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!