1.C Language Brief Introduction
C language is a process-oriented language, the program can be written to run on the major operating systems, such as Windows,linux,unix,mac,android,ios, and C language written applications more efficient (the same hardware, about 5 times times faster than Java), Suitable for the development of the bottom, embedded, mobile applications, the major processes of the operating system are developed using C. However, C language has its own shortcomings, poor transplant, (that is, C language written on the WINODWS application on the Linux system to run, may have to change the corresponding system library), over-reliance on the major operating system API.
Tools for 2.C language development
C language has corresponding development tools for different platforms (operating systems)
Functionally divided into editors and Ides, the editor provides a simple code-writing capability (Notepad for Windows), while the IDE is a tool that integrates features such as program development, testing, deployment, and team management.
Windows:editplus,visualstudio
Linux:vi,vim
Mac:xcode
3. The first C language Program 3.1 prepares the first C language program.
#include <stdio.h>void main(){ printf("Hello World "); getchar();}
This is the C language program is the simplest program, the purpose of the program is to print a word to the console HelloWorld.
Description of the 3.2 HelloWorld program
Each C language program must contain a function called Main, or the program cannot compile, and the execution of the program starts from the "{" code block of the main function and ends with "}". As mentioned before, C is a process-oriented programming language, and the components of a program are composed of one function. You must include the specified header file in the program before calling the function, where printf () is defined in the Stdio.h header file. This means that the string parameters passed () are printed to the console. In order to enter any character, the interrupt program calls the GetChar () function, and you can see the printed string contents in the console, otherwise it's a flash.
3.3 C Language Execution flow
采用Windows平台,编译器采用Visual Studio2013提供的编译器。
When you write a C program (named HELLOWORLD.C), you can run the machine code of the source code compilation cost platform directly from the compiler provided by the platform. But the middle process takes 4 steps.
1. Editor: The C programmer uses the editor or the IDE to write the source code according to the C language characteristics. The source code suffix is named. c
2. Compile: The source code after the completion of the use of a specific platform compiler compiler generated machine code, if the program has errors, during the compilation will be exposed, but more of the run-time found in the bug. The result of compiling the output generates an object code, such as the helloworld.obj here. Compilation is a VS2013 developer command prompt using the C:\Program Files (x86) \microsoft Visual Studio 12.0\common7\tools\shortcuts catalog, using CL HELLOWORLD.C can be.
3. Link: Combine the various modules generated by the compilation, and then add the necessary code modules from the program provided by the C language to combine them into an executable file. A file with the suffix. exe is on Windows.
4. After the above steps are not error can run the program.
Notes for 3.4 C language:
Comments are written to developers to illustrate the functional information of the program, and the content of the comments will not be compiled. The C language supports single-line (//) and MultiRow (/**/) annotations, where a single line is the name of only one line of content, and multiple lines of comments can annotate multiple lines of content.
After adding comments to the HELLOWORLD.C program, well-accustomed developers should write more comments.
#include <stdio.h > Span class= "hljs-comment" >/* Import header file stdio.h, this file contains the standard input/output */ /* the main method of the definition program, If the program does not have a main method, it cannot compile * any C program has only one main function, which determines where the program starts executing. */ void main () //void means that the main function has no return value { Span class= "hljs-comment" >//c the execution of the program, starting from the main function and ending with the main function. //Use the printf () function in the stdio.h header file to print a word (passed string parameter) to the console printf (" My first C program, Hello World ") ; //called the function must include a header file that specifies the function to be defined. printf ( "\ n Print Again" ) ; //the output parameters are printed again after wrapping, only the function that already exists can be called getchar () ; //stdio.h () function called GetChar header file: Wait for a character to be entered, exit the program }
Introduction to the C language advanced in C language