Welcome to C Programming Quiz, Intermediate Level !!

Question 1. In the following code, the P2 is Integer Pointer or Integer?
typedef int *ptr;
ptr p1, p2;

integer

integer pointer

error in declaration

none of the above

Question 2. 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 3. 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 4. We want to round off x, a float, to an int value, The correct way to do is

y = (int)(x + 0.5)

y = int(x + 0.5)

y = (int)x + 0.5

y = (int)((int)x + 0.5)

Question 5.
long factorial (long x) 
{ 
 ???? 
 return x * factorial(x - 1); 
}

With what do you replace the ???? to make the function shown above return the correct answer?

if (x == 0) return 0;

if (x <= 1) return 1;

if (x >= 2) return 2;

if (x == 0) return 1;

Question 6. 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 7. 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 8. 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 9. 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 10. 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.