Welcome to C Programming Quiz, Intermediate Level !!

Question 1. Can you combine the following two statements into one?
char *p;
p = (char*) malloc(100);

char p = *malloc(100);

char *p = (char) malloc(100);

char *p = (char*)malloc(100);

char *p = (char *)(malloc*)(100);

Question 2. If the binary eauivalent of 5.375 in normalised form is 0100 0000 1010 1100 0000 0000 0000 0000, what will be the output of the program (on intel machine)?
#include<stdio.h>
#include<math.h>
int main()
{
    float a=5.375;
    char *p;
    int i;
    p = (char*)&a;
    for(i=0; i<=3; i++)
        printf("%x\n", (unsigned char)p[i]);
    return 0;
}

40 AC 00 00

04 CA 00 00

00 00 AC 40

00 00 CA 04

Question 3. what will be the value of "counter" after the following code is executed?
x = 3, counter = 0; 
while ((x-1)) 
{ 
   ++counter; 
   x--; 
}

0

1

2

3

Question 4. which one of the following declares "A pointer to an array of three chars"?

char *ptr[3]();

char (*ptr)*[3];

char (*ptr[3])();

char (*ptr)[3];

Question 5. what is the output of the following code sample?
int x = 0; 
for (x=1; x<4; x++); 
printf("x=%d\n", x);

x=0

x=4

x=5

no output, it will loop forever

Question 6. Which of the following is the correct order if calling functions in the below code?
a = f1(23, 14) * f2(12/4) + f3();

f1, f2, f3

f3, f2, f1

Order may vary from compiler to compiler

none of the above

Question 7. char txt [20] = "Hello world!\0";
How many bytes are allocated by the definition above?

11 bytes

12 bytes

13 bytes

20 bytes

Question 8. What does the following declaration mean?
int (*ptr)[10]

ptr is array of pointers to 10 integers

ptr is a pointer to an array of 10 integers

ptr is an array of 10 integers

ptr is an pointer to array

Question 9. what will be the output of the following program?
int a=10,b;
b=a++ + ++a;
printf("%d,%d,%d,%d",b,a++,a,++a);

12,10,11,13

22,10,11,13

12,11,11,11

Undefined Behavior

Question 10. what is the correct way to increment the pointer ptr
void *ptr;
myStruct myArray[10];
ptr = myArray;

ptr = ptr + sizeof(myStruct);

++(int*)ptr;

ptr = ptr + sizeof(myArray);

ptr = ptr + sizeof(ptr);