Welcome to C Programming Quiz, Advanced Level !!

Question 1. what is the output of the following code sample
int main(void) {
                char *p="abc";
                char *q="abc123";
                                print("%c %c",*p,*q);



infinite loop

segmentation fault

Question 2. what will be the output of the following program
void display(int num, ....);

int main()
    display(4, 'A', 'B', 'C', 'D');
    return 0;
void display(int num, ...)
    char c, c1; int j;
    va_list ptr, ptr1;
    va_start(ptr, num);
    va_start(ptr1, num);
    for(j=1; j<=num; j++)
        c = va_arg(ptr, int);
        printf("%c", c);
        c1 = va_arg(ptr1, int);
        printf("%d\n", c1);

A, A
     B, B
     C, C
     D, D

A, a
     B, b
     C, c
     D, d

A, 65
     B, 66
     C, 67
     D, 68

A, 0
     B, 0
     C, 0
     C, 0

Question 3. 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 4. what is the output of the following code sample?
#include <stdio.h>
int i; 
void increment( int i ) 
   i++  ; 

int main() 
   for( i = 0; i < 10; increment( i ) ) 
   printf("i=%d\n", i); 
   return 0; 

it wont compile at all



wont print anything

Question 5. 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 6. what is the output of the following program
#include "stdio.h"
int f(int *a, int n)
    if (n <= 0) return 0;
    else if (*a % 2 == 0) return *a +  f(a + 1, n-1);
    else return *a - f(a + 1, n-1);

int main()
    int a[] = {12, 7, 13, 4, 11, 6};
    printf("%d", f(a, 6));
    return 0;





Question 7. 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 8. The following program releases memory from a link list..which of the following is true?
struct node *nPtr, *sPtr;    /* pointers for a linked list. */ 
for (nPtr=sPtr; nPtr; nPtr=nPtr->next)

It will work correctly since the for loop covers the entire list.

It may fail since each node "nPtr" is freed before its next address can be accessed.

In the for loop, the assignment "nPtr=nPtr->next" should be changed to "nPtr=nPtr.next".

The loop will never end.

Question 9. What will be the output of the program?
int main(void) {

                int i=3, j;
                i++ + i++ + i++;
                printf("%d", j);
                return 0;



compilation error

undefined behavior

Question 10. What does y in the sample code evaluated to?
int x[] = { 1, 4, 8, 5, 1, 4 }; 
int *ptr, y; 
ptr  = x +  4; 
y = ptr - x;



4 + sizeof( int )