C Language Learning first week (one)

Source: Internet
Author: User
Tags arithmetic arithmetic operators variable scope

First day

C Language Introduction

C language is a functional language, consisting of multiple functions, each with its own function

A program can have only one main function, the main function is called by the system, if the program does not have a main function, the program will not be called, the function will only be executed at the time of invocation, so the main function of the writing must be standardized

Program Operating principle

Code writers write source code to generate. c files that are compiled by the compiler to generate a. o target file that can be identified by the computer by linking all the target files and library functions together to generate an executable. out file, and finally the program executes.

Next day

Keywords: data type 20, Process control type 12 Total 32

Identifier

Naming rules for identifiers

1, can only be composed of numbers, letters, underscores, dollar signs

2. Cannot start with a number

3. Cannot duplicate the keyword

4. To distinguish case

Naming conventions

1. Start with a meaningful name

2, if the identifier is composed of more than one word, except the first word, the first letter of the upper case of the Hump name method

Comments

Comments are intended for other program personnel to understand your code

Comment classification

Multiline comment/**/: Multiple lines of comments cannot be nested multiple lines

Single-line comment//: single-line comment Comment range is//after the line, break exit comment range

Data type

Integer: Short integer takes two bytes, integer int occupies 4 bytes, long integer is 8 bytes

Binary number starts with 0b, octal number starts with 0, decimal number computer default integer is decimal, hexadecimal starts with 0x

Real: Single-precision occupies four bytes, double-precision occupies eight bytes

Single-precision float with f-end, double-precision Doubles computer Default-type double-precision

Character type:

Char: Takes a byte in the "enclosed part"

Constant

Is the data that cannot be changed

Constant: integer constant, real constant, character type constant

Variable

Represents a memory space, the value is the basic unit that can change

Basic format: Variable type variable name;

Divide by scope

Scope: The range of variables that can be used

Local variables: variables defined within a function or code block

Local variable scope: The variable definition starts to the "}" cutoff of the function or code block

Global variables: Variables defined outside of a function

Global variable Scope: variable definition starts at the end of the file

printf function

You need to include the "stdio.h" header file, which is the output library function of the C language.

Function: Output the desired result according to certain rules

Format: printf ("Format control string", output item list);

The format control string contains

%d output integral type

%0MD is the domain width is not sufficient when the complement 0 for the data self-increment output, example: int num = 1;num++;p rintf ("%02d", num), the output is 01, 、...、 10, 11 ...

%f Output Real Type

%f accuracy problem

Float type Default output 6 digits after decimal point, valid number is 7 bits

Double type default output 6 digits after decimal point, valid number 15 bits

%M.NF problems

m represents the width of the field is the output of data total number of bits

n represents the number of digits after the output

For example float num = 3.1415926f; printf ("%5.2f", num); the output is: space 3.14, because n is 2, so to output a decimal point two M is 5 that is, the field width is 5, not enough field width to fill space because +5 is left-to-right empty, so the output is: space 3.14

%c Output Character type

Also called a placeholder, corresponds to the number of data types that follow the list of output items.

Escape character

"\ n": output a carriage return; "\ T": Outputs a tab; "\ \" outputs a \; "percent": outputs a%;

scanf function

Also known as a blocking function, the function is to wait for the user to enter after the functions are run, and if you do not enter the program will wait

Format:

scanf ("Format control string", output address list);

& Take address symbol

Use note

1. Cannot specify%M.N format, but can specify%m format

2, if the data type is integer type, enter multiple tab, space, enter will be ignored by the system

3, the character type and the integral type mixed input to avoid the input space and so on may not get the desired result by the character type absorption, if has the character type mix to be possible to enter as is

4, illegal input will not get the desired results

Third Day

Operator

is a symbol that tells the compiler to perform a specific arithmetic or logical operation

Classification

by function: arithmetic operator, logical operator, relational operator, bitwise operator

by operand: monocular operator, binocular operator, trinocular operator

Arithmetic operators: + 、-、 *,/,% (redundancy)

Binocular operator, left associative, *,/,% priority level 3, +,-4 level

% Redundancy operator Note:

1, n==0 no meaning

2, m==0 result is 0

3, M>n normal to take surplus

4, m<n result is M

5, the results of positive and negative depending on the first operand

6. The operand that participates in the operation must be an integral type

Compound Assignment operators: + =,-=, *=,/=,%=

Binocular operator, right-associative, priority level 14

function equivalent to A + = b--->a = a + b

Relational operators:>, <, >=, <=, = =,! =

Binocular operator, left-associative, >, <, >=, <= priority Level 6, = =,! = Priority Level 7

The result of the operation is only true (1) False (0) two possible

Logical operator:&& (with), | | (or),! (non)

The result of the operation is only true (1) False (0) two possible

!: Monocular operator Precedence Level 2, right-associative

Formula: True change false, false change true

&&: Binocular operator, left-associative, priority level 11

Format: expression 1&& expression 2, formula: a false is false

or short-circuit: If the expression 1 is false then the result is false so the subsequent expression is no longer evaluated

|| : Binocular operator, left associative, priority level 12

Format: Expression 1| | Expression 2. Formula: A true truth

and short-circuit: If the expression 1 is true then the result is false so the subsequent expression is no longer evaluated

Assignment operators:

=: Binocular operator, right-associative, priority level 14

sizeof operator:

sizeof (variable, constant, data type);

The storage size of the operand given in bytes

Monocular operator, right-associative, priority level 2

Note: The constant character type is stored with the ASICC code value of the character, so the sizeof character constant Gets the result of 4 bytes

Three-mesh operator (conditional expression):

Expression 1-expression 2: expression 3;

Calculation principle: First evaluates the expression 1 if the value of the expression 2 is the value of the entire expression, if expression 1 is false the value of the expression 3 is the value of the entire expression

Trinocular operator, right-associative, priority level 13

Self-increment decrement operator: + + 、--;

Format: variable + +, variable--、 + + variable 、--variable

Calculation principle: int a = 0;a++; equivalent to a = a + 1;

Prefix expression: the operator is preceded by the prefix expression, the variable is self-increment, and then use the value of the variable as the value of the expression, first change the

Postfix expression: The operator is followed by the prefix expression, the value of the variable is used as the value of the expression, and then the variable self-decrement operation, first use the later change

Note: The self-increment decrement operator can only function on a variable

Comma operator:,

Format: expression 1, expression 2, expression 3;

Calculation principle: The value of the expression is calculated separately, the value of the last expression 3 as the value of the entire expression

Note: Not all commas are comma-expressions, such as int, A, B;

C Language Learning first week (i)

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.