Welcome to C Programming Quiz, Advanced Level !!

Question 1. 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 2. 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)
{    
    free(nPtr);
}

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 3. what is the output of the following code sample
int main(void) {
                char *p="abc";
                char *q="abc123";
                while(*p=*q)
                {
                                print("%c %c",*p,*q);
                }
}

aabbcc123

abcabc123

infinite loop

segmentation fault

Question 4. what will be the output of the following program
#include<stdio.h>
#include<stdarg.h>
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 5. Consider the function increment_ints(), defined below. Despite its significant inline commentary, it contains an error. Which one of the following correctly assesses it?
/* Increment each integer in the array 'p' of * size 'n'. */ 
void increment_ints (int p [/*n*/], int n) 
{ 
  assert(p != NULL);  /* Ensure that 'p' isn't a null pointer. */ 
  assert(n >= 0);  /* Ensure that 'n' is nonnegative. */ 
  while (n)  /* Loop over 'n' elements of 'p'. */ 
  { 
    *p++  ;          /* Increment *p. */ 
     p++  , n--;      /* Increment p, decrement n. */ 
  } 
}

*p++ causes p to be incremented before the dereference is performed, because both operators have equal precedence and are right associative.

An array is a nonmodifiable lvalue, so p cannot be incremented directly. A navigation pointer should be used in conjunction with p.

*p++ causes p to be incremented before the dereference is performed, because the autoincrement operator has higher precedence than the indirection operator.

The condition of a while loop must be a Boolean expression. The condition should be n != 0.

Question 6. what will be the output of the following program
#include<stdio.h>
int fun(int **ptr);

int main()
{
    int i=10;
    const int *ptr = &i;
    fun(&ptr);
    return 0;
}
int fun(int **ptr)
{
    int j = 223;
    int *temp = &j;
    printf("Before changing ptr = %5x\n", *ptr);
    const *ptr = temp;
    printf("After changing ptr = %5x\n", *ptr);
    return 0;
}

address of i
     address of j

10
     223

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

garbage value

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

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

9

15

compilation error

undefined behavior

Question 8. 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

i=9

i=10

wont print anything

Question 9. 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;

-3

4

4 + sizeof( int )

0

Question 10. what is the value of x when the following sample code is executed
int x = 3; 
if( x == 2 );
  x = 0; 
if( x == 3 )
 x++; 
else x += 2;

4

2

4

0