Constructed type: array \ enum \ struct

Source: Internet
Author: User

Constructed type: array \ enum \ struct #import <Foundation/Foundation.h>
struct: Constructed type, is a custom type.
struct cpoint//struct is a keyword used to declare that a struct is followed by the name of a struct. The contents of the curly braces are called member variables
//{
float x;
Float y;
};//with a semicolon-terminated typedef struct car{
Char name[20];
int number;
Float score;
}ca;
struct//anonymous struct No name struct declaration and struct variable are put together, not commonly used
//{
Char name[20];
Char happy[20];
}L1 = {"Yuanxinfeng", "NV"};
typedef The first typedef is a good way to simplify struct names, so it is recommended to use TypeDef for the second type
typedef struct Student Stu;
//
typedef the second Kind

typedef struct PERSON{CHAR name[20];
char gender;
int number;
float score;//}per;////Structure body occupancy rule: 11 memory-occupying member variable type is Unit 2 top-down classification
struct student{
Char name[10];
int score;
int age;
float x;
Char y;
Double z;};/ /40//Access member variables use the. struct variable name for access. Member variable name//printf ("%s%c%d%.2f\n", s1.name,s1.gender,s1.number,s1.score);printf ("%s\n", S1.name);//printf ("%s%c%d%.2f\n", s1.name,s1.gender,s1.number,s1.score);
S1.score = 98;
S1.gender = ' m ';
S1.number = 10;
strcpy (S1.name, "Yuanxinfeng");//string array can not be assigned directly, use function to assign value
S1 = s2;//struct variable can be directly assigned//printf ("%s%c%d%.2f\n", s1.name,s1.gender,s1.number,s1.score);//struct nested//Multiple data---using arrays

Constructed type: array \ enum \ struct

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.