Exercise: Questions on Functions


Questions on Functions : Question 1 :
Output of following program?
#include <stdio.h>
int main()
{
    int i = 5;
    printf("%d %d %d", i++, i++, i++);
    return 0;
}

7 6 5
5 6 7
7 7 7
Compiler Dependent
Show Answer
Questions on Functions : Question 2 :
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
Show Answer
Questions on Functions : Question 3 :
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
Show Answer
Questions on Functions : Question 4 :
#include <stdio.h>
int main()
{
  printf("%d", main);  
  return 0;
}

Address of main function
Compiler Error
Runtime Error
Some random value
Show Answer
Questions on Functions : Question 5 :
Output?
 #include <stdio.h>
 
 int main()
 {
     int (*ptr)(int ) = fun;
     (*ptr)(3);
     return 0;
 }
 
 int fun(int n)
 {
   for(;n > 0; n--)
     printf("PROcoder ");
   return 0;
 }
 

PROcoder PROcoder PROcoder
PROcoder PROcoder
Compiler Error
Runtime Error
Show Answer
Questions on Functions : Question 6 :
Output of following program?
#include<stdio.h>

void dynamic(int s, ...)
{
    printf("%d ", s);
}

int main()
{
    dynamic(2, 4, 6, 8);
    dynamic(3, 6, 9);
    return 0;
}

2 3
Compiler Error
4 3
3 2
Show Answer
Questions on Functions : Question 7 :
Predict the output?
 #include <stdio.h>
 int main()
 {
     void demo();
     void (*fun)();
     fun = demo;
     (*fun)();
     fun();
     return 0;
 }
 
 void demo()
 {
     printf("PROcoder ");
 }
 

PROcoder
PROcoder PROcoder
Compiler Error
Blank Screen
Show Answer
Questions on Functions : Question 8 :
What is the meaning of using extern before function declaration? For example following function sum is made extern
extern int sum(int x, int y, int z)
{
    return (x + y + z);
}

Function is made globally available
extern means nothing, sum() is same without extern keyword.
Function need not to be declared before its use
Function is made local to the file.
Show Answer
Questions on Functions : Question 9 :
What is the meaning of using static before function declaration? For example following function sum is made static
static int sum(int x, int y, int z)
{
    return (x + y + z);
}

Static means nothing, sum() is same without static keyword.
Function need not to be declared before its use
Access to static functions is restricted to the file where they are declared
Static functions are made inline
Show Answer
Questions on Functions : Question 10 :
In C, what is the meaning of following function prototype with empty parameter list
void fun()
{
   /* .... */
}

Function can only be called without any parameter
Function can be called with any number of parameters of any types
Function can be called with any number of integer parameters.
Function can be called with one integer parameter.
Show Answer