• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

50 C Language MCQs with Answers

Question 41

In C, parameters are always 
 

  • Passed by value
     

  • Passed by reference
     

  • Non-pointer variables are passed by value and pointers are passed by reference
     

  • Passed by value result
     

Question 42

Which of the following is true about return type of functions in C?
 

  • Functions can return any type
     

  • Functions can return any type except array and functions
     

  • Functions can return any type except array, functions and union
     

  • Functions can return any type except array, functions, function pointer and union
     

Question 43

Which one of the following is correct for overloaded functions in C++ ?
 

  • Compiler sets up a separate function for every definition of function.
     

  • Compiler does not set up a separate function for every definition of function. 
     

  • Overloaded functions cannot handle different types of objects. 
     

  • Overloaded functions cannot have same number of arguments. 
     

Question 44

Consider the following C-program :
C
int fun(){  static int num = 16;  return num--;}int main(){  for(fun(); fun(); fun())    printf(\"%d \", fun());  return 0;}
What is output of above program?
  • Infinite loop
     

  • 13 10 7 4 1
     

  • 15 12 8 5 2
     

  • 14 11 8 5 2
     

Question 45

Assuming int size is 4 bytes, what is going to happen when we compile and run the following program? 
 

C
#include “stdio.h”
int main()
{
  printf(GeeksQuiz\\n);
  main();
  return 0;
}
  • We can’t use main() inside main() and compiler will catch it by showing compiler error.
     

  • GeeksQuiz would be printed in 2147483647 times i.e. (2 to the power 31) - 1.
     

  • It’ll print GeeksQuiz infinite times i.e. the program will continue to run forever until it’s terminated by other means such as CTRL+C or CTRL+Z etc.
     

  • GeeksQuiz would be printed only once. Because when main() is used inside main(), it’s ignored by compiler at run time. This is to make sure that main() is called only once.
     

  • GeeksQuiz would be printed until stack overflow happens for this program.
     

Question 46

Which of the following is not a storage class specifier in C?
 

  • auto
     

  • register
     

  • static
     

  • extern
     

  • volatile
     

Question 47

What is the output of the following program? 
 

#include 
int tmp=20;
main( )
{
printf("%d ",tmp);
func( );
printf("%d ",tmp);
}
func( )
{
static int tmp=10;
printf("%d ",tmp);
}


 

  • 20 10 10
     

  • 20 10 20
     

  • 20 20 20
     

  • 10 10 10
     

Question 48

If only one memory location is to be reserved for a class variable, no matter how many objects are instantiated, then the variable should be declared as 

 

  • extern
     

  • static
     

  • volatile
     

  • const
     

Question 49

In C, static storage class cannot be used with:
 

  • Global variable
     

  • Function parameter
     

  • Function name
     

  • Local variable
     

Question 50

Consider the following code:

C++
int a, b, c = 0;

void prtFun(void);

void main()
{
    static int a = 1;
    prtFun();
    a += 1;
    prtFun() printf("\n %d %d ", a, b);
}

void prtFun(void)
{
    static int a = 2;
    int b = 1;
    a += ++b;
    printf("\n %d %d ", a, b);
}

What output will be generated by the given code d\\segment if: 
Line 1 is replaced by “auto int a = 1;” 
Line 2 is replaced by “register int a = 2;” (GATE CS 2012) 
 

  • 3 1

    4 1

    4 2

     

  • 4 2

    6 1

    6 1

     

  • 4 2

    6 2

    2 0

     

  • 4 2

    4 2

    2 0

     

There are 50 questions to complete.

Last Updated :
Take a part in the ongoing discussion