C Language Knowledge Collation (1): Introduction

Source: Internet
Author: User

Because of the project requirements, you need to learn iOS mobile development. The core language of iOS development is that objective-c,objective-c is a layer of object-oriented syntax based on the C language. In order to be able to master objective-c better, we first learn C language and then sublimate to objective-c on the basis of C language.

First, a brief history of C language C language
    • The C language was invented in 1972 and was first used to rewrite the Uinx operating system (Unix was previously written with sinks);
    • With the success of Unix operating system, C language has also been greatly promoted, is still the world's most popular, the most widely used one of the high-level programming language;
    • C language is a process-oriented language, non-object-oriented language.
The advantages and disadvantages of C language
    • Advantages: C language has a wealth of data types and operators, allowing direct access to physical address, the operation of the hardware; Compared with assembly language, C language is good readability, easy to debug, modify and transplant;
    • Disadvantage: Because C language is process-oriented, it is first to analyze the steps required to solve the problem, and then use the function of the steps to achieve the next step, use the time one by one to call the function can be, so its data encapsulation poor, low security (object-oriented language is one of the characteristics of the package of data) , grammar restrictions are not strict, the type of variable constraints are not strict, the array subscript do not check, and so on.
What C language can do
    • Because C language has rich data types, it is suitable for writing database software (such as Oracle, DB2), etc.
    • Because C language has a powerful data processing ability, and allows direct access to physical address, directly to the hardware operation, it is suitable for writing system software, graphics processing, microcontroller program, embedded system development;
    • Many of the underlying operating systems are written in C, such as Android, Linux, and later Unix rewritten in C.
Second, c program code Analysis 1. #include <stdio.h>
    • #include is one of the pre-processing instructions in C, so-called preprocessing, which is done before compiling, the preprocessing instruction usually begins with #;
    • After the #include instruction follows a file name, the preprocessor discovers the #include instruction, finds the file according to the filename, and includes the contents of the file in the current file. The text in the included file replaces the #include instruction in the source file as if you had copied all the contents of the contained file to the location of the #include instruction;
    • If the included file extension is named. h, we call it "header file", the header file can be used to declare the function ("function" is the object-oriented "method"), in order to use these functions, you must first use the #include directive containing the function of the header file;
    • The #include directive is not limited to. h header files, and can contain any code files that the compiler can recognize, including. C,.hpp,.cpp, and so on, even txt,.abc.
    • Note that why stdio.h use angle brackets to <>, while my.txt use double quotes ""? This is very good difference, if the system comes with the file, it is best to use <>; if it is the developer's own files created, it is best to use "".
2.main function
    • A C program has only one main function, which is the entrance of the whole C program;
    • The return value of the main function is type int, receiving 2 parameters, in fact, can not write parameters;
    • The main function can also not write the return value type, but it does not mean that the function does not return a value, but rather that the return value type is type int and void represents a function that does not return a value because the C language syntax restriction is not strict.
3.stdio.h

Stdio.h is a header file in the C language library that defines some standard input and output functions.

Ii. steps for developing and running C programs

The step diagram is as follows:

1. Writing procedures

The C language source file has the extension ". C", and the source file is stored in ASCII format and cannot be executed directly by the computer because the computer can only recognize binary instructions, that is, 0 and 1.

2. Compiling (VC environment)
    • The C source program is translated into a computer can recognize the binary form of the target code file, this process is called compilation, by the C compiler to complete;
    • While compiling, the syntax of the source program is also checked. If a syntax error occurs, the compilation fails. If the compilation succeeds, the target file is generated with the same name as the source program file with the extension ". obj". For example, mj.c compile to generate the target file mj.obj;
    • Each source file is compiled separately, and if there are multiple. C source files in a project, compiling successfully generates multiple corresponding. obj targets. In general, there is a correlation between the target files, such as a.obj may call a function defined in b.obj, so none of them can be executed by the computer alone, and the destination file does not contain the library functions that the program needs to run.
3. Links (VC environment)
    • The process of combining all the associated obj target files, as well as the system-provided C library functions, to generate the executable file, called a "link";
    • The file name of the executable file that the link generates has the same name as the source program file, and the extension is ". exe", which the computer can execute directly.
4. Running
    • * If you are in a Windows environment, simply double-click the ". exe" file to run the C language program.
5. Summary

    • 1. Execute the # include directive before compiling, copy the contents of the stdio.h into the source program;
    • 2. Compile the source program, generate the target file;
    • 3. Link C language function library, generate executable file;
    • 4. Run the executable file and output "Hello, world!" on the screen.

Classification of function (1) function in C language

C-language functions can be divided into 3 categories:

    • 1. The main function, which is the main function. There can be only one or one main function in each program. The C program always executes from the main function, regardless of where the main function is written
    • 2. Developer custom functions, optional, unlimited number
    • The 3.C language provides library functions, such as the output function in Stdio.h printf () and the input function scanf ()
(2) Declaration and definition of functions
    • 1. In the standard C language, the order in which functions are defined is fastidious, and by default only functions defined by the following can be called by a function that is previously defined.
    • 2. If you want to write the definition of the other functions behind the main function, and the main function can call these functions normally, then you must make a declaration of the function in front of the main function.
    • 3. In a large C program, in order to sub-module development, the function is generally declared and defined (that is, implementation) in 2 files, the function declaration is placed in the. h header file, the function definition is placed in the. C source file.
(3) Formal parameters and arguments of a function

When defining a function, the variable defined in () after the function name is called a formal parameter (formal parameter), and the value passed in when the function is called is called the actual parameter (argument).

C Language Knowledge Collation (1): Introduction

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.