MCQ Computer Science

C Programming Questions and Answers – If-then-else Statements – 1

C Programming Questions and Answers – If-then-else Statements – 1

1. The output of the code below is

#include <stdio.h>
void main()
{
int x = 5;
if (x < 1)
printf(“hello”);
if (x == 5)
printf(“hi”);
else
printf(“no”);
}
a) hi
b) hello
c) no
d) None of the mentioned

View Answer

Answer:a

2. The output of the code below is

#include <stdio.h>
int x;
void main()
{
if (x)
printf(“hi”);
else
printf(“how are u”);
}
a) hi
b) how are you
c) Compile time error
d) None of the mentioned

View Answer

Answer:b

3. Comment on the following code below

#include <stdio.h>
void main()
{
int x = 5;
if (true);
printf(“hello”);
}
a) It will display hello
b) It will throw an error
c) Nothing will be displayed
d) Compiler dependent

View Answer

Answer:b

4. The output of the code below is

#include <stdio.h>
void main()
{
int x = 0;
if (x == 0)
printf(“hi”);
else
printf(“how are u”);
printf(“hello”);
}
a) hi
b) how are you
c) hello
d) hihello

View Answer

Answer:d

5. The output of the code below is

#include <stdio.h>
void main()
{
int x = 5;
if (x < 1);
printf(“Hello”);

}
a) Nothing
b) Run time error
c) Hello
d) Varies

View Answer

Answer:c

6. The output of the code below is(when 1 is entered)

#include <stdio.h>
void main()
{
double ch;
printf(“enter a value btw 1 to 2:”);
scanf(“%lf”, &ch);
switch (ch)
{
case 1:
printf(“1”);
break;
case 2:
printf(“2”);
break;
}
}
a) Compile time error
b) 1
c) 2
d) Varies

View Answer

Answer:a

7. The output of the code below is(When 1 is entered)

#include <stdio.h>
void main()
{
char *ch;
printf(“enter a value btw 1 to 3:”);
scanf(“%s”, ch);
switch (ch)
{
case “1”:
printf(“1”);
break;
case “2”:
printf(“2”);
break;
}
}
a) 1
b) 2
c) Compile time error
d) No Compile time error

View Answer

Answer:c

8. When 1 is entered, The output of the code below is?

#include <stdio.h>
void main()
{
int ch;
printf(“enter a value btw 1 to 2:”);
scanf(“%d”, &ch);
switch (ch)
{
case 1:
printf(“1\n”);
default:
printf(“2\n”);
}
}
a) 1
b) 2
c) 1 2
d) Run time error

View Answer

Answer:c

9. When 2 is entered, The output of the code below is?

#include <stdio.h>
void main()
{
int ch;
printf(“enter a value btw 1 to 2:”);
scanf(“%d”, &ch);
switch (ch)
{
case 1:
printf(“1\n”);
break;
printf(“Hi”);
default:
printf(“2\n”);
}
}
a) 1
b) Hi 2
c) Run time error
d) 2

View Answer

Answer:d

10. When 1 is entered, The output of the code below is?

#include <stdio.h>
void main()
{
int ch;
printf(“enter a value btw 1 to 2:”);
scanf(“%d”, &ch);
switch (ch, ch + 1)
{
case 1:
printf(“1\n”);
break;
case 2:
printf(“2”);
break;
}
}
a) 1
b) 2
c) 3
d) Run time error

View Answer

Answer:b

For more Visit the Link:

Computer Science MCQ All Topic C programming MCQ All Topic

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button