Welcome to C Programming Quiz, Randomly Selected !!

Question 1. what will be the output of the following program
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




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. 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 4. what is the output of the following program?
char* myFunc (char *ptr)
 ptr  += 3;
 return (ptr);
int main()
 char *x, *y;
 x = "HELLO";
 y = myFunc (x);
 printf ("y = %s \n", y);
 return 0;


y = ELLO

y = LLO

y = LO

Question 5. What is the purpose of "rb" in fopen() function used below in the code?
FILE *fp;
fp = fopen("source.txt", "rb");

open "source.txt" in binary mode for reading

open "source.txt" in binary mode for reading and writing

Create a new file "source.txt" for reading and writing

none of the above

Question 6. What function should be used to free the memory allocated by calloc() ?


demalloc(variable_name, 0)


decalloc(variable_name, 0)

Question 7. How many elements does the array dwarves (declared below) contain? Assume the C compiler employed strictly complies with the requirements of Standard C.
char * dwarves [] = { 
  "Dopey" "Doc", 
  "Grumpy" "Sneezy", 

Compilation Error




Question 8. How many times the program will print "TechInfoGurus" ?

int main()
    return 0;

infinite number of times

ERROR : main() cant be called recursively

65535 times

Till stack doesn't overflow

Question 9. Explain the following C Declaration:
typedef int *(*(*fp[])())()

fp is pointer to function returning array of pointer to int

fp is function returning pointer to array of pointer to function returning pointer to int

fp is array of pointer to function returning pointer to function returning pointer to int

fp is array of pointer to function returning pointer to pointer to int

Question 10. What will be the output of the program?

union employee
    char name[15];
    int age;
    float salary;
const union employee e1;

int main()
    strcpy(e1.name, "K");
    printf("%s %d %f", e1.name, e1.age, e1.salary);
    return 0;

Error: RValue required

Error: cannot convert from 'const int *' to 'int *const'

Error: LValue required in strcpy

no error