If Else in C MCQs Exercise I


Ques 1 If Else


What is the output of the following code?
int main()
{
    int i=1;
    if(i=='1')
    {
        printf("i=1");
    }
    else
    {
        printf("i is not equal to '1'");
    }
    return 0;
}

  a) i='1'
  b) i is not equal to '1'
  c) Syntax error
  d) None of these


b is the correct option





Ques 2 If Else


What is the output of the following code ?
int main()
{
    int i;
    if(i)
        printf("SmallCode");
    else
        printf("Hello SC User");
    return 0;
}

  a) Hello SC User
  b) Error
  c) Logical Error
  d) SmallCode


b is the correct option





Ques 3 If Else


What is the output of the following code ?

int main()
{
    int i=10;
    if(i<1)
        printf("SmallCode");
    if
        printf("Hello SC User");
    return 0;
}

  a) Hello SC User
  b) Syntax Error
  c) Logical Error
  d) SmallCode


b is the correct option





Ques 4 If Else


What is the output of the following code ?(DEV C++)

int main()
{
    char i="i";
    if(i)
        printf("SmallCode");
    else
        printf("Hello SC User");
    return 0;
}

  a) Hello SC User
  b) Error
  c) Logical Error
  d) SmallCode


a is the correct option





Ques 5 If Else


What is the output of the following C Code?


#include<stdio.h>
int main()
{
    int year = 2022;
    int year = 2023;
    printf("Year : %d\n", year);
    return 0;
}

  a) Year : 2022
  b) Year : 2023
  c) Compilation Error
  d) None of these


c is the correct option