[First knowledge of C language] What is C language, the first C program, and C language data types

1. What is C language?

(1) C language is a process-oriented, compiled programming language (different from object-oriented programming languages ​​such as C++ and Java, ps: C and C++ are compatible). After compilation, an executable program (ie exe , Can be run directly).
(2) The C language is very classic and will generally be developed and used at the bottom. Linux and Mac OS are written in C.
(3) The C language supports cross-platform (! Not a cross-compiler but a cross-operating system).
(4) The C language is very close to the computer architecture, and can feel the characteristics of computer software and hardware.

2. The first C program && knowledge points

#include <stdio.h>//(1)
int main()//(2)
{
    
    
	printf("Hello world!\n");//(3)
	return 0;//(4)
}

Insert picture description here

2.1 Header file

(1) #include <stdio.h> is the standard input/output header file to be included (standard input output)
(2) #include <____.h> is used for the header file provided by the system, search in the location of the system header file The header file.
#include "____.h" is used to customize the header file, search for the header file in the current file.

2.2 main function

(1) The main function is also a function, and the return value of the main function is generally int.
(2) The main function is the entry function of the program, and there is generally one and only one. Once the program is started, it starts to execute from the main function.

2.3 Function call

(1) Call the output function in the system function library for output.
(2)'\n' is a carriage return and line feed, which is an escape character.

2.4 return 0;

Situation:
(1) In the main function (main() function), it means that there is no system return value, that is, it jumps out of the end of the program directly when it is executed.
(2) In a custom function, it means that there is no return value of the function.

3. Data Type

3.1 C language data types

char        //字符数据类型
short       //短整型
int         //整形
long        //长整型
long long   //更长的整形
float       //单精度浮点数
double      //双精度浮点数

! C language has no string type.

3.2 Why are there so many data types?

Because computers are to solve human problems, various scenes in life use various types of data.

3.3 The size of each data type

#include <stdio.h>
int main()
{
    
    
	printf("%d\n", sizeof(char));
	printf("%d\n", sizeof(short));
	printf("%d\n", sizeof(int));
	printf("%d\n", sizeof(long));
	printf("%d\n", sizeof(long long));
	printf("%d\n", sizeof(float));
	printf("%d\n", sizeof(double));
	printf("%d\n", sizeof(long double));

	return 0;
}

Insert picture description here
The above uses sizeof to calculate the size of the type, and the result is in bytes.

Guess you like

Origin blog.csdn.net/m0_46630468/article/details/112998757