In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to write the first program in C language". In daily operation, I believe that many people have doubts about how to write the first program in C language. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about how to write the first program in C language. Next, please follow the editor to study!
Code # include int main () {puts ("Hello World"); return 0;} II. Header file
# include
When C language developers write many commonly used functions and put them under different files, these files are called header files. If you want to use these functions, you have to introduce the header file where the function is located, otherwise the compiler will not find the function.
This concept is similar to guide packages in Java and inverted libraries in Python. Packages and libraries can be imported through the import keyword in Java and Python, so that all methods or functions in the package or library can be called.
In the C language, the header file is introduced using the # include command, with the file name in between. There can be spaces or none between # include and.
Header files are suffixed with .h, while C code files are suffixed with .c. They all belong to text files, and there is no difference in nature.
The # include command simply copies the contents of the header file to the current file and compiles it along with the current file. If you copy the contents of the header file to the current file, then you do not have to introduce the header file.
Note: the header file is not a necessary part of the C language, if the function of the following program does not have the functions in the header file, then there is no need to introduce the header file. For example:
Int main () {return 0;}
The puts function is not used here, so there is no need to introduce a header file.
Third, the concept of function
Puts ("Hello World")
This line of code will show "Hello World" on the monitor, which is equivalent to System.out.println in Java or print in Python, meaning output and print.
In C language, there are some statements that do not need parentheses, while others must have parentheses, and these parentheses are called functions (Function).
Although we are in the process of tapping the code, only one sentence of code is needed to achieve the desired effect. However, the bottom layer to achieve these functions is more complex, often the combination of software and hardware, but also need to consider all aspects. If all these functions are to be done by programmers, it will undoubtedly increase the learning costs of programmers and reduce the efficiency of programming.
As a result, the code has long been specifically classified in different files, and each piece of code has its own unique name. When we need to use this feature, we just need to add a () to the corresponding name. A piece of code like this can perform some functions independently, and it can be called repeatedly after being written at once, which is called a function. Like puts (), it is a piece of code that has been written and has the function of output.
IV. Custom functions and main functions
The functions that exist in C language are called Library Function functions. Library is a very basic concept in the programming language. It can be simply thought of as a collection of functions, equivalent to a folder on disk, and functions are the sub-files under it.
The libraries carried by the C language are called standard libraries (Standard Library), while those developed by other companies or individuals are called third-party libraries (Third-Party Library).
Of course, if both the standard library and the third-party library do not have the function methods they want, they can also write their own functions to expand the function of the program, and this series of operations are custom functions. In the way of writing and using, custom functions and library functions are the same, but they are written by different institutions and different people.
As in the code above, int main () {function}
Int is the abbreviation of integer, which means "integer". What it means here is to tell us that the value returned by this function can only be an integer.
Main is the name of this function.
() indicates that this is a function definition.
{}; inside the curly braces is the function that this function is going to implement.
Note:
C language stipulates that every program must have one and only one main function, and the main function is also called the main function, which is the entry function of the program. Every program starts from the main function to the end of the main function. (the function ends only when it encounters a return or executes to the end of the function. )
This is equivalent to the main main method in Java, which is required for the Java program to run.
So, if there is no main function, then the C language program does not know the starting entry, and an error will occur at run time.
At this point, the study of "how to write the first program in C language" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.