L2
data types in C:
int x, // x can takes on value between -2^31 through 2^31-1
//2^32 possibilities.
(x:32 bits,bit: is a piece of information that takes value 0 or 1, 8 bits=1 byte)
integer data
char: 1 byte integer -128~127
short: 2 byte integer -2^15~2^15-1
int: either 2 bytes or 4 bytes,machine dependent
unsigned int:0~2^32-1
unsigned char:0~255
digital image
1:3 bytes:0-255(b,g,r) eg:(255,0,255)
eg:data storage:1024*768*3 bytes=2.25mb
decimal point numbers:
float :4 bytes, 32 bits
8.85e12
(8.85e:7 digits,22 bits; -12::-50-40=log(2)80,6-7 bits)
double- 8 bytes- 64 bits
1234567890123465:16 digits of pr :50 bits
exponent:-308~308: 600 possible values: 9~10 bits
#include<st>
int main()
{
double x,y;
x=-11.0;
y=5.5;
printd("Average of %f =%f\n",
(*note:%f:non-scientific of 10 digits after decimal place
format specifiers:%f:prints float a double in non-sci ,not, v(?) 6 digit after decimal place
%.2f: same as above except 2 digits after decimal place
%10.2f: same as above but v/ white space characters such that entire field width is 10.
eg:
x x^2 2^x
1 1 2
2 4 4
3 9 8
4 16
int main()
{
int x;
x=1;
printf("%d
return 0;
}
%6d: filed width of 6-right justified
%-6d: .... left...
#include<st>//printf
#include<pow>//exp(base,expo )
for-loops:
repeat a block of code until a condition becomes false
for( ; ; )
block of code that will be repeated
eg:
for(i= ; i<=5; i+i+1)
in general are excuted once when for-loop first excution
increment/decrement op:
i=0; i x
x=2; 0 2
x=i++; 1 0
i=0; i x
x=2; 0 2
x=++i 1 1
int x, // x can takes on value between -2^31 through 2^31-1
//2^32 possibilities.
(x:32 bits,bit: is a piece of information that takes value 0 or 1, 8 bits=1 byte)
integer data
char: 1 byte integer -128~127
short: 2 byte integer -2^15~2^15-1
int: either 2 bytes or 4 bytes,machine dependent
unsigned int:0~2^32-1
unsigned char:0~255
digital image
1:3 bytes:0-255(b,g,r) eg:(255,0,255)
eg:data storage:1024*768*3 bytes=2.25mb
decimal point numbers:
float :4 bytes, 32 bits
8.85e12
(8.85e:7 digits,22 bits; -12::-50-40=log(2)80,6-7 bits)
double- 8 bytes- 64 bits
1234567890123465:16 digits of pr :50 bits
exponent:-308~308: 600 possible values: 9~10 bits
#include<st>
int main()
{
double x,y;
x=-11.0;
y=5.5;
printd("Average of %f =%f\n",
(*note:%f:non-scientific of 10 digits after decimal place
format specifiers:%f:prints float a double in non-sci ,not, v(?) 6 digit after decimal place
%.2f: same as above except 2 digits after decimal place
%10.2f: same as above but v/ white space characters such that entire field width is 10.
eg:
x x^2 2^x
1 1 2
2 4 4
3 9 8
4 16
int main()
{
int x;
x=1;
printf("%d
return 0;
}
%6d: filed width of 6-right justified
%-6d: .... left...
#include<st>//printf
#include<pow>//exp(base,expo )
for-loops:
repeat a block of code until a condition becomes false
for( ; ; )
block of code that will be repeated
eg:
for(i= ; i<=5; i+i+1)
in general are excuted once when for-loop first excution
increment/decrement op:
i=0; i x
x=2; 0 2
x=i++; 1 0
i=0; i x
x=2; 0 2
x=++i 1 1
还没人转发这篇日记