This article will help you learn C language and talk about the basic knowledge of C language (data types, variables, functions, arrays, etc.). I hope it will be helpful to everyone!
C language is a computer language , widely used in low-level development, using the language to write code programs and solve problems
So for the computer major, C language and learning C language are very important
As far as computers are concerned, the initial implementation of binary code (1/0) was achieved by powering on the computer to communicate with the computer and then forming a binary code
But It was too troublesome, so we developed mnemonics (assembly language), and then formed the B language, and then developed the C language
And then various interpreted languages appeared (Java, python, etc.)
Recommended VS2019 compiler
#include<stdio.h> //<>内是头文件名称;stdio代表standard input output; 即标准输入输出头文件(与后面所执行任务要用的库语言所关联) int main() //主函数,程序的入口(有且只有一个); { //int 代表整型;即表示main函数调用返回整型值 任务; return 0; }
char character short (int) short integer type int integer type long (int) long integer type long long (int) long integer type
float single-precision floating-point type double double-precision floating-point type (integer type is used for integers, and floating point type is used for decimals)
There are so many data types, it is for more convenience It’s good to apply for memory space from computer (try to save space and optimize memory )
From the above The memory applied for each data type is: 1 2 4 4 8 4 8 (unit bytes, individual differences vary depending on the number of computers)
Example; short is 2 bytes, which is 16 bits (binary)
Range: the minimum is all 0, which means 0; the maximum is all 1, the range obtained by the weight bit is 2*10^16-1
Variables are divided into local variables and global variables
Local variables: In the local scope where local variables are located
Global variables: the entire project
Local variables: the period starts when entering the local scope and ends when leaving
Global variables: the life cycle of the program
Note: When the defined variable has the same name, the local priority## in the local scope #;
C language and law stipulate thatvariables must be defined at the front of the current code block.
In the coding process, it is inevitable to encounter the repeated use of a certain set of statements. Creating a function at this time can make coding much easier and faster - simplifying reuse.
int Add(int x, int y) { int z = 0; z = x + y; return z; } int main() { int a = 10; int b = 20; int ret = 0; ret = Add(a, b); printf("%d\n", ret) return 0; }
The array is an Grouping a collection of elements of the same type
Arithmetic: Multiply* Division/Remainder % Addition Subtraction-
Shift (2 Base): First represent the number in binary and shift it, and then represent it into the corresponding number after the shift注意区别=与==:一个是赋值,一个是判断相等
(操作数个数决定是单还是其他,例 1+2:1和2是操作数,为双目操作符)
即“ ”中的内容(例:“abc”)
sizeof(arr[])计算内容包括“\0”,算作一个bite
strlen(arr)不包括“\0”,计算字符串内容长度(需要审引库函数—
)
\0是一个字符,还有\t,\n等代表不同意思的字符
转义字符则是转变原来的意思
例如你想单纯打印\n,那么则需要在“\n”前再打一个“\”,来转变“\n”原本的意思
注释即用来注明,解释代码步骤的意思,让自己和读者能更好的理解
C语言——/* */ C++——//
if(条件) 多选择:if(条件) 执行语句; 执行语句; else \\反之 else if(条件) 执行语句; 执行语句; else...
while循环: 初始化; while(条件) { 执行和调整语句;} for循环 for(初始化;条件;调整) { 执行语句; } do while循环 do { 执行和调整语句;} while(条件)
注:while先判断条件,符合再执行语句,而do while循环先执行语句,再判断条件是否再进行循环;在长幅篇的代码中,用for循环比较适合,用while不利于更改如果有需要的话
相关推荐:《C视频教程》
The above is the detailed content of Introduction to C language: talk about basic knowledge (data types, variables, functions, arrays, etc.). For more information, please follow other related articles on the PHP Chinese website!