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
False
B
True False
C
True
D
None of these
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
True
B
ABC
C
ABCTrue
D
ABCFalse
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
No output and No Error
B
Error: Misplaced If
C
Error: Undeclared identifier if
D
Error : Expression Syntax 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
256 Times
B
1 Time
C
255 Times
D
Infinite 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: L-Value Required
C
Error: Expression syntax
D
Error: R-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.