C Programming [MCQ] : Features of C (Multiple Choice Questions)
Question 1 |
What will be printed if we execute following program ?
#include<stdio.h> int main() { float a = 0.3; if(0.3 > a) printf("True\n"); else printf("False\n"); return 0; }
None of these | |
True False | |
True | |
False |
Question 1 Explanation:
We cannot compare the two float values because there is small difference between the actual float value and the value stored inside the variable.
Question 2 |
Predict the output of the program ?
#include<stdio.h> int main() { if(printf("ABC")) printf("True"); else printf("False"); return 0; }
ABCTrue | |
ABC | |
ABCFalse | |
True |
Question 2 Explanation:
Step 1 :Printf will return the number of characters printed on the screen
if(printf("ABC"))is equivalent to -
if(3). Step 2 :Thus if statement will be considered to be True and it will follow True block.
Question 3 |
Guess the output of the program ?
#include<stdio.h> int main() { int i = 1, j = 2; if(i = 1) && if(j = 2) printf("India is my country"); return 0; }
Error: Misplaced If | |
Error : Expression Syntax Error | |
Error: Undeclared identifier if | |
No output and No Error |
Question 4 |
How many times loop will get executed ?
#include<stdio.h> int main() { int i = 0; while(i <= 255) { printf("%d", i); i++; } return 0; }
1 Time | |
Infinite Times | |
256 Times | |
255 Times |
Question 4 Explanation:
i is starting from 0 so loop will be executed 256 times
Question 5 |
Point out error in the following code -
#include<stdio.h> int main() { int x = 50, y = 100; if(x = = y) printf("x is equal to y\n"); else if(x > y) printf("x is greater than y\n"); else if(x < y) printf("x is less than y\n")l return 0; }
Error: Statement missing Semicolon | |
Error: R-Value Required | |
Error: Expression syntax | |
Error: L-Value Required |
Question 5 Explanation:
We need to use "==" operator to check equality. Use of "= =" will cause L Value require error.
There are 5 questions to complete.