Welcome to C Programming Quiz, Intermediate Level !!

Question 1. 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 2. What will be the output of the program?
#include<stdio.h>

int main()
{
    const int x=5;
    const int *ptrx;
    ptrx = &x;
    *ptrx = 10;
    printf("%d\n", x);
    return 0;
}

5

10

error

garbage value

Question 3. struct customer *ptr = malloc( sizeof( struct customer ) );
Given the sample allocation for the pointer "ptr" found above, which one of the following statements is used to reallocate ptr to be an array of 10 elements?

ptr = realloc( ptr, 10 * sizeof( struct customer));

realloc( ptr, 9 * sizeof( struct customer ) );

ptr = malloc( 9 * sizeof( struct customer ) );

ptr = realloc( ptr, 9 * sizeof( struct customer ) );

Question 4. 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 5. 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 6. Assuming a short is two bytes long, what will be printed by the following code sample?
 short testarray[4][3] = { {1}, {2, 3}, {4, 5, 6} }; 
 printf( "%d\n", sizeof( testarray ) );

It will not compile because not enough initializers are given.

6

12

24

Question 7. What will the function rewind() do?

Reposition the file pointer to a character reverse.

Reposition the file pointer stream to end of file.

Reposition the file pointer to begining of that line.

Reposition the file pointer to begining of file.

Question 8. 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 9. 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 10. How many times the while loop will get executed if a short int is 2 byte wide?
#include<stdio.h>
int main()
{
    int j=1;
    while(j <= 255)
    {
        printf("%c %d\n", j, j);
        j++;
    }
    return 0;
}

infinite number of times

255 times

256 times

254 times