C Language Foundation---constants, operators, functions

Source: Internet
Author: User
Tags alphabetic character bitwise bitwise operators logical operators

C Language Foundation---constants, operators, functions

One, variable

1. Name rules for variable names

1) The first character must be a letter or an underscore, followed by a letter, a number, or an underscore. The following are lawful:

Sum, _total, li_ling

Illegal: zhang-sum, 136, student ' s

2) uppercase and lowercase letters represent different characters

3) The length is not infinite

4) try to be concise and easy to remember, see the name of the idea

5) Different variables cannot take the same variable name in the same function

2. Variables must be "defined first, then used"

3, at the time of compiling, must pay attention to the validity of variable operation. For example, integer variables can be redundant, if A and B are defined as Integer variables, you can perform a%b operations to find the whole remainder of a by B, and if it is a real variable, it is not allowed to do the redundancy operation

4. Integer variables:

Basic integer: int

Length int: Long int.

Short integer: Shorter int

int is signed by default, unsigned at the front plus unsigned

5, the Real type variable

Single precision: float

Double precision: Double

Long double-precision: Long Doubles

The output is no longer "%d", it becomes "%f", "%1f,%2f" is reserved one, or two decimal places

6, Character type variable

Character type name: Char

Characters are enclosed in a single apostrophe, and a character variable is output with an alphabetic character:%c

7. Escape character

/n

Line break

/t

To jump the next output data to the next output area

/b

Backspace

/R

Enter

/F

Page change

/0

Empty operation

/ddd

Characters represented by 1-3-bit octal

/xhh

Characters represented by 1-2-bit hexadecimal

Convert lowercase letters to uppercase

Program:/* Lowercase converted to uppercase letters */

#include "stdio.h"

void Main ()

{

Char c1= ' A ', c2= ' B ';

c1=c1-32;

c2=c2-32;

printf ("%c,%c\n", C1,C2);

}

Result is a, b

The lowercase letter of the ASCLL code currency is large 32, so subtract 32

8. String constants

A string constant is a sequence of characters enclosed in double apostrophes: ""

C= "KADFJ";

This is a bad syntax because a string constant cannot be assigned to a character variable and must be stored in a character array

Second, operator

1 , Arithmetic

+

Addition operation

-

Subtraction operations

*

Multiplication operations

/

Division operation

%

To find the remainder operation

i++,i--

Let I plus minus before using I

++i,--I

I plus minus after I use I

+

string addition

Note: The sequence of operations is the same as the number operation, from left to right in the same level

When a modulo operation is performed, if there are negative numbers, the result of the operation depends on whether there are negative numbers on the left

String data and any data using + are connected and eventually become strings.

Self-increment, the self-subtraction operation applies only to variables

2. Relational operators

>

Greater than

<

Less than

==

Equivalent to

different from =

>=

Greater than or equal

<=

Less than or equal

!=

Not equal to

3. Logical operators

Non -

&&

And

||

Or

4 Assignment Operator: =

and "= =" must be differentiated, "=" is only the assignment, and "= =" is about equal to

Priority level

Operator

Meaning

Number of operand objects required

Combination method

1

( )

[ ]

·

Parentheses

Subscript Operation Index

Pointer to struct member operator

struct Member operators

From left to right

 

 

 

 

   !"

   ~

   ++

   --

   -

  (type)

   *

   &

  sizeof

Logical non-operator

Bitwise negation operator

Self-increment operator

Decrement operator

Minus sign operator

Type conversion operator

Pointer operator

Address and operator

Length operator

 

 

 

         1

     (monocular operator)

",

 

 

 

From right to left

3

*

/

%

Multiplication operator

Division operator

Remainder operator

2

(Binocular operator)

From left to right

4

+

-

Addition operator

Subtraction operator

2

(Binocular operator)

From left to right

5

<<

>>

Left shift operator

Right shift operator

2

(Binocular operator)

From left to right

6

<<=︺>>=

Relational operators

2

(Binocular operator)

From left to right

7

= =

! =

equals operator

Not equal to operator

2

(Binocular operator)

From left to right

8

&

Bitwise-AND operator

2

(Binocular operator)

From left to right

9

^

Bitwise XOR OR operator

2

(Binocular operator)

From left to right

10

Bitwise OR operator

2

(Binocular operator)

From left to right

11

&&

Logic and operators

2

(Binocular operator)

From left to right

12

logical operators

2

(Binocular operator)

From left to right

13

?:

Conditional operators

2

(Binocular operator)

From left to right

14

=+=-=*=

/=%=>>=<<=

&=^=︱=

Assignment operators

2

From right to left

15

Comma operator (sequential job search operator)

From left to right

Description

(1) Operators of the same precedence have the same precedence, and the order of operations is determined by the binding direction. For example, * and/have the same priority level, its binding direction is from left to right, therefore, the 3*5/4 order of operations is first multiply after the divide. One and + + are the same priority, and the combination direction is from right to left, so-i++ is equivalent to one (i++).

(2) Different operators require different operands, such as 10 (plus) and-(minus) as binocular operators, requiring an operand (such as 3+5, 8-3, and so on) on either side of the operator. The + + and-(minus) operators are unary operators that can only appear on one side of the operator (such as-A, i++ 、--I, (float) I, sizeof (int), *p, and so on). The conditional operator is the only three-mesh operator in C, such as X?A:B.

(3) The precedence of various operators can be summed up from the above table:

Elementary operator () []→

Monocular operator

Calculating operator (first multiplication, then plus minus)

Relational operators

logical operators (not included!)

Conditional operators

Assignment operators

Comma operator

The priority levels above are decremented from top to bottom. The primary operator has the highest precedence and the comma operator has the lowest precedence. Bitwise operators are more decentralized in their precedence. For easy memory, you can add an arc number when using the bitwise operator.

C Language Foundation---constants, operators, functions

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.