博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++ 复合类型
阅读量:7265 次
发布时间:2019-06-29

本文共 1454 字,大约阅读时间需要 4 分钟。

struct Student{    std::string name;    int age;};//定义Student1的时候创建变量std1struct Student1{    std::string name;    int age;}std1;//定义无名机构体的时候创建变量std0struct{    std::string name;    int age;}std0;struct _student{    std::string name;    int age;    _student(std::string _name,int _age)    {        name = _name;        age = _age;    }};

int num[3];    num[0] = 1;    num[1] = 2;    num[2] = 3;    for(int i : num)    {        log("This is %d", i);    }        int arr[3] = {4, 5, 6};    log("Size of int is %lu", sizeof(int));//4    log("Size of arr is %lu", sizeof(arr));//12        int arr1[] = {7,8,9};//编译器会帮你算个数的,可是不推荐。        int arr2[100] = {0};//仅仅要显示的初始化第一个元素,编译器就会把其它的元素都初始化为0                //c++11新特性    int c11_1[3] {5, 2, 0};//能够省略等于号    int c11_2[3] {};//能够不在括号中写不论什么东西,这将把全部元素都设置为0            std::string love {"zhouyunxuan"};            //struct    std1.name = "yunxuan";    std1.age = 21;        Student stu2 =    {        "zhouyunxuan",        21    };        Student stu3 {"yunxuan", 21};                //创建动态数组    int idx = 10;    int* p  = new int[idx];    for (int i = 0; i < 10; ++i)    {        p[i] = i*100;    }    for (int i = 0; i < 10; ++i)    {        log("this is %d", p[i]);    }            _student ss("YUNXUAN", 21);    log("my name is %s", ss.name.c_str());

//结构体函数typedef struct _student{    std::string name;    int age;    _student(const char * _name):name(_name){        printf("%s\n", name.c_str());    }}Student;

转载地址:http://fgrdm.baihongyu.com/

你可能感兴趣的文章
为什么OKR比KPI更适合IT企业
查看>>
去除虚拟机报警声音
查看>>
grub设置
查看>>
代码调试利器lsyncd
查看>>
微信JSAPI支付_1
查看>>
Linux C打印IP地址信息
查看>>
iOS之Block详解
查看>>
在Ubuntu 14.04中安装Webmin
查看>>
getopts简易教程(Small getopts tutorial)译文
查看>>
对linux硬链接和软链接理解
查看>>
Python 如何安装 pip 包管理工具
查看>>
Linux vi命令
查看>>
线程的创建方式一-----继承Thread类
查看>>
NO.98 最禅道第五季,燃烧您的想像力!
查看>>
Docker网络解决方案-Weave部署记录
查看>>
Linux上有两种时间,一种是硬件时间,一种是系统时间
查看>>
详解STP下交换机端口状态
查看>>
我的友情链接
查看>>
BruteXSS:XSS暴力破解神器【含福利】
查看>>
我的友情链接
查看>>