Welcome to C Programming Quiz, Advanced Level !!

Question 1. What number will z in the following code sample
int z,x=5,y=-10,a=4,b=2;
z = x++ - --y * b / a;





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. 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 4. what is the value of x when the following sample code is executed
int x = 3; 
if( x == 2 );
  x = 0; 
if( x == 3 )
else x += 2;





Question 5. 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 6. 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 7. 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 8. 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 )


Question 9. 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 10. What will the SWAP macro in the following program be expanded to on preprocessing? will the code compile?
#define SWAP(a, b, c)(c t; t=a, a=b, b=t)
int main()
    int x=10, y=20;
    SWAP(x, y, int);
    printf("%d %d\n", x, y);
    return 0;

it compiles

compiles with a warning

not compile

compiles and prints nothing