Pointers - C Questions

Pointers Questions - 1 Pointers Questions - 2 Pointers Questions - 3 Pointers Questions - 4 Pointers Questions - 5 Pointers Questions - 6 Pointers Questions - 7 Pointers Questions - 8

Data Types - C Questions

Data Types Questions - 1 Data Types Questions - 2 Data Types Questions - 3 Data Types Questions - 4 Data Types Questions - 5

Operators - C Questions

Operators Questions - 1 Operators Questions - 2 Operators Questions - 3 Operators Questions - 4 Operators Questions - 5

Structures - C Questions

Structures Questions - 1 Structures Questions - 2 Structures Questions - 3 Structures Questions - 4 Structures Questions - 5

Files - C Questions

Files Questions - 1 Files Questions - 2 Files Questions - 3 Files Questions - 4 Files Questions - 5

printf - C Questions

printf Questions - 1 printf Questions - 2 printf Questions - 3 printf Questions - 4 printf Questions - 5

Variables - C Questions

Variables Questions - 1 Variables Questions - 2 Variables Questions - 3 Variables Questions - 4 Variables Questions - 5

Preprocessor Macros

Preprocessor Macros - 1 Preprocessor Macros - 2 Preprocessor Macros - 3 Preprocessor Macros - 4 Preprocessor Macros - 5

While Loop - C Questions

While Loop Questions - 1 While Loop Questions - 2 While Loop Questions - 3 While Loop Questions - 4 While Loop Questions - 5

for Loop - C Questions

for Loop Questions - 1 for Loop Questions - 2 for Loop Questions - 3 for Loop Questions - 4 for Loop Questions - 5

if else - C Questions

if else Questions - 1 if else Questions - 2 if else Questions - 3 if else Questions - 4 if else Questions - 5

Switch case - C Questions

Switch case Questions - 1 Switch case Questions - 2 Switch case Questions - 3 Switch case Questions - 4 Switch case Questions - 5

Array - C Questions

Array Questions - 1 Array Questions - 2 Array Questions - 3 Array Questions - 4 Array Questions - 5

Functions - C Questions

Functions Questions - 1 Functions Questions - 2 Functions Questions - 3 Functions Questions - 4 Functions Questions - 5

Memory Allocation

Memory Allocation - 1 Memory Allocation - 2
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

We to update you