Home » C Programming » Decision Making » Question
  1. What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard input).
    #include <stdio.h>
    void main()
    {
    double var;
    printf("Enter a value between 1 to 2:");
    scanf("%lf", &var);
    switch (var)
    {
    case 1:
    printf("1");
    break;
    case 2:
    printf("2");
    break;
    }
    }
    1. 1
    2. Compilation Error
    3. 2
    4. Runtime Error
    5. None of these
Correct Option: B

Compilation Error

error: '::main' must return 'int'
void main()
In function 'int main()':
error: switch quantity not an integer
switch (var)



Your comments will be displayed only after manual approval.