II-38 Programming Concepts
19.
void main()
{
float f=5/2;
clrscr();
printf(" %f",f);
}
Bug: No bug. However, to get the desired output as 2.5, either 5 or 2 should be float
or explicit type casting is required.
20.
void main()
{
float d=65535.43;
double p=65789.987654;
clrscr();
printf("%d %d",d,p);
getche();
}
Bug: No bug. However, to get the desired output format provided is wrong. %f and %lf
are needed. Answer would be
65535.429688 65789.987654
21.
void main()
{
float d=1234567.43;
double p=987654321.1234567;
clrscr();
printf(" %f %lf",d,p);
printf(" %d %d",size of(d),size of(p));
getche();
}
Bug: Space between size and of should be removed. The answer will be
1234567.375000 987654321.123457
4 8
M02_ITL-ESL4791_02_SE_C02.indd 38 12/22/2012 4:59:43 PM
The C Declarations II-39
Typecasting 
22.
void main()
{
clrscr();
printf(" %d", 7/2);
printf(" %g",7.0/2);
printf(" %g", float7/2);
getche();
}
Bug: float must be enclosed within bracket then answer
will be 3
3.5
3.5
Volatile and constants 
23.
void main()
{
volatile d=15;
const p=25;
clrscr();
printf("%d %d"d+10,p+1);
getche();
}
Bug: Missing , (comma) in the printf().
Answer after correction
25 26
24.
void main()
{
const x=5;
clrscr();
x++;
printf("%d",x);
}
Bug: constant variable can be modified
M02_ITL-ESL4791_02_SE_C02.indd 39 12/22/2012 4:59:43 PM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset