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;
}
A
None of these
B
True False
C
True
D
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;
}
A
ABCTrue
B
ABC
C
ABCFalse
D
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;
}
A
Error: Misplaced If
B
Error : Expression Syntax Error
C
Error: Undeclared identifier if
D
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;
}
A
1 Time
B
Infinite Times
C
256 Times
D
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;
}
A
Error: Statement missing Semicolon
B
Error: R-Value Required
C
Error: Expression syntax
D
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.