C operators summary

Detailed Operator
operator and expressions
Directory
1: arithmetic operators
2: shift operators
3: bitwise operator
4: assignment operators
5: unary operator
6: relational operators
7: logical operators
8: Operating Conditions Fu
9: comma expression
10: subscripts references, function calls and data structures

A; Arithmetic Operators

      • /%
        Arithmetic modulo
        specific example:
        . 1: #include <stdio.h>
        int main ()
        {
        int = A. 1;
        int. 1 B = ++;
        int = C ++. 1;
        the printf ( "% D,% D, D% \ n-", A, B, C);
        } //. 1, 1,2
        // summary: first front jerk ++, ++ in Houhoujiajia
        2: #inciude <stdio.h >
        int main ()
        {
        int a = 10;
        a float B = 5.0;
        int C = a / B;
        the printf ( "% D \ n-", C);
        } // C = 2.0 / If there is an integer and a float like points / floating point result is
        two; shift operators

<< right left (binary shift)
corresponding to two divided by
1, logical shift left filled with zeros, discarding the right
2, arithmetic shift left filled with the original value of the sign bit, discarding the right
<< multiplied by two is equivalent to
1, after the left leading zero;
III; bitwise operators
& bitwise aND | bitwise oR ^ bitwise exclusive oR (their operands must be an integer)
& bitwise
corresponding to multiplication (binary)
| bitwise oR
has a 1, no 1 0
^ bitwise exclusive or
different 1, 0 is the same as
the special example:
1: #include <stdio.h>
int main ()
{
int = 20 is A;
int B = 10;
A a ^ B =;
B = a ^ B;
a = a ^ B;
the printf ( "% D, D% \ n-", a, B); \ 10; 20 is exchanged ab &
}
2: #include <stdio.h >
int main ()
{
int A = -1;
int I = 0;
int COUNT = 0;
the while (A)
{
COUNT ++;
= A & A (A -. 1);
}
the printf ( "in a binary number D% =", COUNT);
} // output a binary number

IV: assignment operators
=, + =, - =, / =,% =, = >>, << =, & =, =, ^ =!
Example:
#include <stdio.h>
int main ()
{
int = 10 A;
A + = 2; A = A + 2 //
the printf ( "% D", A);
} // output 12
V: unary operator
, -, +, &, sizeof , ~,! -, +, *, (type)
logical negation, negative, positive values, fetch address, the type of operand length, a number of bitwise, pre- and post -, ++ dereference operator, casts,
special example:
. 1: #include <stdio.h>
int main ()
{
int A = 10;
int * = P & A;
int ** = PP & P;
int *** PPP = & PP;
*** = 99 PPP;
the printf ( "% D \ n-", A);
System ( "PAUSE");
return 0;
} // output = 99 A;
2: #include <stdio.h>
int main()
{
int a = 10;
P = NULL * int;
P = & A;
* P = 10; // pointer field preventing
return 0;
}
. 3: #include <stdio.h>
int main ()
{
int -1 = A;
A = A ~;
the printf ( "% D \ n-", A);
System ( "PAUSE");
return 0;
} // 0
. 4: #include <stdio.h>
// () casts
int main ()
{
Double D = 10.9 ;
int A = (int) d;
System ( "PAUSE");
return 0;
} // d-cast by a double int
. 5: #include <stdio.h>
// array and the sizeof
void test1 (int arr [ ])
{
the printf ( "% D \ n-", the sizeof (ARR)); //. 4
}
void test2 (CH char [])
{
the printf ( "% D \ n-", the sizeof (CH)); //. 4
}
int main()
{
int arr[10] = { 0 };
char ch[10] = { 0 };
printf("%d\n", sizeof(arr));//40
printf("%d\n", sizeof(ch));//10

	system("pause");
	return 0;
}

Six: relational operators

,> =, <, <=,! =, ==
is greater than, greater equal, less than, less than or equal, not equal, equal
CAUTION! == determined error-prone

Seven: logical operators
&&, ||
logical AND, logical OR (statements are shorted)

Eight: conditional operator:
? A b: c
// meaning if a true implementation or execution b c;

Nine: comma expression:
A, B, C, ...
special example:
. 1: #include <stdio.h>
int main ()
{
int = A. 1;
int B = 2;
int = C (A> B, A = 10 + B, A, A + B =. 1);
the printf ( "% D \ n-", C); // output = 13 is C
return 0;
}
2: // can be
A = get_val ()
count_val (A) ;
the while (A> 0)
{
A = get_val ();
count_val (A);
}
// into
the while (A = get_val (), count_val (A), A> 0)
{
}
// output comma expression as the last expression

X: a reference index, function calls and data structures
1; the table reference operator
operand: an array index value of a name +
int arr [10];
arr [. 9] = 10;
[] of the two operands is arr and 9;
2; function call operators,
3; accessing a structure member
special example
#include <stdio.h>
struct STU
{
char name [10];
int Age;
char Sex [. 5];
Double Score;
};
void set_age1 (struct Stu STU)
{
stu.age 18 is =;
}
void set_age2 (struct * PStu Stu)
{
pStu-> Age = 18 is; // access structure members
}
int main ()
{
struct Stu STU;
struct & STU Stu * = PStu ; // structure member access

	   stu.age = 20;//结构成员访问
   	 set_age1(stu);

   	pStu->age = 20;//结构成员访问
	set_age2(pStu);
	 return 0;
	 }

Guess you like

Origin blog.csdn.net/belongHWL/article/details/90614005
Recommended