Welcome to C Programming Quiz, Randomly Selected !!

Question 1. 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 2. The function crash(), defined below, triggers a fault in the memory management hardware for many architectures. Which one of the following explains why "got here" may NOT be printed before the crash?
void crash (void) 
{ 
 printf("got here"); 
 *((char *) 0) = 0; 
}

The C standard says that dereferencing a null pointer causes undefined behavior. This may explain why printf() apparently fails.

printf() always buffers output until a newline character appears in the buffer. Since no newline was present in the format string, nothing is printed.

If the standard output stream is buffered, the library buffers may not be flushed before the crash occurs.

printf() expects more than a single argument. Since only one argument is given, the crash may actually occur inside printf(), which explains why the string is not printed. puts() should be used instead.

Question 3. 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 4. Is there any difference between following declarations?
1:  extern int fun();
2:  int fun();

Both are identical

No difference, except extern int fun(); is probably in another file

int fun(); is overrided with extern int fun();

None of the above

Question 5. Which bitwise operator is suitable for checking whether a particular bit is on or off?

&& operator

& operator

|| operator

! operator

Question 6. What are the different types of real data type in C ?

float, double

short int, double, long int

float, double, long double

double, long int, float

Question 7. 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 8. 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 9. What function should be used to free the memory allocated by calloc() ?

dealloc();

demalloc(variable_name, 0)

free()

decalloc(variable_name, 0)

Question 10. What does x mean in this code sample ?
typedef char (*(*arrfptr[3])())[10];
arrfptr x;

x is a pointer

x is an array of three pointer

x is an array of three function pointers

error in declaration of x