Welcome to C Programming Quiz, Advanced Level !!

Question 1. 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 2. 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 3. what is the output of the following sample code?
void myFunc (int x) 
{ 
   if (x > 0)
   myFunc(--x); 
   printf("%d, ", x); 
} 
int main() 
{ 
   myFunc(5); 
   return 0; 
}

1, 2, 3, 4, 5, 5,

4, 3, 2, 1, 0, 0,

0, 0, 1, 2, 3, 4,

0, 1, 2, 3, 4, 5,

Question 4. 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 5. What will the SWAP macro in the following program be expanded to on preprocessing? will the code compile?
#include<stdio.h>
#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

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

Question 7. 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 8. 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 9. 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 [] = { 
  "Sleepy", 
  "Dopey" "Doc", 
  "Happy", 
  "Grumpy" "Sneezy", 
  "Bashful", 
};

Compilation Error

5

6

7

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

5

6

10

11