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 if else 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 if else 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 if else to make your MNC interview very easy.

C if else Questions

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

#include<stdio.h>
int main()
{
	int i = 5, j = 6, k = 7;
	if(i > j == k)
		printf("%d %d %d", i++, ++j, --k);
	else	
		printf("%d %d %d", i, j, k);
	return 0;
}

A. 5 7 6

B. 5 6 7

C. 6 6 6

D. 5 7 7

x

 

Option: B

Explanation

The if statement condition is (i > j == k) becomes (5 > 6 == 7) its looks like (expression1 == expression2), expression1 becomes 0 and expression2 is a non-zero value so expression2 returns 1. Finally the condition is False (0 == 1) so else block gets executed.

For Example

*(ptr + 0) = 2
*(ptr + 1) = 3
*(ptr + 2) = 5
*(ptr + 3) = 7
*(ptr + 4) = 11
*(ptr + 5) = 13

Answer


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

#include<stdio.h>
int main()
{
	int i = 2;
	if(i == (1, 2))
		printf("Hai");
	else
		printf("No Hai");
	return 0;
}

A. Compilation Error

B. Runtime Error

C. Hai

D. No Hai

x

 

Option: C

Explanation

The condition if(i == (1, 2)) is if(expression1 == (expression2, expression3)). The expression3 is evaluated last so the if block gets executed.

Answer


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

#include<stdio.h>
int main(){
char str[8] = "2braces";
char str1[8] = "2braces";
   if(str == str1)
	   printf("Strings are Equal");
   else
	   printf("Not Equal");
return 0;
}

A. Compilation Error

B. Run time error

C. Strings are Equal

D. Not Equal

x

 

Option: D

Explanation

String cannot be compared normally using == operator, if we compared two strings using == operator, a character alone will be compared which usually some random special character.

#include<stdio.h>
int main(){
	char str[8] = "2braces";
	printf("%c",str);
	return 0;
}

Answer


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

#include<stdio.h>
int main(){
	int i = 5;
    if(i == 3, 4)
     	printf("Hai");
    else
		printf("No Hai");
	return 0;
}

A. Hai

B. No Hai

C. Compilation Error

D. None of the Above

x

 

Option: A

Explanation

The if statement in the above C program is if(i == 3, 4) which means if(expression1 == expression2), expression1 is a direct non-zero value so it always returns 1 and expression 2 has a , operator it acts as a seperate expression and returns 1. So the condition is true and if block gets executed. But if you run the below program:

#include<stdio.h>
int main(){
	int i = 5;
	if(i == 3)
		printf("Hai");
	else
		printf("No Hai");
	return 0;
}

This C program will print No Hai.

Answer


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

#include<stdio.h>
int main(){
	char *str = {"2braces"};
	char *str1 = {"2braces"};
	if(*str == *str1)
		printf("inside if block");
	else 
		printf("inside else block");
	return 0;
}

A. Runtime Error

B. Compilation Error

C. inside if block

D. inside else block

x

 

Option: C

Explanation

In the above C program, while comparing two strings using pointer character variables, the *str and *str1 will takes complete memory location to compare two strings.

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