---------------------------------- Test Your "C" Skill --------------------------------------
FLOATING POINT ISSUES
1.
void main()
{
float a=0.7;
if(a<0.7)
printf(“C”);
else
printf(“C++”);
}
a. C
b. C++
c. Error
d. None of above.
Output:- A.
2.
void main()
{
float a=0.7;
if(a<0.7f)
printf(“C”);
else
printf(“C++”);
}
a. C
b. C++
c. Error
e. None of above
Output:- B.
3.
void main()
{
printf(“%f”,sqrt(36.0));
}
a. 6.0
b. 6
c. 6.000000
d. Some absurd result
Output:- D
4. Would this program give proper
results <yes/no>?
void main()
{
printf(“%f”,log(36.0));
}
Output:- No. since math.h is not included.
5.Would the following printf()s print
the same values for any value of a <yes/no>?
void main()
{
float a;
scanf(“%f”,&a);
printf(“%f”,a+a+a);
printf(“%f”,3*a);
}
Output:- No.
6. We want to round off x, a float,
to an int value. The correct way to do so would be
a.
y=(int)(x+0.5);
b. y=int(x+0.5);
c. y=(int) x+0.5;
d. y=(int)((int)x+0.5);
Output:- A.
7. Which error are you likely to get
when you run the following program.
void main()
{
struct emp
{
char name[20];
float sal;
};
struct emp e[10];
int x;
for(x=0;x<9;x++)
scanf(“%s %f”, e[x].name,e[x].sal);
}
a. Suspicious pointer conversion.
b. Floating point formats not linked
c. Can not use scanf() for structure
d. Strings can not be nested inside
structure
Output:- B
8. Which are the three different
types of real data types available in C and what are the format specifiers used for them?
Output:-
Float 4 bytes %f
Double 8 bytes %lf
Long double 10 bytes %Lf
9. By default any real number is
treated as
a float
b double
c long double
b depends on the memory model
that you are using
Output:- B.
10. What should you do to treat the
constant 3.14 as a float?
Output:- Use 3.14f
11. What should you do to treat the
constant 3.14 as long double?
Output:- Use 3.14l
12.
void main()
{
printf(“%d %d %d”,sizeof(3.14f),sizeof(3.14),sizeof(3.14l));
}
a. 4 4 4
b. 4 garbage value garbage value
c. 4 8 10
d. error
Output:- C
13.The binary equivalent of 5.375 is
a
101.101110111
b
101.011
c
101011
d
none of above
Output:- B.
14. A float occupies 4 bytes. If the
hexadecimal equivalent of each of these bytes is A, B, C, and D, then when this
float is stored in memory these bytes get stored in the order.
a.
ABCD
b.
DCBA
c.
0xABCD
d.
0xDCBA
Output:- B.
15. If the binary equivalent of 5.375
in normalized form is 0100 0000 1010 1100 0000 0000 0000 0000, what would be
the output of the following program?
void main()
{
float a=5.375;
char *p;
int x;
p=(char*)&a;
for(x=0;x<=3;x++)
printf(“%02x”,(unsigned char)p[x]);
}
a
40 AC 00 00
b
04 CA 00 00
c
00 00 AC 40
d
00 00CA 04
Output: C.
No comments:
Post a Comment