Welcome to C Programming Quiz, Intermediate Level !!

Question 1. What would be the equivalent pointer expression for referring the array element a[i][j][k][l]

((((a+i)+j)+k)+l)

*(*(*(*(a+i)+j)+k)+l)

(((a+i)+j)+k+l)

((a+i)+j+k+l)

Question 2. Which one of the following statements allocates enough space to hold an array of 10 integers that are initialized to 0?

int *ptr = (int *) malloc(10, sizeof(int));

int *ptr = (int *) calloc(10, sizeof(int));

int *ptr = (int *) malloc(10*sizeof(int));

int *ptr = (int *) calloc(10*sizeof(int));

Question 3. int testarray[3][2][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
What value does testarray[2][1][0] in the sample code above contain?

3

11

7

9

Question 4. 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 5. Which of the following function is correct that finds the length of a string?

int xstrlen(char *s) { int length=0; while(*s!='\0') { length++; s++; } return (length); }

int xstrlen(char s) { int length=0; while(*s!='\0') length++; s++; return (length); }

int xstrlen(char *s) { int length=0; while(*s!='\0') length++; return (length); }

int xstrlen(char *s) { int length=0; while(*s!='\0') s++; return (length); }

Question 6. 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 7. Which one of the following declares - "A pointer to a function which receives an int pointer and returns float pointer"

float *(ptr)*int;

float *(*ptr)(int)

float *(*ptr)(int*)

float (*ptr)(int)

Question 8. 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 9. 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 10. char txt [20] = "Hello world!\0";
How many bytes are allocated by the definition above?

11 bytes

12 bytes

13 bytes

20 bytes