123 // signed int
11234 L 11234 l // signed long int
123 U 123u // unsigned int
2.78F 2.78 f // float
2.78 // double
2.78 L 2.78 l // long double
-----------------------------------------------------------------------------------------
:
const int K = 7;
#define K 7
, , , .
-----------------------------------------------------------------------------------------
. . () .
2.
l-value = | r-value | |
char, signed char | unsigned char | r-value > 127, |
unsigned char | char, signed char | r-value < 0, |
char | short, short int | 8 |
char | int, long int | 24 |
short, short int | int, long int | 16 |
short, short int, int, long int | float, double | , , - |
float | double | , |
// 25.
:
#define PRINT(x) printf("%d\n", x)
int x = 2, y, z;
x *= 3+2; PRINT(x); | x= x*5=10 |
x *= y = z = 4; PRINT(x); | z=4 à y=4 à x=x*y=10*4=40 |
x = y == z; PRINT(x); | 4==4 à x=true, 1 |
x == (y = z); PRINT(x); | = 0, x=1 |
// 26.
#define PRINT printf("%d\t %d\n", x, y)
double d=3.2, x;
int i=2, y;
x = (y = d/i)* 2; PRINT(x, y); | y=1à x= 2 |
y = (x = d/i)* 2; PRINT(x, y); | x=1.6 ày=3 |
y = d * (x = 2.5/d); PRINT(y); | y=2 |
x = d*(y = ((int)2.9+1.1)/d); PRINT(x, y); | y=0 à x=0 |
// 27.
#include <stdio.h>
#include <conio.h>
int main()
{
// warning
double d = 3.2, x;
int k, i = 2;
x = (k = d/i)* 2;
printf("% f \n", x); // !!! warning C4244
k = (x = d/i)* 2;
printf("% d \n", k); // !!! warning C4244
k = d * (x = 2.5/d);
printf("% d \n", k); // !!! warning C4244
x = d *(k =((int)2.9 + 1.1)/d);
printf("% f \n ", x); // !!! warning C4244
_getch();
|
|
return 0;
}
!!! warning C4244: '=': conversion from 'double' to 'int', possible loss of data
, warning:
2.000000
3
2
0.000000
-----------------------------------------------------------------------------------------
// 28.
#include <stdio.h> //
#include <conio.h>
int main()
{
int x = -3+4*5-6;
printf("%d \n ", x); //11
x = -3+4%5-6;
printf("%d \n ", x); //-5
x = -3*4%-6/5;
printf("%d \n ", x); //0
x = (7+6)%5/2;
printf("%d \n ", x); //1
_getch();
return 0;
}
-----------------------------------------------------------------------------------------
// 29.
#include <stdio.h> //
#include <conio.h>
int main()
{
Int x, y, z;
x = y = 1; z = x++ - 1;
printf("%d\n", x); printf("%d\n", z); //2 0
z += -x++ + ++y;
printf("%d\n", z); printf("%d\n", x); printf("%d\n", y); //0 3 2
z = x/ ++x;
printf("%d\n", z); printf("%d \n ", x); //1 4
_getch();
return 0;
}
-----------------------------------------------------------------------------------------
// 30.
#include <stdio.h> //
#include <conio.h>
int main()
{
int x = 2, y, z;
x *= 3+2;
printf("%d\n", x); //10
x *= y = z = 4;
printf("%d\n", x); //40
x = y == z;
printf("%d\n", x); //1
x ==(y = z);
printf("%d \n ", x); //1
_getch();
return 0;
}
-----------------------------------------------------------------------------------------