You are on page 1of 4

Embedded C Programming QUIZ

Q1. One or more of the following is not a valid C built-in type. Please mark the
wrong one(s) with an X.

int
double
unsigned short
float
real
long long

Q2. One or more of the following declarations is wrong. Please mark the wrong
one(s) with X.

enum bool {true, false} boolean;


union {float f; struct {float f; int i;} s;} U;
struct {float f; union {float f; int i;} u;} S;
typedef struct {double x; double y;} point;
typedef u_int unsigned long int;
typedef signed char s8;

Q3. One or more of the following will NOT print HELLO. Please mark these with
X.

if (7&&9) printf (HELLO);


if (0&&1&&2) printf (HELLO);
if (7-1&&9-1) printf (HELLO);
if (1||2||3||4) printf (HELLO);

Q4. One or more of the following C programs will produce a compilation error.
Please mark these with X.

main (){1,2,3;}
main (){{{}}}
main (){;;;}
main (){1+2+3}
main (){1;2;3;}

Q5. What is the result of the following bitwise expressions?

1 & 2 & 3 & 4


1 & 2 & 4 & 8
1 | 2 | 3 | 4
1 | 2 | 4 | 8
1 ^ 2 ^ 3 ^ 4
1 ^ 2 ^ 4 ^ 8
5 & 7 | 2
2 ^ 4 ^ 8

Q6. Assuming that x is declared as an int, the following lines alter bit 3 of x. One
line turns bit-3 on, one turns bit-3 off and one toggles the value of bit-3. Which
line does which?

x = x | (1 << 2)
x = x & ~(1 << 2)
x = x ^ (1 << 2)

Q7. Which one of the lines of code below copies 0xAE to the contents of address
0x00010000?

*((unsigned char *)0x00010000) = 0xAE;


((unsigned char )0x00010000) = 0xAE;
*((unsigned char )0x00010000) = 0xAE;
((unsigned char *)0x00010000) = 0xAE;

Q8. The following C program should produce a table of Fahrenheit to centigrade


conversions. However, it has a problem which causes all the conversions to be
0.0. Suggest a fix?

main ()
{
double f,c;

for (f = 0; f < 160; f = f + 40)


{
c = (f-32)*(5/9);
printf ("%lfF = %lfC\n", f, c);
}
}

Output

0.000000F = -0.000000C
40.000000F = 0.000000C
80.000000F = 0.000000C
120.000000F = 0.000000C
Q9. One of the following C statements calls a function at address 0x3000. Tick
the correct one.

((void ()(void))0x3000)(*);
((void (*)(void))0x3000)();
((void ()(void))0x3000)();
((void (*)(void))0x3000)(*);

Q10. What would you expect the following program to print in a little endian
system? Assume to variable x is located at memory address 0x10008000.

#include <stdio.h>

main ()
{
unsigned long int x = 0x12345678;
unsigned char *p = (unsigned char *)&x;
int i;

for (i = 0; i < 4; i++)


{
printf ("%p %02x\n", p + i, p[ i ]);
}
}
Q12. Write a 'C' program which sorts 10 successive signed bytes starting at
address 0x2000A000.

You might also like