際際滷

際際滷Share a Scribd company logo
ANSI C
Language
Introduction
Lection 6
弌仂亟亠亢舒仆亳亠
 亳仄亠亳亠从亳亠 仂仗亠舒仂
 仗亠舒仂 舒于仆亠仆亳
 仂亞亳亠从亳亠 仂仗亠舒仂
 仂弍亳仂于亠 仂仗亠舒仂
 弌仂舒于仆亠 仂仗亠舒仂
23.05.2019 0:15 Introduction 2
亳仄亠亳亠从亳亠 仂仗亠舒仂
仆仂于仆亠 弍亳仆舒仆亠 仂仗亠舒亳亳, 舒仗仂仍仂亢亠仆仆亠 于 仗仂磲从亠 仄亠仆亠仆亳 仗亳仂亳亠舒:
 *  仄仆仂亢亠仆亳亠;
 /  亟亠仍亠仆亳亠;
 +  仍仂亢亠仆亳亠;
 -  于亳舒仆亳亠;
 %  仂舒仂从 仂 亠仍仂亳仍亠仆仆仂亞仂 亟亠仍亠仆亳.
仆仂于仆亠 仆舒仆亠 仂仗亠舒亳亳:
 ++  亳仆从亠仄亠仆亳仂于舒仆亳亠 (于亠仍亳亠仆亳亠 仆舒 1);
   亟亠从亠仄亠仆亳仂于舒仆亳亠 (仄亠仆亠仆亳亠 仆舒 1);
 -  亳亰仄亠仆亠仆亳亠 亰仆舒从舒.
3
亳仄亠亳亠从亳亠 仂仗亠舒仂
亳仆舒仆亠 舒亳仄亠亳亠从亳亠 仂仗亠舒亳亳 仄仂亞 弍 仂弍亠亟亳仆亠仆  仂仗亠舒亳亠亶
仗亳于舒亳于舒仆亳:
 仂弍亠从 *= 于舒亢亠仆亳亠; // 仂弍亠从 = 仂弍亠从 * 于舒亢亠仆亳亠
 仂弍亠从 /= 于舒亢亠仆亳亠; // 仂弍亠从 = 仂弍亠从 / 于舒亢亠仆亳亠
 仂弍亠从 += 于舒亢亠仆亳亠; // 仂弍亠从 = 仂弍亠从 + 于舒亢亠仆亳亠
 仂弍亠从 -= 于舒亢亠仆亳亠; // 仂弍亠从 = 仂弍亠从  于舒亢亠仆亳亠
 仂弍亠从 %= 于舒亢亠仆亳亠; // 仂弍亠从 = 仂弍亠从 % 于舒亢亠仆亳亠
4
亳仄亠亳亠从亳亠 仂仗亠舒仂
5
int main()
{
unsigned int a,b,c;
a = 100;
b = 200;
c = a + b;
printf("Result: C = %d", c);
return 0;
}
Result: C = 300
亳仄亠亳亠从亳亠 仂仗亠舒仂
6
Result: ???
int main()
{
unsigned int a,b;
a = 55 / 2;
b = 35 % 3;
printf("Result: A = %d, B = %d", a, b);
return 0;
}
亳仄亠亳亠从亳亠 仂仗亠舒仂
7
Result: A = 27, B = 2
int main()
{
unsigned int a,b;
a = 55 / 2;
b = 35 % 3;
printf("Result: A = %d, B = %d", a, b);
return 0;
}
亳仄亠亳亠从亳亠 仂仗亠舒仂
8
Result: ????
int main()
{
unsigned short a;
a = 2;
a--;
a--;
a--;
printf("Result: A = %d", a);
return 0;
}
亳仄亠亳亠从亳亠 仂仗亠舒仂
9
Result: A = 65535
int main()
{
unsigned short a;
a = 2;
a--;
a--;
a--;
printf("Result: A = %d", a);
return 0;
}
仗亠舒仂 舒于仆亠仆亳
仂仍亳仆于仂 仂仗亠舒仂仂于 舒于仆亠仆亳 仗亳仄亠仆亳仄 从 亳仍仂于仄 亰仆舒亠仆亳礆.  仂 弍亳仆舒仆亠 仂仗亠舒仂,
亳仄亠ム亳亠 亟于舒 亳仍仂于 舒亞仄亠仆舒, 仆仂 于仂亰于舒舒ム亳亠 仍仂亞亳亠从仂亠 亰仆舒亠仆亳亠.
 >  仂仗亠舒仂 束弍仂仍亠損.
 >=  仂仗亠舒仂 束弍仂仍亠 亳仍亳 舒于仆仂損.
 <  仂仗亠舒仂 束仄亠仆亠損.
 <=  仂仗亠舒仂 束仄亠仆亠 亳仍亳 舒于仆仂損.
 !=  仂仗亠舒仂 束仆亠 舒于仆仂損.
 ==  仂仗亠舒仂 从于亳于舒仍亠仆仆仂亳 (舒于亠仆于舒).
仂仍亠亟仆亳亠 亟于舒 仂仗亠舒仂舒 仄仂亞 仗亳仄亠仆 仆亠 仂仍从仂 亟仍 亳仍仂于 亰仆舒亠仆亳亶, 仆仂 亳, 仆舒仗亳仄亠, 亟仍
仍仂亞亳亠从亳.
10
仗亠舒仂 舒于仆亠仆亳
11
Result: ????
int main()
{
unsigned short a,b,c;
a = 2; b = 5;
if (a > b)
c = 10;
else
c = 20;
printf("Result: C = %d", c);
return 0;
}
仗亠舒仂 舒于仆亠仆亳
12
Result: C = 20
int main()
{
unsigned short a,b,c;
a = 2; b = 5;
if (a > b)
c = 10;
else
c = 20;
printf("Result: C = %d", c);
return 0;
}
仗亠舒仂 舒于仆亠仆亳
13
Result: ????
int main()
{
unsigned short a,b,c;
a = 50; b = 20;
if (a = b)
c = a - b;
else
c = a + b;
printf("Result: C = %d", c);
return 0;
}
仗亠舒仂 舒于仆亠仆亳
14
Result: C = 0
int main()
{
unsigned short a,b,c;
a = 50; b = 20;
if (a = b)
c = a - b;
else
c = a + b;
printf("Result: C = %d", c);
return 0;
}
仂亞亳亠从亳亠 仂仗亠舒仂
弌亠于亠 仆亠从仂仍从仂 弍亳仆舒仆 仍仂亞亳亠从亳 仂仗亠舒仂仂于 亳 仂亟亳仆 仆舒仆亶.  从舒亠于亠 舒亞仄亠仆仂于 亟仍 于亠 亳
仂仗亠舒仂仂于 于仗舒ム 仍仂亞亳亠从亳亠 仍亳亠舒仍 (从仂仆舒仆), 仍仂亞亳亠从亳亠 仗亠亠仄亠仆仆亠 亳 于舒亢亠仆亳, 亳仄亠ム亳亠
仍仂亞亳亠从仂亠 亰仆舒亠仆亳亠.
 !  束仂亳舒仆亳亠損, 仆舒仆亶 仂仗亠舒仂, 仄亠仆磳 亰仆舒亠仆亳亠 仆舒 仗仂亳于仂仗仂仍仂亢仆仂亠
 &&  仍仂亞亳亠从仂亠 束亳損 (束从仂仆ミ出済亳晛, 束仗亠亠亠亠仆亳亠損), 弍亳仆舒仆舒 仂仗亠舒亳, 于仂亰于舒舒亠 亳亳仆仆仂亠 亰仆舒亠仆亳亠
仂亞亟舒 亳 仂仍从仂 仂亞亟舒, 从仂亞亟舒 仂弍舒 仂仗亠舒仆亟舒 亳亳仆.
 ||  仍仂亞亳亠从仂亠 束亳仍亳損 (束亟亳亰ミ出済亳晛, 束仂弍亠亟亳仆亠仆亳亠損), 弍亳仆舒仆舒 仂仗亠舒亳, 于仂亰于舒舒亠 亳亳仆仆仂亠 亰仆舒亠仆亳亠,
从仂亞亟舒 仂 弍 仂亟亳仆 亳亰 仂仗亠舒仆亟仂于 亳亳仆仆亶.
丕 仍仂亞亳亠从亳 仂仗亠舒仂仂于 仍亠亟ム亳亶 仗亳仂亳亠: 仂亳舒仆亳亠, 从仂仆ミ出済亳, 亟亳亰ミ出済亳.
15
仂亞亳亠从亳亠 仂仗亠舒仂
16
仂亞亳亠从亳亠 仂仗亠舒仂
17
Result: ????
int main()
{
unsigned short a,b,c;
a = 50; b = 20;
if ((a > b) && (b != 20))
c = a - b;
else
c = a + b;
printf("Result: C = %d", c);
return 0;
}
仂亞亳亠从亳亠 仂仗亠舒仂
18
Result: C = 70
int main()
{
unsigned short a,b,c;
a = 50; b = 20;
if ((a > b) && (b != 20))
c = a - b;
else
c = a + b;
printf("Result: C = %d", c);
return 0;
}
仂亞亳亠从亳亠 仂仗亠舒仂
19
Result: ????
int main()
{
unsigned short c, d;
c = 100; d = 0;
c = !(!c);
d = !(!d);
printf("Result: C = %d, D = %d", c, d);
return 0;
}
仂亞亳亠从亳亠 仂仗亠舒仂
20
Result: C = 1, D = 0
int main()
{
unsigned short c, d;
c = 100; d = 0;
c = !(!c);
d = !(!d);
printf("Result: C = %d, D = %d", c, d);
return 0;
}
仂弍亳仂于亠 仂仗亠舒仂
仂弍亳仂于亠 仂仗亠舒亳亳 仄仂亢仆仂 仗亳仄亠仆 仂仍从仂 从 亠仍仂亳仍亠仆仆仄 亳仗舒仄.
亳亟 仗仂弍亳仂于 仂仗亠舒亳亶:
 & ( 亳仍亳 AND ),
 | ( 亳仍亳 OR ),
 ^ ( 亳仍亳 XOR ),
 ~ ( 亳仍亳 NOT ),
 << - 亟于亳亞 于仍亠于仂
 >> - 亟于亳亞 于仗舒于仂
21
仂弍亳仂于亠 仂仗亠舒仂
22
仗亠舒仂 仍仂亞亳亠从仂亞仂 亟于亳亞舒
23
仂弍亳仂于亠 仂仗亠舒仂
24
Result: Z = 3, X = 131
int main()
{
unsigned char z, x;
z = 0x0F; // 0b 0000 1111 (15)
z = z >> 2; // 0b 0000 0011 (3)
x = z | 0x80; // 0b 1000 0011 (131)
printf("Result: Z = %d, X = %d", z, x);
return 0;
}
弌仂舒于仆仂亶 仂仗亠舒仂
25
弌仂舒于仆仂亶 仂仗亠舒仂
26
int main()
{
unsigned short a, b, c, d;
a = 20; b = 30; c = 100; d = 0;
if (a == 3)
c = 20;
else
{
c = 40;
if (d < 10)
{
d *= 2;
}
}
{
unsigned int e;
a = b = c = d = 0;
}
return 0;
}

More Related Content

C language lect_06_introduction

Editor's Notes

  1. https://ru.wikipedia.org/wiki/%D0%9E%D0%BF%D0%B5%D1%80%D0%B0%D1%82%D0%BE%D1%80%D1%8B_%D0%B2_C_%D0%B8_C%2B%2B