Overview and C language data types

First, the idea and significance of C programming:
1. Complete a case in C:
/ * Output Word the Hello! /
#Include "stdio.h"
void main ()
{
printf ( "the Hello Word \ the n-!");
}
the above is a C language source code, we can try it on your own C language tools, look at the output, some students might say, the teachers do not understand what that means, it does not matter, it is not the code itself, but others, that what is most important? I would say, whether it is school, or family business; and regardless of the cause, or the country industry, the right ideas is the most important. Only under the guidance of correct thought, in order to bear the so-called "good fruit." Likewise, the essence of programming and code written training program is also thought to strengthen and expand learning a language or development tool, grammatical structure, function calls are minor, understand its ideology after, you can use the work, implementation code a. For the different tools we can do it by analogy.
Second, the computer programming language
before the introduction of the C language, the program first language rough idea.
1. The machine language
machine language is the language recognized by the computer, also called binary language. Series of computer instructions is a binary number composed of 0 and 1 to express language computer operations. Machine language features are: the computer can directly identify, does not require any translation.
2. Assembly language
assembly language is machine-oriented programming language. In order to alleviate pain using machine language programming, with a string of letters or symbols instead of binary machine language code, easy to understand and so put into a machine language using the assembly language. Thus, the use of assembly language is easy to read and understand than a machine language program.
3. The high-level language
As the assembly language depends on the hardware system, and the more the number of mnemonic language, so the use of it is still not convenient enough. In order to make the program language can be closer to the natural human language, while not dependent on computer hardware, so have the high-level language. This language, its syntax is similar to English, and as far away from direct hardware operation, and easy to be understood by the average person to use. In which a greater impact, using a common high-level languages Fortran, ALGOL, Basic, COBOL, LISP, PROLOG, C, C ++, VC, VB, Delphi, Java and so on.
Third, the history of the C language
C language is the basis for the development of UNIX developer of Dennis • Ritchie (Dennis Ritchie) and Ken • Thompson (Ken Thompson) in 1970 developed the BCPL language (referred to as B language) and on perfected. The early 1870s, AT & T Bell Lab programmers • Dennis Ritchie for the first time the B language to C language.
C language is a process-oriented language, while having the advantage of high-level language and assembly language. C language can be widely applied to different operating systems such as UNIX, MS-DOS, Microsoft Windows and linux and so on.
On the basis of the C language has developed a variety of programs to support the style of the C ++ language, Java, JavaScript and Microsoft's C # language widely used on the network. In other words, after the C language to learn, it will be more relaxed when re-learn other languages.
Fourth, the simple little program
before leading to the c language program in the world, first of all not to fear for the c language, that language should be patented academics or researchers. c language is the common wealth of mankind, through the efforts of ordinary people as long as you can learn to master knowledge. By following a simple program to take a look at what it was like c language program.
This example program implements the functions can only display a message "hello word!" The first glimpse of the faces c program. Although this simple little program is very short, but full description of the program was started by c what position, what position ended.
/
! * Output Word Hello /
#include "stdio.h"
void main ()
{
the printf ( "Hello Word \ n-!"); / Output string to be displayed /
}

  1. #include "stdio.h"
    This statement is related to the function of pre-processing operations. include file contains a command called, the contents of the back angle brackets is called a header file or the first file. Of course, it can also be used as double quotes angle brackets.
    2. The blank line
    the second line code example.
    c language is a more flexible language, so the format is not fixed, arrested in a grid. In other words, spaces, blank lines, tabs and does not affect the program. Some readers will ask: "Why have these extra spaces and blank lines it?" In fact, it is like life, like writing on paper, although you can bring a piece of paper to write on, but also typically squares printed on line by line and spaced apart from each piece of text in the paragraph above the paper, and more beautiful naturally specification. The rational use of these spaces, blank lines can make the computer program out of more standardized, and finishing on the future of reading play an important role.
    3.main function declaration
    void main ()
    This line of code representative of the main function declaration means no reference no return value of the function (reference cell 13), wherein the void is a keyword, the meaning of a keyword that represents empty. Function is the basic unit constituting the program.
    In this part of the function it is called a function head portion. In each program, there will be a main function, then what is the main function of the role is it? It is the main function of the inlet portion of a program. In other words, the program is started from the main function of the head, and then enter the main function, the main function of executing content.
    4. The body of the function
    when the main function in the above description, a term referred to - head ,, then think about the function, since the function headers, it should also have the function of the body, right? Yes, a function is divided into two parts: First, the function head, one body of the function.
    Program braces {} these two statements constitute the body of the function blocks, the function of the body may also be called a function.
    5. Execute the statement
    printf ( "hello word \ n! ");
    Action execute a statement that the contents of the function body to perform. Each executing the statement are ";" at the end. This line of code is a simple example of the most complex. The line of code while seemingly complex, in fact, not difficult to understand, printf function is to generate formatted output can be simply understood as the role text or symbols output to the console. Parameters in brackets called function, the brackets can be seen that the output string "hello word! \ N", where \ n called escape character.
    6. Notes code
    to establish such a concept: the program is compiled for others, so that people understand the first one. Especially if you might join a team in the future, along with dozens of individuals or even hundreds of individual cooperation program, coordinated with each other, the more clearly written comments should be plainly.
    printf ( "hello word \ n! "); / output string to display /
    content of this line in / ** / comment is between. Good code format specifications and add detailed notes to write, is a good programmer should have good habits.
    V. constant:
    data processing language C are constants and variables in two forms
    1. Constants
    As the name suggests, the constant value is not the amount of change in the program. Divided by type are as follows: integer constant, real constants, character constants, string constants, and enumeration constants (enumeration on the line here, we know, do explain).
    Examples of the types of constants Remarks
    integer constant 10, -30,0 comprises a positive or negative whole number including zero, and all integers
    real constant 3.14, since the computer -0.56,18.0 real numbers are floating-point format table of formula , i.e. the position of the decimal point may be floating, i.e. because some real constant real numbers may be referred to, may also be referred to as a floating
    character constant 'X', 'x', '0', '9' by a single quote any character enclosed
    Constant string "Hello!", "K88" , "9" with a pair of double quotes zero or more characters
    six variables
    1. Why use variables
    / * enter a number, the output is odd or even * /
    #include "stdio.h"
    void main ()
    {
    int n-;
    the printf ( "enter a number:");
    Scanf ( "% D", & n-);
    IF (n-% 2 == 0)
    {
    the printf ( " even number \ the n-");
    }
    the else
    {
    printf (" odd \ the n-");
    }
    }
    These are the source code of the program a C language, we can be on their own C language tools under test, look at the implementation of the results: you It found that when you just enter an integer, can be determined that the number is odd or even. Then you enter this number in fact, it is uncertain, may be 11 or may be 12 That can change, it can only set a variable to be completed, there are variables that our program has become more practical perfect.
    There is now number 10, followed by the use of, for example, that the number 10 is 1,2,3,4,5,6,7,8,9,10 it will need 10 to occupy space on the storage space, but If there is a variable, each time you use it is a number, use the number after another and back, then we only occupy a space. Therefore, the use of variables can reduce space usage during program execution.
    2. Variable can solve any problem
    From the above description of the case and, in fact, we can also see that variables can actually help us to save space, but also based on the implementation of the program, different values used to determine the results of the program to be correct in a statement the results .
    3. The variables and constants difference
    variables can be used to store data, which is assigned to the computer section of memory. Is called a space, and is a constant amount can not be changed during program execution, the instructions may not be directly through the use of, for example: 3, 'a', " abc" and the like. That in the end what is variable, how to use variables, please continue to read.
    4. The variable naming rules and
    variables is constant with respect to the terms, the amount thereof during program execution is referred to as a variable value can be changed.
    The variable name is a symbolic name memory storage unit. To access its corresponding memory cell by a reference symbol name.
    Named variable names should comply with the following basic naming convention
    (1) A variable name can only be letters, numbers, and underscores
    (2) must begin with a letter or an underscore variable name
    (3) variable name is not permitted to use keyword
    (4) variable names are case sensitive. Such as sum, Sum, and SUM are three different variable names
    (5). Variable names can contain any number of characters, but in general there will be a maximum length limit, related to the compiler, but in most cases do not reach this limit.
    Keywords: Programming language system reserved for the symbolic name that represents a specific meaning. As int, float, char, etc.
    defined and 5. The variable assignment
    in the C language, a variable must be defined before use. When you define a variable, you declare the type of variable and variable name. Variable is defined as the general form:
    type keyword variable name;
    Example. 1:
    void main ()
    {
    int A; /Keyword specifies the type of a variable int /
    float B; / designated keyword variable a type float /
    char C; / designated keyword char type variable a /
    a =. 1; / is assigned a variable integer int constants. 1 /
    b = 2.5; / a float variable assignment integer constant b 2.5 /
    C = 'a'; / is a variable char c assignment integer constant 'a' /
    }
    procedures standard C language are it is the main () as the beginning, which specifies the starting point of C program execution occurs only once in a C program. A C program must have one and only one with a main () as a function of the name, this function known as main function. C program always starts execution from the main function, regardless of its position in the program. In general, C statement is a semicolon.
    Example 2:
    void main ()
    {
    int A;
    A =. 1; / first executable statement /
    a float B; / Error! Since variable b must be defined before the first executable statement /
    b = 2.5;
    char C; / Error! Because the variable b must be defined before the first executable statement /
    C = 'A';
    }
    C language definitions of the variables while allowing variable is initialized (its initial value). The following
    Example. 3:
    void main ()
    {
    int a =. 1; / define integer variables and initializes a /
    a float b = 2.5; / definition of a real variable b and initializes /
    char C = 'A'; / defined string variables and initializes c /
    }
    If a variable is defined, but initialize, then the value of the variable is a random number (except static and global variables).
    Note that, in the program, with / and content / contain up, called comments. Note that left no space between the slash and asterisk. C ++ style comments // places to start, end to end of the line, and only one row, while interbank need to write each line must start with //.
    Notes can not be nested, i.e., one can not add another comment annotation.
    In a statement, the same can also define a plurality of variable type, variable between a plurality of comma as a delimiter, it does not matter the order written. For example, three may be defined as follows integer variable:
    int A, B, C;
    To define the variable while it is initialized to 0, was
    int a = 0, b = 0 , c = 0;
    but not written
    int a = b = c = 0 ;
    variable is constant with respect to the terms, the amount thereof during program execution is referred to as variable values may be changed.
    Each variable with other variables have a different name, called the variable name.
    The first character of the variable name must be a letter or underscore, followed by the characters only letters, digits, and underscores the same keywords and names not be used with the C programming language or language-related system retained (see Keyword Appendix B)
    seven simple screen output
    variable is assigned later, how to display the values of these variables it on the screen? This use to printf () function. Effect standard C input / output function printf () is the output of a string, or an output value of some variables and data format specified type, degree as shown below.
    Example: How to output a, b, c values of three variables
    #include "stdio.h"
    main ()
    {
    int = A. 1;
    a float B = 2.5;
    char c = 'A';
    the printf ( "% A = D \ n ", a); / press format of the output value of the integer variable a /
    the printf ("% b = F \ n ", a); / press real format of the output variable value of b /
    the printf ("% C = C \ n ", a); / press character format of the output variable value of c /
    the printf (" End of Program \ n-"); / output a string /
    }
    results are as follows:
    a =. 1
    B = 2.500000
    c = a
    End of program
    procedures% d,% f,% c format are characters.
    % d: decimal integer value representing the format of the output variables
    % f: represents the decimal value according to the format of the output variables, specified otherwise, output 6 implied decimal places.
    % c: represents the value of the output variable character (a character); \
    n-output represents a line break is about to move the cursor to the beginning of the next line.
    The last line of the output value of the output variables do not have to directly located string (not including \ n) within the double quotation marks to the screen display. In the C language, a pair of a plurality of characters enclosed in double quotes, called a string.

Eight basic data types of classification
variables in the program to take what data type is determined by the needs of engineering tasks. C language data types can be divided into the following two categories: the first basic data types, including integer, floating point and character; second category is the type of configuration, including arrays, structures, unions, enumerations. The so-called structure data type, this means that the type is composed of several basic data types of variables according to a specific rule constructed from a combination.
So we are focused on learning the basic data types of data.
Integer. That is integer type, it can be classified into four
int Integer 4 bytes, the number represents the range 2147483647 ~ -2147483648
unsigned int unsigned integer 4 bytes, the number represents the range 4294967295 ~ 0
Long long int 4 bytes integer representing the number range 2147483647 ~ -2147483648
unsigned long unsigned long int 4 bytes, the number represents the range of 0 to 4294967295
real. I.e. also known as floating-point real number type: float (4 bytes in memory) Score e.g. a float
a float float 4 bytes, a valid bits 7 bits after the decimal point
double double 8 bytes, a decimal point 15 valid bit
long double long double type uses 16 bytes, 19 bits decimal effective
char character: occupying 1 byte.

Guess you like

Origin blog.csdn.net/SqrsCbrOnly1/article/details/91361455