C + + composite types

Source: Internet
Author: User


struct student{    std::string name;    int age;};/ /define STUDENT1 When creating a variable std1struct student1{    std::string name;    int age;} std1;//Create a variable std0struct{std::string name when defining the body of a nameless body    ;    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};//compilation        The device will help you count the number, but it is not recommended. int arr2[100] = {0};//only to display the initialization of the first element, the compiler will initialize the other elements to 0//c++11 new attribute int c11_1[3] {5, 2, 0};//can omit the equals sign in            T c11_2[3] {};//can not write whatever in parentheses, this will set all elements to 0 std::string love {"Zhouyunxuan"};    struct Std1.name = "Yunxuan";        Std1.age = 21;        Student stu2 = {"Zhouyunxuan", 21};                Student stu3 {"Yunxuan", 21};    Create dynamic array int idx = 10;    int* p = new INT[IDX];    for (int i = 0; i < ++i) {p[i] = i*100;    } for (int i = 0; i < ++i) {log ("This is%d", p[i]);    } _student SS ("Yunxuan", 21); Log ("My name is%s", Ss.name.c_str ()); 



struct function typedef struct _student{    std::string name;    int age;    _student (const char * _name): Name (_name) {        printf ("%s\n", Name.c_str ());}    } Student;








C + + composite types

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.