Basic knowledge of C language and several commonly used statements __c language

Source: Internet
Author: User
1.1 software, program and computer language

Software is a collection of program files that are compiled to perform certain functions.

Program is the sequence of computer instruction, the work of programming is to compile instruction sequence for computer.

People and computer communication also need to employ and computers are easy to accept and understand the language, this is the computer language. 1.2 Development of program language

1.2.1 Machine language

The machine language of a computer is made up of 0 and 1, and all the data of the computer is composed of 0 and 1.

1.2.2 Assembly language

Assembly language is a linguistic representation of these fixed binary instructions by means of symbols.

1.2.3 Advanced Language

Advanced languages are always as close as possible to the natural language and way of thinking of "Advanced animals". 1.3 Basic methods and steps of software development

1. Analyze problems and establish data models.

2. Determine data structure and algorithm.

3. Weaving process.

4. Debug the program.

1.3.1 Algorithm

Usually the computer algorithm is divided into two kinds: the numerical algorithm and the non numeric algorithm.

Numerical operation is to solve the problem of numerical solution, the non-numeric operation includes a very wide range of fields. Numerical operations have a certain mathematical model, generally have a relatively mature algorithm. There are many kinds of non-numeric operations and different requirements. The basic features of the algorithm (poor, deterministic, effective, with 0 or more inputs, one or more outputs.) Algorithm representation-Flow chart (a graph solution to a given algorithm, the flowchart is called a block diagram, it uses a set of graphics, flow lines and text description to represent the basic operation and control process of the algorithm, its advantage is the image intuitive, easy to understand, easy to modify and exchange. )

Flowchart includes start and end boxes, input/output boxes, processing boxes, judgment boxes, comment boxes, process boxes, connection points.

1.3.2 Code Implementation

Steps to create a C language program:

1. Write source code

2. Compile the source code into the target code.

3. Link Target code becomes executable program source code

The source program's code instructions are stored, and the computer uses two different formats to store the files, respectively, in both text and binary formats.

Text files include symbols for ASCII character sets. The ASCII character set includes the uppercase and lowercase letters of the alphabet. It also includes numbers from 0-9 and some punctuation marks. Binary files are made up of binary numbers.

When writing a program, we store the source code in a text file, and programmers usually create a program from multiple source code text files. The source code in the text file is converted into a binary instruction stored in a binary file through a very short time compilation and linking process. Compiling source code

The computer can not execute the source code, we have to write a compiler or translator, so that the program from the high-level language program into binary code, that is, machine language. Link

When a link is linked to an executable form, it uses multiple libraries to link the target program. A library is a collection of precompiled functions. These functions may accomplish one or more tasks.

1.3.3 Debug Program

Several different types of errors that are most likely to occur in a program are syntax error logic error development error Run-time error

2.1 Programming language Overview

The only way to learn a new language is to use it to program. For starters, the first program that is written is almost identical, showing "Hello, world" on the screen, with the word "Hello World" printed professionally.

"Example 1-1" prints Hello, world. /* First C language program print Hello, World/#include <stdio.h>//include header file stdio.h int main () {//main function printf ("Hello, word\n");//Print string return 0; Returns 0, indicating that the program is running correctly}

Although this program is simple, but for beginners, it can still become a major obstacle, because to achieve this goal, the first to write code, and then compile, link and run, and finally see the output results. After mastering the details of these operations, other things are easier.

About compiling and linking is explained in the next section, which explains the program first: line 1th contains the standard library files, including the file contains commands, and files with the extension. h are called header files. Line 2nd defines a function named main that does not accept parameter values; The statements of the main function are enclosed in curly braces; int is the return value type of the main function. Line 3rd Prints "Hello, World", and the main function calls the library function printf to display a sequence of characters. Line 4th indicates that the return value of the main function is 0,return so that the function returns a value. Line 5th ends the main function, and the curly bracket must appear in pairs.

The


is commented on in "* *  */" and after "//" to describe the program, and annotations are automatically ignored at compile time.

A C language program, regardless of its size, is made up of functions and variables. The

function has certain functions that perform a specific action, and a function that contains statements to illustrate the procedure of the operation. Variables are used to store values used during the calculation.

In this case, the name of the function is main. Normally, there is no limit to the name of a function, but main is a special function name, and each program executes from the start of the main function, which means that each program must contain a main function in a location. The

Main function usually calls other functions to help with some work, and the called function can be written either by ourselves or from a library of functions. The first line of statements in the above program section #include <stdio.h> is used to tell the compiler to include a standard input/output library in this program. Many C language source programs contain this line of statements at the beginning of the program. We will provide a detailed description of the standard library in subsequent chapters. One way to exchange data between

functions is to call a function to provide a list of values, called parameters, to the called function. A pair of parentheses after the function name encloses the list of arguments. In this case, the main function does not require any arguments, so it is represented by an empty parameter table (). The statements in the

function are enclosed in a pair of curly braces {}. The main function in this example contains the following two statements: printf ("Hello, word\n"); return 0;

When calling a function, you only need to use the function name plus a parameter table enclosed in parentheses. The above statement invokes "Hello, world\n" as a parameter to the printf function. printf is a library function for printing output, where it prints a string in the middle of a double quote.

A sequence of characters enclosed in double quotes is called a string or string constant, such as "Hello, world\n" is a string. For now, we use only strings as parameters for printf and other functions.

In C, the character sequence \ n represents a newline character, and when it is encountered in print, the output print wraps, starting at the beginning of the left end of the next line. If you remove \ n from the string (this is an exercise worth doing), the output does not wrap even after it has been printed. In the argument of the printf function, only \ n is used to represent the line break. If you are replacing a line with a program, for example:
printf ("Hello, Word
");
The C compiler will produce an error message.

The printf function never wraps automatically, so we can call the function multiple times to get a long output line in phases. The first program given above can also be written in the following form:

1 2 3 4 5 6 7 8 #include <stdio.h> int main () {printf ("Hello,");
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.