1. What will be the output of the following code?
#include<stdio.h>
int var;
int main()
{
printf(“%d”, var);
return 0;
}
a) garbage
b) 0
c) no output
d) Compilation error
Answer: b)
2. What will be the output of the following code?
#include<stdio.h>
int main()
{
int i=5;
printf(“%d”,i–);
if(i)
main();
return 0;
}
a) 5 4 3 2 1
b) 5 5 5 5 5…..till stack overflow
c) 4 4 4 4 4…..till stack overflow
d) compilation error
Answer: b)
3. What will be the output of the following code?
#include<stdio.h>
int main()
{
typedef static int i;
i var;
printf(“%d”, var);
return 0;
}
a) garbage
b) 0
c) no output
d) Compilation error
Answer: d)
4. What will be the output of the following code?
#include<stdio.h>
int main()
{
typedef int i;
printf(“%d”, i);
return 0;
}
a) garbage
b) 0
c) no output
d) Compilation error
Answer: d)
5. The memory space to local variables is allocated from
a) Stack
b) Heap
c) Queue
d) Data segment
Answer : a)
6. What will be the output of the following code?
#include<stdio.h>
int main()
{
int i;
for(i=0;i<3;i++)
{
int x=0;
static int y=0;
printf(“x=%d, y=%d\n”,x++,y++);
}
return 0;
}
a) x=0, y=0
x=1, y=1
x=2, y=2
b) x=0, y=0
x=0, y=1
x=0, y=2
c) x=0, y=0
x=0, y=0
x=0, y=0
d) x=1, y=1
x=2, y=2
x=3, y=3
Answer : b)
7. What will be the output of the following code?
#include<stdio.h>
function(static int para)
{
printf(“%d”,para);
}
int main()
{
int i=200;
printf(“%d “, i);
function(i);
return 0;
}
a) 200 200
b) 200 0
c) 200 garbage
d) Compilation error
Answer : d)
8. What will be the output of the following code?
#include<stdio.h>
int main()
{
extern int i;
printf(“%d”, i);
return 0;
}
int i=100;
a) garbage
b) 0
c) 100
d) Compilation error
Answer : c)
C MCQ Set-14 Explanation
9. What will be the output of the program?
#include<stdio.h>
int main()
{
typedef int arr[5];
arr iarr = {1, 2, 3, 4, 5};
int i;
for(i=0; i<4; i++)
printf(“%d, “, iarr[i]);
return 0;
}
a) 1, 2, 3, 4,
b) 1, 2, 3, 4, 5,
c) 1,2,3,4
d) Error: Cannot use typedef with an array
Answer: a)
C MCQ Set-14 Explanation
10. Consider the following C program segment:
int main()
{
char p[20];
char *s = “string”;
int length = strlen(s);
int i;
for (i = 0; i < length; i++)
p[i] = s[length – i];
printf(“%s”,p);
}
The output of the program is:
a) gnirts
b) gnirt
c) string
d) no output is printed
Answer: D