Summary of daily classes at Camp David

Source: Internet
Author: User

Struct is a definition similar to a super array. It can define many different types of variables and add the variable name with struct, which is similar to the definition of int, however, the difference is that the structure needs to use three symbols such as {}; To summarize the content in the content. After the definition, it can be called directly in the main function, (.) or (->) two operators are called.

struct book{    char titleP[MAXTITL]    char author[AXAUTL]    float value}library;

The above is an alias for the structure book called library. In the main function, we can also directly use library, and there is another declaration method.

struct{    char titleP[MAXTITL]    char author[AXAUTL]    float value}library;

In this way, you do not need to define the variable name for the struct at the beginning. At the end, you can directly create another alias library for the struct. In this way, you can omit a naming step.

The following describes how to use the structure question.

# Include <stdio. h> # include <string. h> # define maxtitl 41 // Maximum length of the title + 1 # define maxautl 31 // Maximum length of the author name + 1 struct book // structure template: mark book {char title [maxtitl]; char author [maxautl]; float value ;}; int main (INT argc, const char * argv []) {struct book library; // declare the library as a book-type variable printf ("Please enter the book title. \ n "); gets (library. title); // gets is a bug that is prone to overflow. It is generally not recommended to use // scanf ("% s", library. title); // access the title part printf ("now enter the author. \ n "); gets (library. author); // gets is a bug that is prone to overflow. It is generally not recommended to use // scanf ("% s", library. author); printf ("now enter the value. \ n "); scanf (" % F ", & library. value); printf ("% s by % s: $ %. 2f \ n ", library. title, library. author, library. value); printf ("% s: \" % s \ "($ %. 2f) \ n ", library. author, library. title, library. value); printf ("done. \ n "); Return 0 ;}

 

 

C program memory address space layout

1. short text (. Text: executable command)

2. Data Segment

Initialize data segments (global variables, static variables)

Non-initialized Data Segment

 

The initialization data segment needs to be defined by ourselves, and should be substituted into it before running.

Non-initialized data segments are entered by the system when the program is running.

 

3. Stack is allocated by the system itself

 

Data is first-in-first-out (or later-in-first-out)

 

A. Local Variables

B. Return address for function calling

C. Information about the called Environment

 

4. Heap requires us to allocate release management (common local variables)

We allocate release management by ourselves. If we do not release it, it will be automatically reclaimed by the system at the end of the program.

 

The malloc, calloc, realloc, and other functions in the program are all allocated memory. A small space is allocated to a large space, and the heap is allocated from the bottom up.

 

Summary of daily classes at Camp David

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.