I. Basic Framework of C language program, gcc compiler briefing, C comments, variables, input and output

Source: Internet
Author: User
Tags switch case

  1. Computer Language Classification

    1> machine language commands)

    2> Assembly Language

    3> Basic, C, Java, C ++, C #/. net, OC, VB, PHP, etc)

  2. Relationship between C language and C language, strong type language

    C language: A Language evolved from C language, such as C ++ and Java.

    C Language -- mainly usedUnderlying DevelopmentTherefore, the C language is also calledIntermediate Language.

    Strong type language-a variable must explicitly declare the type before use. The declared type only needs to be declared once. The type cannot be included in use.

  3. C language programming steps in GNU/Linux ):

    1> use the Vi/Vim editor to edit xx. c

    2> after saving and exiting, use gcc xx. c to compile the link.

    3> run with./a. out. If a. out is configured in the PATH environment variable, you can directly use a. out)

  4. C program structure

    # Include <stdio. h> // The first C language program and test the inclusion file int main () {# include "s. c "printf (" hello c \ n "); return 0 ;}

    In xx. c, it is generally composed of three parts.

    1> # commands start with # include # define # if.

    # Include is used to contain a file, which generally contains the header file (. h) under/usr/include ).

    2> int main () {} is called a function. main is the main function and the entry point of the program.Return type, function name, and parameter list(Multiple parameters are separated by commas). {} is called the function body.

    3> the content in function {} is a statement, and the statement ends.

  5. C program principle

    1> compile the source program xx. c)

    2> preprocessing all commands.

    3> compile the program and generate the. o/. obj file.

    4> link the program to link external resources such as library functions with the. o file to generate the. out file.

    5> load the. out file from the hard disk to the memory. Run the. out Program.

    Steps 2, 3, and 4 depend on the gcc compiler. gcc can be used directly as a command:

  6. Common gcc options

    -C onlyCompile/compiling)No link

    -O target file name ModificationTarget object)The default file name is a. out)

    -Std = c89/c99 sets the c89/c99 standard to the c89 standard compilation link by default)

    -Wall displayAll warnings All Wall)Information warning does not affect program compilation and running)

    -E onlyPre-Processing)

    -S generationAssembly)File

    ......

  7. # Include "xx" # differences between include <xx>:

    "" Is first inCurrent directory .)Find, go to the system directory, <> just goSystem Directory (/uer/include /)Find. # Do not include non-blank characters before include.

  8. C language comments

    Annotations are a way of communication between programmers. Annotations are not involved in program compilation, linking, and running.

    1> comment on a single row // start to end with this row

    2> multi-line comment/* start */end can contain any number of characters and any number of lines

    Note: multi-line comments cannot be nested.

  9. C language coding specifications:

    1> separate statements into multiple rows

    2> space can better differentiate code

    3> indentation can better differentiate hierarchies. Generally, 2-4 spaces are indented.

    4> Empty lines can better differentiate code modules

    5> the name of a variable or function must be meaningful. Multiple words are distinguished by the camper or underscore (_) method.

  10. Variable

    1> Variables

    It is actually an area of memory, and the variable name corresponds to the memory area. Before using the variable, you must declare the type. The type is the type of the variable. You can determine the size of the memory occupied by the variable.

    2> type

    It mainly includes: char character, int integer, float single precision Floating Point, double precision Floating Point, structure, union, enumeration, and pointer.

    3> variable Declaration

    Defines the type of a variable and a variable. The format is as follows:

    Type variable name [= initial value];

    Int a; int a = 10; int a, B = 5, c;

    The first value assignment of a variable is called initialization. If a variable is not initialized, its value is uncertain.

    # Include <stdio. h> // use int main () {int a = 10, B; float f1 = 1.0f; a = 20; printf ("a = % d \ n", a); // % d indicates the integer variable printf ("f1 = % f \ n", f1 ); // % f float variable printf ("B = % d \ n", B); // The value of B is not sure return 0 ;}


  11. Identifier

    The identifier used to name variables, functions, macros, and other entities. Criterion:

    1> the identifier must consist of letters, numbers, and underscores. The number cannot be the first.

    2> case sensitive

    3> the length is not limited, but the compiler truncates it during compilation.

    4> it cannot conflict with the keywords in the C language.

    A keyword is actually a special word used by C language itself. It has a special meaning and cannot be used as an identifier by programmers. Common: int char float double return if else switch case default for while do break continue goto ......

  12. Standard Input Function and standard output function

    1. Standard Input: printf ()

    Printf () can print 0-n variables (Variable Parameter quantity)

    Printf (Format String, variable or expression 1, 2, 3, 4 ,...)

    The format string can be composed of two parts:Common stringAndConversion format(% D)

    Conversion format:

    %-0 m. n l/h format characters

    % Conversion format start character

    -Left alignment omitted means right alignment (understanding)

    0: Empty fill 0; omitted: Empty do not fill (understanding)

    M. n m domain width (width) n precision number of digits after the decimal point of a floating point number (understanding)

    L/h l integer long lf represents double

    H integer short (less used)

    Format characters:

    I/d decimal integer

    C character

    S string

    F floating point (float, if double needs to add l)

    G floating point remove the following 0)

    P address

    X hexadecimal integer

    O octal integer

    U unsigned integer

    2> scanf ()

    Scanf can input 0-N values from the keyboard and store them in corresponding variables.

    Scanf (Format String, memory address list of variables) can be 0-n Variables

    Int I; & I: the memory address of the variable I

    Scanf ("% d ",&I); // store an integer input by the keyboard

    The format string in scanf is basically the same as that in printf.

    Scanf verifies the input one by one from the front to the back, returns the result when it does not conform to the format, and saves the variables that conform to the preceding format.

    # Include <stdio. h> // input and output test int main () {int I; printf ("enter an integer \ n"); scanf ("% d", & I ); printf ("I = % d \ n", I); return 0 ;}

    3> common types:

    Integer variable: % d

    Balanced variable: % c

    Floating Point double variable: % lf

    String variable: % s

    Pointer variable: % p

    If the type is incorrect, the displayed result may be incorrect.

    If % exists in the format string, % must be used.



This article from the "Snow Wolf" blog, please be sure to keep this source http://wolfzhxp.blog.51cto.com/2409990/1284793

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.