C language final exam knowledge points

1. Function

The basic unit of C language program is function

1.1 main function

① The C language always starts execution from the main function and ends with the global main function.

② The function called does not have to be defined in the main function.

1.2 Calling functions recursively

Directly recursively call function a and call function a directly;
indirectly recursively call function a and call function b, and then call function a in function b.

2. Character input and output

① getchar() means that only one character can be input

② putchar() means that only one character can be output

③ gets() is used to receive input string array , it can be said that scanf specific class
gets received character array name, character pointer or address of character array element

④ Puts starts from a certain address and sequentially outputs the characters in the storage unit.

2.1 Matters needing attention

2.1.1 getchar() that accepts a single character

getchar() It can receive elements that only occupy one character at a time (it can be 0-9 , because 0-9 occupies one character, but it is not recommended to use getchar to input numbers)

2.1.2 "Rebirth" gets_s()

In December 2011, ANSI adopted the ISO/IEC 9899:2011 standard. The gets() function was deleted from the standard and a new and safer function was used*gets_s()*Alternative, so in the visual studio 2019 c++ empty file, there is no gets identifier, only gets_s() can be used.

3. Array

3.1 Definition

The array starts with subscript 0, and stores the data space accordingly until the array limit is reached

3.2 Examples of combining pointers and arrays

3.2.1 Example ① (int type)

definition:

int *p,   s[20],i;
*p=s;

The array s[i] means:
A *(s+i) √
B *(p+i) √
C *(s = s + i) ❌
D *(p = p + i) √

The analysis is as follows:

The essence of p+1 is to move to the address of the next element of the array (four bytes of int type and one byte of char)
p+i represents the address of the i+1th element, then (p+i) is Represents the content of the i+1th element. That is, p+i is a pointer to element a[i], and (p+i) is equivalent to a[i].

3.2.2 Example ② (char type)

If there is:

char c[] = "encourage";
char *p = c;
printf("%s", p+5);

The output result is: rack

①、char c[ ]= "encourage" in "" (quotation marks) does not occupy storage space

②, *p = c; means to assign the first address of the array c to p

③, p+5 represents c[5], which is the sixth character'r'

④. The output format is %s, which means that all subsequent character rage will be output

4.
Leap year definition:
ordinary leap year: a year that is divisible by 4 but not 100.
Century leap year: a year that is divisible by 400
year%4==0 && year % 100 != 0 || year % 400==0

5.
In the C language% (remainder) must ensure that the numerator and denominator are both integers (can be negative, but the negative remainder of each compiler depends on the compiler itself, according to the compiler rules)

3.
strlen is a C language library function, included in string.h, used to count the number of elements in a string (character array), that is , count from the head of the array until it encounters the end of the string \0, The count result does not include \0 .
[Example]
strlen(“abcd\0ed\0g”)The return value is 4

4. Structure

4.1 Structure definition and definition form

4.1.1 Definition

A structure is a collection that contains multiple variables or arrays. Their types can be the same or different. Each such variable or array is called a member of the structure

4.1.2 Definition form

struct structure name { variable or array contained in the structure } ;

struct stu{
    
    
    char *name;  //姓名
    int num;  //学号
    int age;  //年龄
    char group;  //所在学习小组
    float score;  //成绩
};

4.2 Fill in the blanks with examples (use of structure)

Fill in the code under the underline:

#include<stdio.h>
struct date
{
    
    
    int year;
    int month;
    int day;
};

int main()
{
    
    
    date d={
    
    2020,1,20};
    printf("%04d-%02d-%02d\n", _____);
    date *pd=_____;
    printf("%04d-%02d-%02d\n", pd->year,pd->month,pd->day);
    return 0;

}

The first empty: d.year,d.month,d.day
(note the output format) The
second empty: &d

Guess you like

Origin blog.csdn.net/weixin_42198265/article/details/112175599