University c language must back to the basic knowledge _c language basic knowledge Daquan

For students who are just starting to learn computer programming, having no prior programming knowledge is not a problem. However, it's crucial to build a solid foundation in the basics of C language. This series aims to help everyone review and understand the fundamental concepts of university-level C programming. I hope you find it helpful.

University C Language Must Return to Basic Knowledge

University C language must back to the basic knowledge _c language basic knowledge Daquan

For example:

Printf("-,123); The second part has three digits, which is larger than the specified two digits.

Printf("]",123 ); The second part has three digits, less than the specified five digits, and two spaces on the left. 123

Printf("%f",1.25); The decimal number needs to be complemented by 6 digits, and there is no complement of 6 digits. The result is 1.250000

Printf("%5.3f",125 ); three decimal places, the entire five digits, the result is 1.250 (one decimal place)

Printf ("%3.1f", 1.25); one decimal place, the whole three, the result is 1.3 (to be rounded)

Section 3 Data Input

1, scanf ("a=%d, b=%d", &a, &b) exam super focus! It is important to remember to enter data in the terminal in the format of the first part. The core of the exam is: exactly the same. Enter a=12 and b=34 on the black screen to correctly assign 12 and 34 to a and b. It doesn't matter if it is different.

2, scanf (" %d,%d", x, y); this method is absolutely wrong, the second part of scanf must be the address! Scanf (" %d, %d", &x, &y); note that this can be written!

3, pay special attention to the pointer in the scanf for example: int x = 2; int * p = &x; scanf (" % d", x); error scanf (" % d", p); correct scanf (" % d" ,&p); Error scanf(%d, *p) error

4. Specify the length of the input (exam focus) Terminal input: 1234567 scanf ("-M%d", &x, &y, &z); x is 12, y is 3456, z is 7 Terminal input: 1 234567 due to 1 and 2 There are spaces in the middle, so only 1 bit is given to x scanf("-M%d", &x,&y,&z); x is 1, y is 2345, z is 67

5, characters and integers are close relatives: int x=97; printf ("%d", x); the result is 97 printf ("%c", x); the result is a

6, the difference between the input character and the integer (examination super focus)

Scanf ("%d", &x); enter 1 at this time, pay special attention to the integer 1

Scanf ("%c", &x); Enter 1 at this time, paying special attention to the character '1' ASCII as an integer 48.

Additional instructions:

1) The format of the scanf function:

Note that the second part of the function is an address such as &a, not a; scanf("%d%d%*d%d", &a,&b,&c); skips the third data entered.

2) putchar, getchar function test:

Char a = getchar() is no argument, get a character you type from the keyboard to the variable a. Putchar('y') outputs the character y to the screen.

3) How to achieve the exchange of values in two variables x, y (required to back down)

It is not possible to use x=y, y=x; to use the intermediate variable t=x; x=y; y=t.

4) How to implement the procedure of retaining three decimal places and the fourth rounding (request to back down)

y=(int)(x*100+0.5)/100.0 This holds two digits and rounds the third digit

y=(int)(x*1000+0.5)/1000.0 This is reserved for three digits, rounded to the fourth digit

y=(int)(x*10000+0.5)/10000.0 This is reserved for four digits, rounded to the fifth digit

This has a general meaning, pay attention to x = (int) x This is to remove the fractional part.

Third Chapter

Pay special attention to the fact that in C language, non-zero is used to indicate logical truth, and 0 is used to indicate logical false.

The C language has a constructed type and no logical type.

Relational arithmetic symbols: Note the difference between the writing of =, == and =! (Exam focus)

If only the latter statement, to manage more than one, please use braces!

1) Relational expression:

a, the value of the expression can only be 1 (represented as true), or 0 (representing false).

For example, the relational expression of 9"8 is true, so the value of the expression 9"8 is 1.

For example, the relation expression of 7 "6 is false, so the value of the expression "7" is 0.

b, the exam is the most error-prone: is int x = 1, y = 0, z = 2;

x "y"z is true or false? Bringing in 1 "0 "2, it is definitely wrong from a mathematical point of view, but if it is C language then it is correct! Because 1 "0 is false to get 0, the expression becomes 0" 2 then the result of the operation is 1, which is called true!

c, the difference between the equal sign and the assignment! Be sure to remember that "=" is the assignment, and "==" is the equal sign. Although many people can recite it, I still want everyone to remember it. Otherwise, if I am wrong, I will definitely despise you!

2) Logical expression:

Core: The value of an expression can only be 1 (represented as true), or 0 (represented false).

a) Total && || ! Three logical operators.

b) ! > &&”|| Priority level.

c) Pay attention to the short circuit. The exam is more like the exam. For details, please see the examples in the book. You must do examples 1 and 2

d) indicates a method in which x is less than 0 and greater than 10.

0 "x "10 is not acceptable (must remember). It is first calculated 0 "x results are 1 or 0; then 0, or 1 and 10 are always true (for 1). So be sure to use (0 "x) && (x "10) means greater than 0 is smaller than 10.

3) if statement

a, else is the match with the nearest if and no else statement.

b, the program of the exchange: t = x; x = y; y = t;

c, if (a "b) t = a; a = b; b = t; if (a "b) {t = a; a = b; b = t;} the difference between the two, the test has been repeatedly tested !

d, a separate if statement: if (a "b) t = a; standard if statement: if (a "b) min = a; else min = b; nested if statement: if (a "b) if (b)c)printf("ok!"); select one if statement if(a==t)printf("a"); else if(b==t)printf("b"); else if (c==t)printf("c"); else pritnf("d");

Through the exercises, you should be familiar with the above if statements!

Classic exam questions: Combine the above four if statement questions to make a question, answer the wrong, please break it yourself! ready, go!

Int a=1, b=0; if(!a)b++; else if(a==0) if(a)b+=2; else b+=3; What is the value of b?

If you don't understand the problem, you should never break it yourself, so that people who can't do it will live reasonably.

The correct thing is that b is 3.

Int a=1, b=0;

If(!a)b++; is false and does not execute

Else if(a==0) is a fake execution

If(a)b+=2; A nested if statement belonging to else if is not executed.

Else b+=3; If the if-else-if statement does not have a correct one, execute the else statement!

4) Conditional expression:

Expression 1? Expression 2: Expression 3

a. Exams: After the fake.

b. Note that when the value of expression 1 is non-zero, the value of expression 2 is used as the whole operation result. When the value of expression 1 is 0, the value of expression 3 is used as the whole result.

c, int a=1, b=2, c=3, d=4, e=5;

k=a>b? c:d>e? d:e; What is the value of k? The answer is san

5) switch statement:

a) The process of execution must be understood! The detailed process of the class is said, please understand yourself!

b) Pay attention to the difference between break and no break. In the two examples in the book, there is no break. As long as there is a case match, the rest must be executed. If there is break, the swiche statement is directly jumped out. Break is a breakup in the C language, meaning a break.

c) switch can only be used with break, not with continue.

d) switch(x) x: is an integer constant, a character constant, and an enumerated data.

{case 1: .... It can't be a variable. Case 2: .... } e)switch is a compulsory question type, please be sure to complete the exercise of the switch after class.

University C language review focus

1) Program structure is three kinds: sequential structure, selection structure (branch structure), and loop structure.

2) The read program should be read from the main() entry, and then read from the top (down to the loop, and choose to make the selection). There is only one main function.

3) The computer's data is stored in the computer in binary form. The location where the data is stored is his address.

4) Bit is a bit that means 0 or 1. Byte is the byte, one byte = eight bits.

The concept is often tested:

1, the compilation pre-processing is not part of the C language, does not account for the running time, do not add a semicolon. A program compiled in C language is called a source program, and it is stored in a text file as an ASCII value.

2, define PI 3.1415926; This is wrong, must not appear semicolon.

3. There is one and only one main function in each C language program.

4. You cannot define a function in a function.

5. Algorithm: There can be no input, but there must be an output.

6, break can be used for loop structures and switch statements.

7. The comma operator has the lowest level and the assigned level is the second lowest.

Structural understanding of C language program based on C language basic knowledge

Using a simple c program example, introduce the basic structure, format, and good writing style of the C language, so that the small partners have a preliminary understanding of the c language.

Example 1: A c program that calculates the sum of two integers:

#include main() { int a,b,sum; /*Define the variable a,b,sum as an integer variable */ a=20; /* assign the integer 20 to the integer variable a*/ b=15; * Assign the integer 15 to the integer variable b*/ sum=a+b; /* assign the sum of the two numbers to the integer variable sum*/printf ("a=%d,b=%d,sum=% d", a, b, sum); /* output the calculation result to the display */ }

Key notes:

1. Any c language program must include the following format:

Main() { }

This is the basic structure of the C language, and any program must include this structure. You can not write anything in parentheses, then the program will not execute any results.

2, main () --- in the c language called "main function", a c program has only one main function, any c program always starts from the main function, a pair behind the main function Parentheses cannot be omitted.

3. The content enclosed by braces { } is called the function body of the main function. This part is the content to be executed by the computer.

4. There is a semicolon (;) after each sentence in { }. In c language, we call a sentence ending with a semicolon a c language statement, and the semicolon is the end of the statement.

5, printf ("a=%d, b=%d, sum=%d", a, b, sum); ---- by executing this c language system provides us with the screen output function directly used, the user You can see the results of the operation. After the program runs, the following results will be displayed on the display:

a=20, b=15, sum=35

6, #include

Note: (1) Start with ## (2) Do not end with a semicolon. This line has no semicolon, so it is not a statement. It is called a command line in C language, or it is called a "precompiled processing command".

7. The part of the program that starts with /* and ends with */ indicates the comment part of the program. Comments can be added anywhere in the program, added to improve the readability of the program, but the computer completely ignores the contents of the main function. The comment section, in other words, the computer as a comment part does not exist in the main function.

C program generation process

The C program is compiled from the source file to generate the target file, and then connected to generate the executable file.

The extension of the source program is .c , the extension of the target program is .obj , and the extension of the executable program is .exe.

Identifier

When writing a program, you must name functions, variables, and so on. This name is called an identifier. The naming rules for identifiers in C are as follows:

Identifiers can only consist of letters, numbers, and underscores;

The first letter of the identifier must be a letter and an underscore;

Identifiers distinguish between uppercase and lowercase letters, such as If and if are two completely different identifiers.

The legal identifiers are as follows: A6, b_3, _mn Illegal identifiers are as follows: ab#12 , 8m , tr3:4 , yes no

The identifier cannot be the same as the keyword with special meaning in the program. It cannot be the same as the function name and C language library function compiled by the user. In the program, the various identifiers should not be repeated as much as possible to distinguish. When choosing variable names and other identifiers, you should pay attention to "knowing the name".

The identifiers are divided into the following three categories:

1, the keyword

A keyword is a type of identifier that has a specific meaning and is specifically used to describe a specific component of the c language and cannot be used as an identifier for the user.

Auto break case char union do double else enum extern goto if int long short signed static sizof struct switch unsigned void for while typedef continue float return typedef default

2, predefined identifier

Predefined identifiers also have a specific meaning in the C language, but can be used as user identifiers. The predefined identifiers fall into two categories:

(1), library function name, such as (printf, scanf, sin, isdigit, etc.) (2), compile processing command name, such as (define, include)

3. User identifier

The identifier that the user defines himself or herself is called a user identifier. Regardless of how you customize the identifier, you must conform to the three naming conventions for the identifier.

constant

The amount by which a value cannot be changed during a program run is called a constant. There are five types of constants: integer constants, real constants, character constants, string constants, and symbolic constants.

(1) Numerical conversion

Four manifestations of numbers:

1: Binary: All numbers consist of 0,1, and every two digits will not appear in the binary number. Example: 2: Octal: Start with the number 0 (note that it is not the letter O, o), all numbers are composed of 0~7, every eight digits, one will not appear in the octal number. Example: 0112, 0123, 077, etc. 3: Decimal: All numbers are composed of 0~9. Every tenths and one decimal, 10 will not appear in the decimal number. Example: 0, 12, -15, etc. 4: Hexadecimal: Start with 0x or 0X (number 0 plus letter x), all numbers are composed of 0~9, A~F (or a~f), every sixteen Further (where A, B, C, D, E, F represent 10, 11, 12, 13, 14, 15 respectively) Example: 0x4A, 0X14c7, etc.

Inside the computer, the numbers are represented and stored in binary form. The ordinary decimal digits input by the user must be converted into binary by the computer to be stored in the computer. Similarly, the operation result of the computer is also binary. Generally, it is converted into a decimal number. The output is read to the user and this conversion is usually done automatically by the computer.

(1) Convert decimal to binary, octal, and hexadecimal

Divide: Divide the decimal number by 2, record the remainder, and the obtained quotient continues to be divided by 2 until the quotient is 0, and then the remainders obtained from each other are arranged in reverse order from the back to the front, and the resulting remainder number sequence is the corresponding decimal number. Binary number. The octal and hexadecimal conversion methods are the same as above.

Example: The value of the decimal number 13 converted to a binary number is 1101, the conversion octal is 015, and the conversion to hexadecimal is D.

(2) Convert binary, octal, and hexadecimal to decimal

Product summation: Multiply each bit of the binary from low to high (lower right, left high) by 20, 21, 22 respectively. . . . And then sum these products together.

For example: =(13)10 (317)8= (23E)16=

(3) Conversion between binary and octal, hexadecimal numbers

1: Binary to octal: Converts every three digits from right to left into a decimal number, and the resulting data combination is the corresponding octal number (note: the high digit is less than three digits). Example: (010 110 111) 2=(267)8 2: Binary to Hexadecimal: Convert every four digits from right to left into a decimal number, and combine the resulting data into the corresponding hexadecimal number (note : The high position is less than four digits to fill the zero). Example: (0101 1011) 2 = (5B) 16 3: Octal conversion binary: Each digit is converted to a three-digit binary number Example: (13) 8 = (001 011) 2 = (Note: remove the first two 00 Because 0 has no meaning in the high position. 4: Hexadecimal conversion binary: Each digit is converted to a four-digit binary number: (E3)16=(1110 0011)2

b) integer constant

There are three forms of integer constants: decimal integer constants, octal integer constants, and hexadecimal integer constants.

(Note: There are no integer constants in the c language that directly represent binary. Binary does not appear in the c language source.)

Write as follows:

Decimal integer constants: 123, 0, -24, 85L (long integer constant) and other octal integer constants: 051, -026, 0773, etc. Hex integer constants: 0x55, 0x1101, 0x, 0x5AC0, -0xFF . Where L is a long integer.

(3) Real constants

Real constants come in two forms: decimal form and exponential form.

Decimal form: 5.4 0.074 -23.0 Exponential form: 5.4e0 4.3e-3 -3.3e4

(1) A real constant with a fractional part of 0, which can be written as 453.0 or 453. (2) When expressed in decimals, the two sides of the decimal point must have a number, which cannot be written as ".453" and "453.", but should be written as "0.453" and "453.0". (3) When using the index method, there must be a number before e, and the index after e must be an integer (note: the integer order code can be positive, negative, or octal, hexadecimal, but must be an integer) .

(four) character constants

The character constant is marked with a pair of single quotes ' ', and there are two types of character constants in the c language:

(1) A character enclosed by a pair of single quotes, such as 'a ', 'r', '#'. Note: 'a' and 'A' are two different character constants.

(2) enclosed by a pair of single quotes, beginning with a backslash \ followed by a number or letter, such as '', where "" is the meaning of escaping, followed by different characters to indicate different meanings, such Character constants are called escape characters. The details are as shown.

The meaning of the escape character escape character ASCII code

Carriage return linefeed 10 Skip to the next tab position 9 \b Backspace 8 Enter 13 \f Paper feed 12 \\ Backslash "" 92 \ ' Single quotation mark 39 \" Double quotation mark 34 \a Ringing 7 \ddd 1~3 digits octal number represented by character \xhh 1~2 digits represented by hexadecimal number

Five) string constants

In C language, a sequence consisting of several characters enclosed in double quotes is a string constant.

Example: "ni hao" "happy" and so on.

(6) Symbolic constants

The symbolic constant is a constant defined by the macro definition "define", and the identifier available in the C program represents a constant.

Example: The c program for calculating the area of a circle.

#include #define PI 3. main() { float r,s; r=12.5; S=PI *r*r; printf("s= %f ",s); }

Description:

#define is a macro definition. All the places where PI appears in this program represent 3., and PI is called a symbol constant. It is customary to use uppercase letters to represent symbolic constants and lowercase letters to represent variables, which makes it easier to distinguish.

variable

A variable is the amount by which its value can change. A variable must have a variable name that occupies a certain memory location in memory, and the value stored in the memory location is the value of the variable. Different types of variables have different sizes of their storage units, and variables must be defined before they can be used.

(1) Integer variables

Integer variables are divided into four types: basic (int), short (short int or short), long int (long int or long), and unsigned int (unsigned short, unsigned long).

Different compiler systems have different specifications for the number of bits and values occupied by the above four types of integer data.

Type specifier

University c language must back to the basic knowledge _c language basic knowledge Daquan

The word signed indicates "signed" (that is, there are positive and negative numbers). If you do not write signed, it is implicitly indicated as signed. Unsigned is used to describe "unsigned" (only positive numbers).

(2) Real variables

In C language, real variables are classified into single precision type ( float ) and double precision type ( double ). Such as:

Float a , b ; double m ;

In vc, float type data occupies 4 bytes (32 bits) in memory, and double type data occupies 8 bytes. Single-precision real numbers provide 7 significant digits, and double-precision real numbers provide 15 to 16 significant digits. Real constants are not divided into float and double. A real constant can be assigned to a float or double variable, but the variable intercepts the corresponding significant number in the real constant according to its type.

Note: Real variables can only store real values. You can't store real values with integer variables, or you can use real variables to store integer values.

(three) character variables

Character variables are used to store character constants, defining the form:

Char variable name;

The keyword char defines a character data type, which occupies one byte of storage unit.

Example: char cr1, cr2; cr1= 'A', cr2='B';

When a character is assigned to a character variable, the character itself is not stored in memory, but the ASCII code corresponding to the character is stored in the memory unit. For example, the character 'A' has an ASCII code of 65 and is stored in memory as follows:

Since the characters in the memory are stored in ASCII code, its storage form is similar to the storage form of the integer, so the character data in the C language can be used in common with the integer data. One character can be output in the form of characters, and integers can also be used. The form output, character data can also perform arithmetic operations, which is equivalent to computing their ASCII code.

Automatic conversion and cast of types

When the types of data in the same expression are different, the compiler will automatically convert them into the same type before calculating. The conversion priority is:

Char "

Outdoor Antenna

With the rapid development of mobile communication equipment, in the mobile communications network engineering design, according to the requirements of the network coverage, traffic distribution, anti-interference requirements and network service quality and so on the actual situation to select the base station antenna, the communication base station antenna is currently on the market work the characteristics of the narrow frequency band, such as directional literal outdoor antenna, The operating frequency band is 860~960Mhz. Those multi-band antennas have the characteristics of high manufacturing cost and complex structure. With the development of communication technology, especially the popularization of 3G communication technology, such antennas are difficult to meet the market requirements. Therefore, to avoid the above problems, it is necessary to provide a base station antenna that is simple to manufacture, low cost, and reliable in performance to overcome the alleged defects in prior art.

Outdoor Antenna for TV,Outdoor Antenna for WiFi,Outdoor Antenna for Booster,Outdoor Antenna for Router,Waterproof outdoor Antenna

Yetnorson Antenna Co., Ltd. , https://www.yetnorson.com

This entry was posted in on