Table of contents
2. Create a new file with the suffix ending with .cpp
1. Create a new folder
2. Create a new file with the suffix ending with .cpp
As shown in the figure below, select the corresponding folder, and then click the button to create a new file. The new file must be written with a suffix.
3. Write code
#include<stdio.h>
int main(){
printf("hello world!\n");
return 0;
}
4. Compile and execute code
In vscode, first save the file, then press F5 to compile and run
code analysis
#include It is a preprocessing command, it is preloaded into the program before the code is run
<stdio.h> This is a preloaded header file, which is generally used with preprocessing commands. std means standard, and io means input and output, and h means head.
#include<stdio.h>
# int represents an integer data type, main() is the name of the main function, and all program execution starts from the main function, and the contents of the curly braces are the function body. There is only one main function in a program, and it appears Multiple can go wrong. There can be multiple .c files in an engineering project, but multiple .c files can only have one main function.
# return 0 means that the returned data is 0. The ultimate goal of each program is to get a result. The return return value can return a specific value according to the situation
# printf() is a library function, which is introduced by the standard input and input functions, and is used to output related data
int main(){
printf("hello world!\n");
return 0;
}
Summarize
When writing a C program for the first time, you may encounter many problems, such as multiple main functions in one program, a function (printf) that does not introduce a standard header file but uses a header file, and the format name is asymmetrical (the curly braces are not symmetrical), etc. . But after the baptism of ups and downs, I believe that one day I will learn something. Well, we have the next chapter goodbye, come on!