• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C Quiz - 110

Question 1

Suppose someone writes increment macro (i.e. which increments the value by one) in following ways: C
#define INC1(a) ((a)+1)

#define INC2 (a) ((a)+1)

#define INC3( a ) (( a ) + 1)

#define INC4 ( a ) (( a ) + 1)
Pick the correct statement for the above macros.
  • Only INC1 is correct.
  • All (i.e. INC1, INC2, INC3 and INC4) are correct.
  • Only INC1 and INC3 are correct.
  • Only INC1 and INC2 are correct.

Question 2

The following program won’t compile because there’re space between macro name and open parenthesis. C
#include \"stdio.h\"

#define MYINC   (  a  )  (  ( a )  +  1 )

int main()
{

 printf(\"GeeksQuiz!\");

 return 0;
}
  • TRUE
  • FALSE

Question 3

The below program would give compile error because comma has been used after foo(). Instead, semi-colon should be used i.e. the way it has been used after bar(). That\'s why if we use semi-colon after foo(), the program would compile and run successfully while printing "GeeksQuiz" C
#include \"stdio.h\"

void foo(void)
{
 printf(\"Geeks\");
}
void bar(void)
{
 printf(\"Quiz\");
}

int main()
{
 foo(), bar();
 return 0;
}
  • TRUE
  • FALSE

Question 4

Which one of the choices given below would be printed when the following program is executed? C
#include
void swap (int *x, int *y)
{
    static int *temp;
    temp = x;
    x = y;
    y = temp;
}
void printab ()
{
    static int i, a = -3, b = -6;
    i = 0;
    while (i <= 4)
    {
        if ((i++)%2 == 1) continue;
        a = a + i;
        b = b + i;
    }
    swap (&a, &b);
    printf(\"a =  %d, b = %d\\n\", a, b);
}
main()
{
    printab();
    printab();
} 
  • a = 0, b = 3
    a = 0, b = 3
  • a = 3, b = 0
    a = 12, b = 9
  • a = 3, b = 6
    a = 3, b = 6
  • a = 6, b = 3
    a = 15, b = 12

Question 5

The following function computes the value of mCn correctly for all legal values m and n (m≥1,n≥0 and m>n)
C
 int func(int m, int n)
{
    if (E) return 1;
    else return(func(m -1, n) + func(m - 1, n - 1));
}
In the above function, which of the following is the correct expression for E?
  • (n = = 0) || (m = = 1)
  • (n = = 0) && (m = = 1)
  • (n = = 0) || (m = = n)
  • (n = = 0) && (m = = n)

Question 6

Typically, library header files in C (e.g. stdio.h) contain not only declaration of functions and macro definitions but they contain definition of user defined data types (e.g. struct, union etc), typedefs and definition of global variables as well. So if we include the same header file more than once in a C program, it would result in compile issue because re-definition of many of the constructs of the header file would happen. So it means the following program will give compile error. 
 

C
#include “stdio.h”
#include “stdio.h”
#include “stdio.h”

int main()
{
 printf(Whether this statement would be printed?)
 return 0;
}
  • TRUE
     

  • FALSE
     

Question 7

In C, 1D array of int can be defined as follows and both are correct. 
 

C
int array1D[4] = {1,2,3,4};
int array1D[] = {1,2,3,4};

But given the following definitions (along-with initialization) of 2D arrays 
 

C
int array2D[2][4] = {1,2,3,4,5,6,7,8}; /* (i) */
int array2D[][4] = {1,2,3,4,5,6,7,8}; /* (ii) */
int array2D[2][] = {1,2,3,4,5,6,7,8}; /* (iii) */
int array2D[][] = {1,2,3,4,5,6,7,8}; /* (iv) */

Pick the correct statements.
 

  • Only (i) is correct.
     

  • Only (i) and (ii) are correct.
     

  • Only (i), (ii) and (iii) are correct.
     

  • All (i), (ii), (iii) and (iv) are correct.
     

There are 7 questions to complete.

Last Updated :
Take a part in the ongoing discussion