C PROGRAMMING MOCK TEST
http://www.tutorialspoint.com/cprogramming/pdf/cprogramming_mock_test_ii.htm Copyright tutorials point.com
This sect ion present s you various set of Mock Test s relat ed t o C Pro gramming Framewo rk. You
can download t hese sample mock t est s at your local machine and solve offline at your convenience.
Every mock t est is supplied wit h a mock t est key t o let you verify t he final score and grade yourself.
C PROGRAMMING MOCK TEST II
Q 1 - Linker generates ___ file.
A - Object code
B - Execut able code
C - Assembly code
D - None of t he above.
Q 2 - Co mpiler generates ___ file.
A - Execut able code
B - Object code
C - Assembly code
D - None of t he above.
Q 3 - Special symbo l permitted with in the identifier name.
A-$
B- @
C-_
D- .
Q 4 - A single line co mment in C language so urce co de can begin with _____
A-;
B- :
C - /*
D - //
Q 5 - A macro can execute faster than a functio n.
A - t rue
B - false
Q 6 - Cho o se the invalid identifier fro m the belo w
A - Int
B - volat ile
C - DOUBLE
D - __0__
Q 7 - Cho o se the applicatio n o ptio n fo r the fo llo wing pro gram?
#include<stdio.h>
main()
{
int *p, **q;
printf("%u\n", sizeof(p));
printf("%u\n", sizeof(q));
}
A - Bot h t he print f() will print t he same value
B - First print f() print s t he value less t han t he second.
C - Second print f() print s t he value less t han t he first .
D - Error in t he code.
Q 8 - What is the built in library functio n to adjust the allo cated dynamic memo ry
size.
A - malloc
B - calloc
C - realloc
D - resize
Q 9 - Identify the C co mpiler o f UNIX.
A - gcc
B - cc
C - Borland
D - vc++
Q 10 - Fo llo wing is the invalid inclusio n o f a file to the current pro gram. Identify it.
A - #include <file>
B - #include file
C - #include < file
D - All of t he above are invalid.
Q 11 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
int* f()
{
int x = 5;
return &x;
}
main()
{
printf("%d", *f());
}
A-5
B - Address of x
C - Compile error
D - Runt ime error
Q 12 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
main()
{
char *p = NULL;
printf("%c", *p);
}
A - NULL
B- 0
C - Compile error
D - Runt ime error.
Q 13 - T he default executable generatio n o n UNIX fo r a C pro gram is ___
A - a.exe
B- a
C - a.out
D - out .a
Q 14 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
void f()
{
static int i = 3;
printf("%d ", i);
if(--i) f();
}
main()
{
f();
}
A - 321 0
B- 321
C - 333
D - Compile error
Q 15 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
main()
{
}
A - No out put
B - Garbage
C - Compile error
D - Runt ime error
Q 16 - Cho o se the co rrect o ptio n in respect to the fo llo wing pro gram.
#include<stdio.h>
void f(int const i)
{
i=5;
}
main()
{
int x = 10;
f(x);
}
I - Erro r in the statement vo id f(int co nst i)
II - Erro r in the statement i=5.
A - St at ement s I & II are t rue
B - St at ement s I & II are false.
C - St at ement I is t rue
D - St at ement II is t rue.
Q 17 - T o sto re a wo rd/sentence declare a variable o f the type string.
A - t rue
B - false
Q 18 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
int x = 5;
int* f()
{
return &x;
}
main()
{
*f() = 10;
printf("%d", x);
}
A - Compile error
B - Runt ime error
C-5
D - 10
Q 19 - What is the o utput o f the belo w co de snippet.
#include<stdio.h>
main()
{
printf("%d", -11%2);
}
A-1
B - -1
C - 5.5
D - -5.5
Q 20 - What is the o utput o f the fo llo wing statement?
#include<stdio.h>
main()
{
printf("\\ri\\ng \\the \\bells");
}
A - \ri\ng \t he \bells
B- i
g heells
C-i
he \bells
D - None of t he above
Q 21 - Do es bo th the lo o ps in the fo llo wing pro grams prints the co rrect string
length?
#include<stdio.h>
main()
{
int i;
char s[] = "hello";
for(i=0; s[i]; ++i);
printf("%d ", i);
i=0;
while(s[i++]);
printf("%d ", i);
}
A - Yes, bot h t he loops print s t he correct lengt h
B - Only for loop print s t he correct lengt h
C - Only while loop print s t he correct lengt h
D - Compile error in t he program.
Q 22 - Fo r the belo w definitio n what is the data type o f PI
#define PI 3.141
A - It s float
B - It s double
C - There is no t ype associat ed wit h PI, as it s just a t ext subst it ut ion
D - Synt ax error, semi colon is missing wit h t he definit ion of PI
Q 23 - Cho o se the invalid predefined macro as per ANSI C.
A - __FILE__
B - __DATE__
C - __TIME__
D - __C++__
Q 24 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
main()
{
int a[] = {10, 20, 30};
printf("%d", *a+1);
}
A - 10
B - 20
C - 11
D - 21
Q 25 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
void f(int a[])
{
int i;
for(i=0; i<3; i++)
a[i]++;
}
main()
{
int i,a[] = {10, 20, 30};
f(a);
for(i=0; i<3; ++i)
{
printf("%d ",a[i]);
}
}
A - 10 20 30
B - 11 21 31
C - Compile error
D - Runt ime error
Q 26 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
main()
{
char *s = "Hello, "
"World!";
printf("%s", s);
}
A - Hello, World!
B - Hello,
Wo rld!
C - Hello
D - Compile error
Q 27 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
main()
{
fprintf(stdout,"Hello, World!");
}
A - Hello, World!
B - No out put
C - Compile error
D - Runt ime error
Q 28 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
main()
{
fprintf(stdout,"Hello, World!");
}
A - Hello, World!
B - No out put
C - Compile error
D - Runt ime error
Q 29 - Which o f the fo llo wing is used in mo de string to o pen the file in binary
mo de?
A-a
B- b
C-B
D - bin
Q 30 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
main()
{
char s[] = "Fine";
*s = 'N';
printf("%s", s);
}
A - Fine
B - Nine
C - Compile error
D - Runt ime error
Q 31 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
main()
{
char *s = "Fine";
*s = 'N';
printf("%s", s);
}
A - Fine
B - Nine
C - Compile error
D - Runt ime error
Q 32 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
main()
{
int x;
float y;
y = x = 7.5;
printf("x=%d y=%f", x, y);
}
A - 7 7.000000
B - 7 7.500000
C - 5 7.500000
D - 5 5.000000
Q 33 - What is the built in library functio n to co mpare two strings?
A - st ring_cmp()
B - st rcmp()
C - equals()
D - st r_compare()
Q 34 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
main()
{
char s1[50], s2[50] = "Hello";
s1 = s2;
printf("%s", s1);
}
A - Hello
B - No out put
C - Compile error
D - Runt ime error
Q 35 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
int main();
void main()
{
printf("Okay");
}
A - Okay
B - No out put
C - Compile error. We cannot declare main() funct ion.
D - Compile error. Mismat ch in declarat ion & definit ion.
Q 36 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
void main()
{
char *s = "C++";
printf("%s ", s);
s++;
printf("%s", s);
}
A - C++ C++
B - C++ ++
C - ++ ++
D - Compile error
Q 37 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
void main()
{
char s[] = "C++";
printf("%s ",s);
s++;
printf("%s",s);
}
A - C++ C++
B - C++ ++
C - ++ ++
D - Compile error
Q 38 - A lo cal variable is sto red in ___
A - Code segment
B - St ack segment
C - Heap segment
D - None of t he above
Q 39 - What is the o utput o f the fo llo wing statement?
#include<stdio.h>
main()
{
printf("%d", -1<<1 );
}
A-2
B - -2
C-1
D - -1
Q 40 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
main()
{
int x = 3;
x += 2;
x =+ 2;
printf("%d", x);
}
A-2
B- 5
C-7
D - Compile error
Q 41 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
main()
{
char *s = "Abc";
while(*s)
printf("%c", *s++);
}
A - Abc
B - bc
C - Compile error
D - Runt ime error
Q 42 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
main()
{
char s[20] = "Hello\0Hi";
printf("%d %d", strlen(s), sizeof(s));
}
A-59
B - 7 20
C - 5 20
D - 8 20
Q 43 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
main()
{
char s[] = "Hello\0Hi";
printf("%d %d", strlen(s), sizeof(s));
}
A-59
B - 7 20
C - 5 20
D - 8 20
Q 44 - What is the o utput o f the fo llo wing statement?
#include<stdio.h>
main()
{
printf("%d", !0<2);
}
A-0
B- 1
C - False
D - True
Q 45 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
main()
{
struct student
{
int num = 10;
}var;
printf("%d", var.num);
}
A - 10
B - Garbage
C - Runt ime error
D - Compile error
Q 46 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
#define sqr(i) i*i
main()
{
printf("%d %d", sqr(3), sqr(3+1));
}
A - 9 16
B- 97
C - Error: macro cannot be defined in lower case.
D - None of t he above.
Q 47 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
main()
{
char *s = "Hello";
while(*s!=NULL)
printf("%c", *s++);
}
A - Hello
B - Helloellolloloo
C - ello
D - Compile error
Q 48 - What is the o utput o f the fo llo wing pro gram?
#include<stdio.h>
main()
{
#undef NULL
char *s = "Hello";
while(*s != NULL)
{
printf("%c", *s++);
}
}
A - Hello
B - Compile error: t here is no macro called undef
C - Compile error: improper place of #undef
D - Compile error: NULL is undeclared.
Q 49 - C is the successo r o f ___ pro gramming language.
A - C++
B - B++
C-B
D - Mini C
Q 50 - Which o f the fo llo wing functio ns disco nnects the stream fro m the file
po inter.
A - fremove()
B - fclose()
C - remove()
D - file point er t o be set t o NULL
ANSWER SHEET
Questio n Number Answer Key
1 B
2 B
3 C
4 D
5 A
6 B
7 A
8 C
9 B
10 C
11 D
12 D
13 C
14 B
15 A
16 D
17 B
18 D
19 B
20 A
21 B
22 C
23 D
24 C
25 B
26 A
27 C
28 A
29 B
30 B
31 D
32 A
33 B
34 C
35 D
36 B
37 D
38 B
39 B
40 A
41 A
42 C
43 A
44 B
45 D
46 B
47 A
48 D
49 C
50 B