• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C Functions

Question 31

Consider the following C++ program\'
int a (int m)
{return ++m;}
int b(int&m)
{return ++m;}
int c(char &m)
{return ++m;} 

void main 0
{
      int p = 0, q = 0, r = 0; 
      p += a(b(p));
      q += b(a(q));
      r += a(c(r));
      cout<

Assuming the required header files are already included, the above program:

  • results in compilation error
  • print 123
  • print 111
  • print 322

Question 32

What is the output of the following program ?
main (){
int x = 2, y = 5;
if(x < y) return (x = x + y);
else printf ("z1");
printf("z2");

  • z2
  • z1z2
  • Compilation error
  • None of these

Question 33

Consider the following program
main()
{
int x = 1;
printf ("%d", (*char(char *)&x)) ;
}

Assuming required header files are included and if the machine in which this program is executed is little-endian, then the output will be
  • 0
  • 99999999
  • 1
  • unpredictable

Question 34

Consider the following C program
#include 
main()
{
float sum = 0.0, j =1.0, i = 2.0; 
while(i/j > 0.001) {
    j = j + 1;
    sum = sum + i/j;
    printf ( "%f\\n", sum );
    }
}
How many lines of output does this program produce?
  • 0-9 lines of output
  • 10-19 lines of output
  • 20-29 lines of output
  • More than 29 lines of output

Question 35

Given below are three implementations of the swap( ) function in C++: (a)
void swap (int a, int b)
{
int temp;
temp = a;
a = b;
b = temp;
}
int main( )
{
int p = 0, q = 1;
swap (p, q);
}

(b)
void swap (int &a, int &b)
{
int temp;
temp = a;
a = b;
b = temp;
}
int main( )
{
int p = 0, q = 1;
swap (p, q);
}

(c)
void swap (int * a, int * b)
{
int * temp;
temp = a;
a = b;
b = temp;
}
int main( )
{
int p = 0, q = 1;
swap (&p, &q);
}

Which of these would actually swap the contents of the two integer variables p and q?
  • (a) only
  • (b) only
  • (c) only
  • (b) and (c) only

Question 36

Consider a Boolean function of ‘n’ variables. The order of an algorithm that determines whether the Boolean function produces a output 1 is
  • Logarithmic
  • Linear
  • Quadratic
  • Exponential

Question 37

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 38

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 39

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 40

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
     

There are 41 questions to complete.

Last Updated :
Take a part in the ongoing discussion