Introduction to C Language

Source: Internet
Author: User

Introduction to C Language
1. Brief Introduction to C Language

C language is a process-oriented language. It can run programs on various operating systems, such as Windows, Linux, Unix, Mac, Android, and IOS, in addition, applications written in C language are more efficient (the same hardware is about five times faster than Java) and suitable for development of underlying, embedded, and mobile applications, the operating systems of various major processes are developed using C. However, the C language also has its own shortcomings and has poor portability (that is, if the application program written in the C language on Winodws is run on the Linux system, the corresponding system library may need to be changed ), it relies heavily on the APIs of major operating systems.

2. C language development tools

C language provides corresponding development tools for different platforms (Operating Systems)
The editor provides simple coding functions (Windows notepad), while the IDE integrates program development and testing, deployment and team management tools.
Windows: Editplus, Visual Studio
Linux: VI, VIM
Mac: Xcode

3. The first C language program 3.1 write the first C language program.
#include 
  
   void main(){    printf("Hello World ");     getchar();}
  

This is the simplest C language program. The purpose of the program is to print a HelloWorld statement to the console.

3.2 HelloWorld program description

Each C language program must contain a function named main. Otherwise, the program cannot be compiled, and the execution of the program starts from the "{" code block "of the main function and ends from. As mentioned earlier, C is a process-oriented programming language. The components of a program are composed of functions. Before calling a function, you must include the specified header file in the program. printf () is defined in the stdio. h header file. This means to print the string parameters passed by () to the console. To enter any character, the interrupt program calls the getchar () function and can view the printed string in the console. Otherwise, the program will flash.

3.3 c language Execution Process
On the Windows platform, the compiler uses the compiler provided by Visual Studio2013.

After compiling a C program (HelloWorld. c), you can run the machine code of the platform directly by using the compiler provided by the platform to compile the source code. However, the intermediate process requires four steps.
1. Editing: the source code written by the C programmer using the editor or IDE based on the features of the C language. Source code Suffix:. c
2. compile: after the source code is compiled, the compiler on the specific platform is used to compile and generate the machine code. If there is an error in the program, it will be exposed during the compilation, but more are bugs found during the runtime. The output result of compilation generates the object code, for example, HelloWorld. obj. Compile with the command prompt of VS2013 developer in the C: \ Program Files (x86) \ Microsoft Visual Studio 12.0 \ Common7 \ Tools \ Shortcuts directory. Use cl HelloWorld. c.
3. Link: combine various modules produced by compilation, add necessary code modules from the programs provided by C language, and combine them into an executable file. Windows is a file suffixed with .exe.
4. After the above steps are complete, you can run the program.

3.4 C Language notes:

Annotations are written to developers to describe the functional information of the program. The comments are not compiled. The C language supports single-line (//) and multi-line (/**/) annotations. As the name suggests, a single-line annotation can only comment one line of content, and multiple-line annotation can comment multiple lines of content.

After adding comments to the HelloWorld. c program, developers with good habits should write more comments.

# Include
  
   
/* Import the header file stdio. h. This file contains the standard input/output * // * main method of defining the program. If the program does not have the main method, it cannot be compiled * any C program has only one main function, determines where the program starts. */Void main () // void indicates that when the main function is executed without the return value {// C, it also ends from the main function. // Use stdio. the printf () function in the h header file prints a sentence (the passed string parameter) printf ("My first C program, Hello World") to the console "); // before calling a function, you must include the header file of the defined function. Printf ("\ n print again"); // print the output parameters again after line feed. You can only call the existing function getchar (); // call stdio. the getchar () function of the h header file: Wait for one character to enter and exit the program}
  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.