11. What will be the output of the following C code?
#include <stdio.h>
int x;
void main()
{
if (x)
printf("hi");
else
printf("how are u");
}
#include <stdio.h>
int x;
void main()
{
if (x)
printf("hi");
else
printf("how are u");
}
12. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int i = 0;
for (foo(); i == 1; i = 2)
printf("In for loop\n");
printf("After loop\n");
}
int foo()
{
return 1;
}
#include <stdio.h>
int main()
{
int i = 0;
for (foo(); i == 1; i = 2)
printf("In for loop\n");
printf("After loop\n");
}
int foo()
{
return 1;
}
13. What will be the output of the following C code?
#include <stdio.h>
int main()
{
float f = 1;
switch (f)
{
case 1.0:
printf("yes\n");
break;
default:
printf("default\n");
}
}
#include <stdio.h>
int main()
{
float f = 1;
switch (f)
{
case 1.0:
printf("yes\n");
break;
default:
printf("default\n");
}
}
14. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int i = 0;
char c = 'a';
while (i < 2)
{
i++;
switch (c)
{
case 'a':
printf("%c ", c);
break;
break;
}
}
printf("after loop\n");
}
#include <stdio.h>
int main()
{
int i = 0;
char c = 'a';
while (i < 2)
{
i++;
switch (c)
{
case 'a':
printf("%c ", c);
break;
break;
}
}
printf("after loop\n");
}
15. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int a = 1;
if (a--)
printf("True");
if (a++)
printf("False");
}
#include <stdio.h>
int main()
{
int a = 1;
if (a--)
printf("True");
if (a++)
printf("False");
}
16. What will be the output of the following C code?
#include <stdio.h>
int main()
{
printf("%d ", 1);
goto l1;
printf("%d ", 2);
}
void foo()
{
l1: printf("3 ", 3);
}
#include <stdio.h>
int main()
{
printf("%d ", 1);
goto l1;
printf("%d ", 2);
}
void foo()
{
l1: printf("3 ", 3);
}
17. What will be the output of the following C code?
#include <stdio.h>
void main()
{
char *str = "";
do
{
printf("hello");
} while (str);
}
#include <stdio.h>
void main()
{
char *str = "";
do
{
printf("hello");
} while (str);
}
18. What will be the output of the following C code?
#include <stdio.h>
void main()
{
int i = 0;
for (i = 0;i < 5; i++)
if (i < 4)
{
printf("Hello");
break;
}
}
#include <stdio.h>
void main()
{
int i = 0;
for (i = 0;i < 5; i++)
if (i < 4)
{
printf("Hello");
break;
}
}
19. Which of the following is an invalid if-else statement?
20. What will be the output of the following C code?
#include <stdio.h>
int main()
{
short i;
for (i = 1; i >= 0; i++)
printf("%d\n", i);
}
#include <stdio.h>
int main()
{
short i;
for (i = 1; i >= 0; i++)
printf("%d\n", i);
}
Read More Section(Control Structures)
Each Section contains maximum 100 MCQs question on Control Structures. To get more questions visit other sections.