The definition of structure in C + +

Source: Internet
Author: User

Definition of struct in C language:

struct struct body name {

Member list;

.....

} struct-body variables;

7.1.1 definition of struct type variables
The definition of a struct type variable is the same as the definition of other types of variables, but since the struct type needs to be defined in advance for the problem, the definition of the struct type variable increases flexibility, with a total of three forms, each of which is described as follows:
1) define the struct type and then define the struct type variables:
struct STU/* Define student structure type */
{
Char name[20]; /* Student Name */
char sex; /* Gender */
Long num; /* Study Number */
float score[3]; /* Three subjects test results */
};
struct Stu student1,student2;/* define struct type variable */
struct Stu Student3,student4;
With this struct type, you can define more of the struct type variable.
2) define struct types and define struct type variables:
struct data
{
int day;
int month;
int year;
} time1,time2;
You can also define the following variables:
struct data time3,time4;
With this struct type, you can also define more of the struct type variable.
3) directly define struct type variables:
struct
{
Char name[20]; /* Student Name */
char sex; /* Gender */
Long num; /* Study Number */
float score[3]; /* Three subjects test results */
} Person1,person2; /* Define the struct type variable */
Because the struct type cannot be logged, the struct type variable cannot be defined beyond the immediate definition

C++

typedef struct node{

int data;

struct Lnode *next;

}lnode,*linklist;

In C, if you want to define a node, you need to use struct node to define this is C + +, directly using node to define it can be Lnode is the alias node, C + + with the node effect, the declaration of the object can be used node node and Lnode node.

Linklist means node *, which refers to node's pointer declaration, linklist list and node *list effect if you do not add TypeDef, it means declaring node Lnode and node *linklist separately, declaring an object, a pointer

The definition of structure in C + +

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.