The ones who are crazy enough to think they can change the world are the ones who do.
- Steve Jobs

C Functions Tricky Questions

In most of the MNC interview questions such as in ZOHO interview question, IVTL Infoview interview questions, Amazon interview questions, GOOGLE interview questions, Infosys interview questions and even in Voonik interview questions, We come across several Tricky C Questions about which 2:5 of the questions are from Functions in c. Solving that kind of tricky C questions is not an easy task for all C programmers. We need more practices to solve it with ease. So we provide 25+ interesting C questions in Functions to make your MNC interview very easy.

C Functions Questions

11. What will be the output of the C program?

#include<stdio.h>
int main()
{
	char arr[] = "function\0";
	int num = strlen(a);
	printf("Length of function is  %d", num);
	return 0;	
}

A. 9

B. 7

C. 10

D. 8

x

 

Option: D

Explanation

Here the char arrray arr will hold the initialized string "function\0", whose length will be counted from 0 till the null character. Hence num holds the integer value 8.

Answer


12. What will be the output of the C program?

#include<stdio.h>
void abc();
int *ptr;
int main()
{
	int i, *p = &i;
	abc();
	return 0;
}
void  abc()
{
	int i = 0;
	ptr = &i;
	ptr++;
	*ptr = 3;
	printf("\nFunction in C %d", i);
}

A. Function in C 0

B. Function in C 1

C. Function in C 2

D. No output

x

 

Option: A

Explanation

*ptr = 3 won't affect the value in a variable i. Because ptr is post increment to the next address of i before declaring *ptr = 3.
Thus outputted Function in C 0.

Answer


13. What will be the output of the C program by considering 'b' as a User input?

#include<stdio.h>
char normal[15] = "Ambulance";
char accident[15];
int main()
{
	swab(normal, accident, strlen(normal +1));
	printf ("%s\n", normal);
	return 0;
}

A. Ambulance

B. mAubalcne

C. mAubalcn

D. ecnalubmA

x

 

Option: C

Explanation

swab is a special type of function in c, which is capable of swapping two text consecutively in a string.
It must to noted that swab function won't display the last odd charater as we saw here "e" is missing in a string "Ambulance"

Answer


14. What will be the output of the C program?

#include<stdio.h>
void ptr(char**);
int main()
{
	char *argv[] = { "abc", "def", "ghi", "jkl", "mno", "pqr" };
	ptr(argv);
	return 0;
}
void ptr(char **p)
{
	char *t;
	t = (p += sizeof(int))[-1];
	printf("%s\n", t);
}

A. ghi

B. jkl

C. mno

D. pqr

x

 

Option: B

Explanation

Here we used pointer array to store a strings ie ) array of string using pointer variable.
ptr() is a valid function which passes the address of first element in an array *argv[].
In ptr() function we get the value p = "abc"
now t = (p = p + sizeof(int))[-1];
t = p = ((address of abc) + 4)[-1]
t = p = (address of mno)[-1]
t = p = address of jkl.
t = jkl as t is single pointer character type

What happens when p is printed

when we printf the value inside p it displays a address as it is a double pointer character type.

Answer


15. What will be the output of the C program?

#include<stdio.h>
int recursive(int i)
{
	static int count = 0;
	count = count + i;
	return count;
}
int main()
{
	int i, j;
	for (i = 0; i <= 5; i++)
	j = recursive(i);
	printf("%d\n", j);
	return 0;
}

A. 5

B. Compilation error

C. 15

D. 0

x

 

Option: C

Explanation

static int count = 0 is only for the first time od iteration because its static.

Iteration 1


count = count + i;
count = 0 + 0;
count = 0;

Iteration 2


count = count + 1;
count = 0 + 1;
count = 0;

Iteration 2


count = count + 2;
count = 1 + 2;
count = 3;

Iteration 3


count = count + 3;
count = 3 + 3;
count = 6;

Iteration 4


count = count + 4;
count = 6 + 4;
count = 10;

Iteration 5


count = count + 5;
count = 10 + 5;
count = 15;

Answer


Report Us

We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.

Report