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