Free C language tutorial

Chapter 1 Initial C Program  1-1 Initial C language
 1-2 C program structure
 1-3 practice questions
 1-4 essential main function
 1-5 Good habits
 1-6 Program Explanation – Notes
Chapter 2, Data Types in C  2-1 C Identifiers
 2-2 Exercises
 2-3 variables and assignments
 2-4 basic data types
 2-5 Formatting Output Statements
 2-6 Exercises
 2-7 Unchangeable constants
 2-8 automatic type conversion
 2-9 Mandatory type conversion
Chapter 3, Operators in C
Chapter 4 C program structure statement
Chapter 5 Secrets of Functions
Chapter 6 Array

Chapter 1 Initial C Program

Briefly describe the C language and write the first Hello World program. Introduce the composition of the C program, what is the main function, the specification in the C language; explain what is the meaning and importance of writing comments and writing comments.

Initial C language

Once the C language emerges, it is rapidly popularized and popularized around the world with its features such as rich functions, strong expressiveness, flexibility, and wide application. C language is not only efficient but also portable, and can be used to develop application software, drivers, operating systems, and so on. C language is also the originator language of many other high-level languages, so learning C language is a compulsory course to enter the programming world.

Here we also want to create the first C program of our programming career – HelloWorld:

operation result:

C program structure

In the previous section, we have already touched the first small program of the C language, and have a preliminary understanding of the C language. Next, we have to look at the specific structure of the C program.

Simply put, a C program consists of several header files and functions.

Looking back at the examples written in the previous section, the following is an analysis of this example:

#include <stdio.h> is a pre-processing command that tells the C language compilation system to do some pre-processing before it can be officially compiled. (About the course after preprocessing)

A function is a small unit that implements code logic.

Note: In the latest C standard, the type before the main function is int instead of void.

Practical Questions:

Which of the following options is the include header file in C language

  1. include<stdio.h>
  2. #include stdio.h
  3. #include<stdio.h>
  4. #include[stdio.h]

Essential main function

A C program has one and only one main function, the main function.

The C program is the code that executes the main function. It can also be said that this main function is the only entry in the C language.

This principle is like having only one door per elevator. If you want to take the elevator, you must enter from this door. The int in front of main is the type of main function, just like what the elevator is.

Printf() is a format output function, so remember that its function is to output the specified information on the screen, which will be explained in detail later. E.g:

Return is the return value of the function, and the returned value is different depending on the function type.

\n is an escape character, and the escape character can be viewed in WIKI.

Note: The C program must be executed from the main function.

Healthy habits

In order to write clear, easy to read, easy to understand, and easy to maintain when writing C language programs, the following rules should be followed when writing programs:

1, a description or a statement of a line , for example: include a header file, an executable statement ends need to wrap;

2, the statement in the function body should be significantly indented, usually by pressing the Tab key as an indentation ;

3, the brackets should be written in pairs , if you need to delete, you must delete them in pairs ;

4, when the end of an executable statement, a semicolon is required at the end ;

5. All symbols in the code are English half-width symbols.

Program explanation – notes

The notes are designed so that others can understand the programs you write, and also to make you understand the programs you have written in a few years. The comments are written to the programmer, not to the computer. So the content of the comment, the C compiler will be automatically ignored at compile time.

There are two ways to comment in C language:

Multi-line comments: /* Comments */

Single line comment: // comment line

The following are examples of using multi-line comments and single-line comments:

Operation result:

We can see that the contents of the comment are not seen in the running result of the example, which indicates that the comment is automatically ignored when compiling.

Leave a Reply

Your email address will not be published. Required fields are marked *