C Technical Interview Questions on Functions

These C Technical Interview Questions on functions post providing basic, intermediate and Hard level examples in C Functions. The Practice of these examples makes you good in C programming.


Find the output of following program
#include<stdio.h>
void f(int, int);
void main()
{
int i=10;
f(i, i++);
printf(“%d\n”,i);
}
void f(int i, int j)
{
if(i>40)
return;
i+=j;
f(i,j);
printf(“%d\n”,i);
}

  1. Compile time error
  2. infinite loop
  3. 41,11
  4. 41,31,21,11

Answer :

Ans : 4, Printing the values at the last statement of recursive function

Find the output of following program
#include <stdio.h>
#include <conio.h>
void main()
{
while (!kbhit())
printf(“Hello.\n”);
return 0;
}

  1. prints ‘hello’ until you press key on keyboard
  2. Compile time error
  3. prints ‘hello’ until stack is over flow
  4. prints hello only once

Answer :

Ans : 1, kbhit() function returns non-zero when we press any key on keyboard

Find the output of following program
#include<stdio.h>
#include<conio.h>
void main()
{
int x;
printf(“Hello”);
x = wherex();
printf(“%d\n”,x);
return 0;
}

  1. Hello
  2. Hello5
  3. Hello6
  4. Error

Answer :

Ans : 3, wherex() function returns the cursor position on x axis

What is the output of following code?
#include <stdio.h>
#include <math.h>
int main()
{
int n=-19 ;
printf(“n :%d\n”,abs(n));
return 0;
}

  1. -19
  2. 19
  3. 1
  4. 0

Answer :

Ans : 2

What is the output of following code?
#include <stdio.h>
#include <math.h>
int main()
{
int n=3 ;
printf(“%.2f\n” , sqrt(n));
return 0;
}

  1. 1.7
  2. 1
  3. 1.732000
  4. 1.73

Answer :

Ans : 4, Printing only 2 decimals of sqrt(3) value

 Arrays – Technical – Part 1

Share this