0% found this document useful (0 votes)
43 views22 pages

Loops MCQ

The document contains a series of multiple-choice questions (MCQs) related to C programming, each with a code snippet and the expected output. The questions cover various topics such as loops, conditionals, switch statements, and the behavior of specific C constructs. Each MCQ is followed by the correct output or behavior of the code provided.

Uploaded by

anurithika004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views22 pages

Loops MCQ

The document contains a series of multiple-choice questions (MCQs) related to C programming, each with a code snippet and the expected output. The questions cover various topics such as loops, conditionals, switch statements, and the behavior of specific C constructs. Each MCQ is followed by the correct output or behavior of the code provided.

Uploaded by

anurithika004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

MCQ 1:

#include <stdio.h>
int main()
{
int i = 1024;
for (; i; i >>= 1)
printf("%d " , i);
return 0;
}

MCQ 2:
#include <stdio.h>
#define PRINT(i, limit) do{ if(i++ < limit){printf("%d
",i);continue;}}while(0)

int main()
{
int i = 0;
PRINT(i, 3);
return 0;
}
MCQ 3:
#include <stdio.h>
int main()
{
int i = 0;
switch (i)
{
case '0': printf("0");
break;
case '1': printf("1");
break;
default: printf("default");
}
return 0;
}
MCQ 4:
#include <stdio.h>
int main()
{
int i = 3;
switch (i)
{
case 0+1: printf("0");
break;
default: printf("default");
case 1+2: printf("3");
break;

}
return 0;
}
MCQ 5:
#include <stdio.h>
#define EVEN 0
#define ODD 1
int main()
{
int i = 3;
switch (i & 1)
{
case EVEN: printf("Even");
break;
case ODD: printf("Odd");
break;
default: printf("Default");
}
return 0;
}
MCQ 6:

#include <stdio.h>
int main()
{
int i;
if (printf("0"))
i = 3;
else
i = 5;
printf("%d", i);
return 0;
}
MCQ 7:
#include <stdio.h>
int i;
int main()
{
if (i);
else
printf("Ëlse");
return 0;
}
MCQ 8:

#include<stdio.h>
int main()
{
int n;
for (n = 9; n ; n--)
printf("n = %d", n--);
return 0;
}
MCQ 9:
#include <stdio.h>
int main()
{
int c = 5, no = 10;
do {
no /= c;
getchar();
} while(c--);

printf ("%d", no);


return 0;
}
MCQ 10:
# include <stdio.h>
int main()
{
int i = 0;
for (i=0; i<20; i++)
{
switch(i)
{
case 0:
i += 5;
case 1:
i += 2;
case 5:
i += 5;
default:
i += 4;
break;
}
printf("%d ", i);
}
return 0;
}
MCQ 11:
#include<stdio.h>
int main()
{
int i = 0;
for (printf("1stn"); i < 2 && printf("2ndn"); ++i &&
printf("3rdn"))
{
printf("*n");
}
return 0;
}
MCQ 12:
#include <stdio.h>
int main()
{
int i;
for (i = 1; i != 10; i <<= 1)
printf(" %d " , i);
return 0;
}
MCQ 13:
#include <stdio.h>
int main()
{
int i = 3;
switch(i)
{
printf("Outside ");
case 1: printf("1");
break;
case 2: printf("2");
break;
defau1t: printf("default");
}
return 0;
}
MCQ 14:
#include <stdio.h>
int main()
{
char check = 'a';
switch (check)
{
case 'a' || 1: printf("Geeks ");

case 'b' || 2: printf("Quiz ");


break;
default: printf("GeeksQuiz");
}
return 0;
}
MCQ 15:
#include <stdio.h>
int main()
{
int check = 20, arr[] = {10, 20, 30};
switch (check)
{
case arr[0]: printf("10");
case arr[1]: printf("20");
case arr[2]: printf("30");
}
return 0;
}
MCQ 16:
#include<stdio.h>
int main()
{
int i = -5;
while (i <= 5)
{
if (i >= 0)
break;
else
{
i++;
continue;
}
printf("%d " , i);
}
return 0;
}
MCQ 17:
#include <stdio.h>
int main()
{
int i = 3;
while (i--)
{
int i = 100;
i--;
printf("%d ", i);
}
return 0;
}
MCQ 18:

#include <stdio.h>
int main()
{
int x = 3;
if (x == 2); x = 0;
if (x == 3) x++;
else x += 2;

printf("x = %d", x);

return 0;
}
MCQ 19:
#include<stdio.h>
int main()
{
int a = 5;
switch(a)
{
default:
a = 4;
case 6:
a--;
case 5:
a = a+1;
case 1:
a = a-1;
}
printf("%d", a);
return 0;
}
MCQ 20:
#include <stdio.h>
int *A, stkTop;
int stkFunc (int opcode, int val)
{
static int size=0, stkTop=0;
switch (opcode)
{
case -1:
size = val;
break;
case 0:
if (stkTop < size ) A[stkTop++]=val;
break;
default:
if (stkTop) return A[--stkTop];
}
return -1;
}
int main()
{
int B[20];
A=B;
stkTop = -1;
stkFunc (-1, 10);
stkFunc (0, 5);
stkFunc (0, 10);
printf ("%d", stkFunc(1, 0)+ stkFunc(1, 0));
}
MCQ 21:
#include "stdio.h"

int main()
{
int i = 1, j;
for ( ; ; )
{
if (i)
j = --i;
if (j < 10)
printf("%d ", j++);
else
break;
}
return 0;
}
MCQ 22:

#include "stdio.h"
int main()
{
int j = 0;
for ( ; j < 10 ; )
{
if (j < 10)
printf("%d ", j++);
else
continue;
printf("#");
}
return 0;
}
MCQ 23:

#include <stdio.h>

int main()
{
unsigned int i = 65000;
while (i++ != 0);
printf("%d", i);
return 0;
}
1)
1024 512 256 128 64 32 16 8 4 2 1
2)
1
3)
Default
4)
3
5)
Odd
6)
03
7)
Ëlse
8)
n = 9n = 7n = 5n = 3n = 1n = -1n = -3……..
9)
A
A
A
Floating point exception
10)
16 21
11)
1stn2ndn*n3rdn2ndn*n3rdn
12)
1 2 4 8 16 32 64 128 256 512 1024 2048 4096
8192 16384 32768 65536 131072 262144 524288
1048576 2097152 4194304 8388608 16777216
33554432 67108864 134217728 268435456
536870912 1073741824 -2147483648 0 0 0 0 0 0 0
0 0………
13)

14)
ERROR
15)
ERROR
16)

17)
99 99 99
18)
x=2
19)
5
20)
15
21)
0123456789
22)
0 #1 #2 #3 #4 #5 #6 #7 #8 #9 #
23)
1

You might also like