Sail E0 Webinar

MCQs

Total Questions : 63 | Page 2 of 7 pages
Question 11.

Functions can be called either by value or reference


  1.    True
  2.    False
 Discuss Question
Answer: Option A. -> True

True, A function can be called either call by value or call by reference.

Example:

Call by value means c = sub(a, b); here value of a and b are passed.

Call by reference means c = sub(&a, &b); here address of a and b are passed.


Question 12.

In C all functions except main() can be called recursively.


  1.    True
  2.    False
 Discuss Question
Answer: Option B. -> False

Any function including main() can be called recursively.


Question 13.

A function cannot be defined inside another function


  1.    True
  2.    False
 Discuss Question
Answer: Option A. -> True

A function cannot be defined inside the another function, but a function can be called inside 

a another function.


Question 14.

Functions cannot return more than one value at a time


  1.    True
  2.    False
 Discuss Question
Answer: Option A. -> True

True, A function cannot return more than one value at a time. because after returning a value 

the control is given back to calling function.


Question 15.

If return type for a function is not specified, it defaults to int


  1.    True
  2.    False
 Discuss Question
Answer: Option A. -> True

True, The default return type for a function is int.


Question 16.


Which of the following statements are correct about the function?


long fun(int num)
{
int i;
long f=1;
for(i=1; i
  1.    The function calculates the value of 1 raised to power num.
  2.    The function calculates the square root of an integer
  3.    The function calculates the FACTORIAL value of an integer
  4.    None of above
 Discuss Question
Answer: Option C. -> The function calculates the FACTORIAL value of an integer

Yes, this function calculates and return the factorial value of an given integer num.


Question 17.


There is a error in the below program. Which statement will you add to remove it?


#include<stdio.h>
int main()
{
int a;
a = f(10, 3.14);
printf("%d\n", a);
return 0;
}
float f(int aa, float bb)
{
return ((float)aa + bb);
}
  1.    Add prototype: float f(aa, bb)
  2.    Add prototype: float f(int, float)
  3.    Add prototype: float f(float, int)
  4.    Add prototype: float f(bb, aa)
 Discuss Question
Answer: Option B. -> Add prototype: float f(int, float)

The correct form of function f prototype is float f(int, float);


Question 18.


Which of the following statements are correct about the program?


#include<stdio.h>
int main()
{
printf("%p\n", main());
return 0;
}
  1.    It prints garbage values infinitely
  2.    Runs infinitely without printing anything
  3.    Error: main() cannot be called inside printf()
  4.    No Error and print nothing
 Discuss Question
Answer: Option B. -> Runs infinitely without printing anything

In printf("%p`setminus`n", main()); it calls the main() function and then it repeats infinetly,

 untill stack overflow.



Question 19.


Point out the error in the program


#include<stdio.h>
int f(int a)
{
a > 20? return(10): return(20);
}
int main()
{
int f(int);
int b;
b = f(20);
printf("%d\n", b);
return 0;
}
  1.    Error: Prototype declaration
  2.    No error
  3.    Error: return statement cannot be used with conditional operators
  4.    None of above
 Discuss Question
Answer: Option C. -> Error: return statement cannot be used with conditional operators

In a ternary operator, we cannot use the return statement. The ternary operator

 requires expressions but not code.


Question 20.


Point out the error in the program


#include<stdio.h>
int main()
{
int a=10;
void f();
a = f();
printf("%d\n", a);
return 0;
}
void f()
{
printf("Hi");
}
  1.    Error: Not allowed assignment
  2.    Error: Doesn't print anything
  3.    No error
  4.    None of above
 Discuss Question
Answer: Option A. -> Error: Not allowed assignment

The function void f() is not visible to the compiler while going through main() function. 

So we have to declare this prototype void f(); before to main() function. This kind of 

error will not occur in modern compilers.


Latest Videos

Latest Test Papers