Welcome to C Programming Quiz, Intermediate Level !!

Question 1. What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array?

The element will be set to 0.

The compiler would report an error.

The program may crash if some important data gets overwritten.

The array size would appropriately grow.

Question 2. 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 3. what will be the output of the following program
#include<stdio.h>
#include<stdarg.h>
void fun(char *msg, ...);

int main()
{
    fun("TechInfoGurus", 1, 4, 7, 11, 0);
    return 0;
}
void fun(char *msg, ...)
{
    va_list ptr;
    int num;
    va_start(ptr, msg);
    num = va_arg(ptr, int);
    num = va_arg(ptr, int);
    printf("%d", num);
}

TechInfoGurus 1 7 11 0

1

4

7

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 program?
int y[4] = {6, 7, 8, 9}; 
int *ptr = y  + 2; 
printf("%d\n", ptr[ 1 ] );

Segmentation Fault

7

8

9

Question 6. 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 7. what will be output of the following code sample
int x = 0; 
for ( ; ; ) 
{ 
 if (x++   == 4)
  break; 
 continue; 
} 
printf("x=%d\n", x);

x=0

x=1

x=5

x=4

Question 8. What is the purpose of fflush() function.

flushes all streams and specified streams.

flushes only specified stream.

flushes input/output buffer.

flushes file buffer.

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

11 bytes

12 bytes

13 bytes

20 bytes