P. 1
c Programming

c Programming

|Views: 588|Likes:
Published by ezgibulut

More info:

Published by: ezgibulut on May 05, 2011
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less





Variables of the int data type represent whole
numbers. If you try to assign a fraction to an int
variable, the decimal part is ignored and the value
assigned is rounded down (or TRUNCATED) from the
actual value.
Also, assigning a character constant to an int
variable assigns the ASCII value.

int main() {
int a,b,c,d,e;
a = 10;
b = 4.3;
c = 4.8;
d = 'A';
e = 4.3 + 4.8;

printf("a = %d\n", a);
printf("b = %d\n", b);
printf("c = %d\n", c);
printf("d = %d\n", d);
printf("e = %d\n", e);
printf("b+c = %d\n", b+c);

return 0;


The output of the example is:

a = 10
b = 4
c = 4
d = 65
e = 9
b+c = 8

Obviously, 10 gets assigned to a without any
4.3 gets rounded down to 4 when assigned to b.

4.8 gets rounded down to 4 when assigned to c - not
up to 5 as one may have expected.
Now, d gets assigned 65 - the ASCII code for the
character 'A'.
9 gets assigned to e because 4.3+4.8 equals 9.1,
which gets rounded down.
The first 5 printf statements prints out the integer
values of a through to e.
The last printf statement prints out the sum of b
and c, that is, 4 and 4 and not 4.3 and 4.8.

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->