- C Programming Tutorial
- C - Home
- C - Overview
- C - Features
- C - History
- C - Environment Setup
- C - Program Structure
- C - Hello World
- C - Compilation Process
- C - Comments
- C - Tokens
- C - Keywords
- C - Identifiers
- C - User Input
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Integer Promotions
- C - Constants
- C - Literals
- C - Escape sequences
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - if statement
- C - if...else statement
- C - nested if statements
- C - switch statement
- C - nested switch statements
- C - Loops
- C - While loop
- C - For loop
- C - Do...while loop
- C - Nested loop
- C - Infinite loop
- C - Break Statement
- C - Continue Statement
- C - goto Statement
- C - Functions
- C - Main Functions
- C - Return Statement
- C - Recursion
- C - Scope Rules
- C - Arrays
- C - Properties of Array
- C - Multi-Dimensional Arrays
- C - Passing Arrays to Function
- C - Return Array from Function
- C - Variable Length Arrays
- C - Pointers
- C - Pointer Arithmetics
- C - Passing Pointers to Functions
- C - Strings
- C - Array of Strings
- C - Structures
- C - Structures and Functions
- C - Arrays of Structures
- C - Pointers to Structures
- C - Self-Referential Structures
- C - Nested Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
C Programming Mock Test
This section presents you various set of Mock Tests related to C Programming Framework. You can download these sample mock tests at your local machine and solve offline at your convenience. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself.
C Programming Mock Test II
Q 1 - Linker generates ___ file.
Answer : B
Explanation
(b). Linker links the object code of your program and library code to produce executable.
Q 2 - Compiler generates ___ file.
Answer : B
Explanation
(b). Compilation is the process of translating high level language statements into equivalent machine code, which is object code.
Answer : C
Explanation
The only permitted special symbol is under score (_) in the identifier.
Q 4 - A single line comment in C language source code can begin with _____
Answer : D
Explanation
Two immediate forward slashes are used to comment a single line. A single can be commented by beginning with /* and should be terminated with */ , in general used for multi-line comments.
Answer : A
Explanation
As the code of macro gets expanded at the line of call, therefore macro gets executed faster with no overhead of context switch.
Answer : B
Explanation
volatile is the reserved keyword and cannot be used an identifier name.
Q 7 - Choose the application option for the following program?
#include<stdio.h> main() { int *p, **q; printf("%u\n", sizeof(p)); printf("%u\n", sizeof(q)); }
A - Both the printf() will print the same value
B - First printf() prints the value less than the second.
Answer : A
Explanation
Irrespective of any data type every type of pointer variable occupies same amount of memory.
Q 8 - What is the built in library function to adjust the allocated dynamic memory size.
Answer : C
Explanation
There is no built-in function with the name resize(). Malloc() & calloc() allocates memory but won’t resize.
Answer : B
Explanation
‘cc’ full form is C Compiler and is the compiler for UNIX. gcc is GNU C compiler for linux. Borland and vc++ (Microsoft visual c++) for windows.
Q 10 - Following is the invalid inclusion of a file to the current program. Identify it.
Answer : C
Explanation
option (a) & (b) are valid. There is no such syntax or provision as in option (c).
Q 11 - What is the output of the following program?
#include<stdio.h> int* f() { int x = 5; return &x; } main() { printf("%d", *f()); }
Answer : D
Explanation
It is invalid to return local variable address as the local variable gets removed after the functions execution is completed.
Q 12 - What is the output of the following program?
#include<stdio.h> main() { char *p = NULL; printf("%c", *p); }
Answer : D
Explanation
It is invalid to access the NULL address hence giving run time error.
Q 13 - The default executable generation on UNIX for a C program is ___
Answer : C
Explanation
"a.out" is the default name of the executable generated on both the UNIX and Linux operating systems.
Q 14 - What is the output of the following program?
#include<stdio.h> void f() { static int i = 3; printf("%d ", i); if(--i) f(); } main() { f(); }
Answer : B
Explanation
As the static variable retains its value from the function calls, the recursion happens thrice.
Q 15 - What is the output of the following program?
#include<stdio.h> main() { }
Answer : A
Explanation
It is valid to have main() function empty, therefore producing no displayable output.
Q 16 - Choose the correct option in respect to the following program.
#include<stdio.h> void f(int const i) { i=5; } main() { int x = 10; f(x); }
I - Error in the statement ‘void f(int const i)’
II - Error in the statement i=5.
A - Statements I & II are true
Answer : D
Explanation
We cannot modify a constant as in statement i=5.
Answer : B
Explanation
There is no such data type called ‘string’ in C language.
Q 18 - What is the output of the following program?
#include<stdio.h> int x = 5; int* f() { return &x; } main() { *f() = 10; printf("%d", x); }
Answer : D
Explanation
The returned address is global variables and 10 being stored in it. Therefore x is 10.
Q 19 - What is the output of the below code snippet.
#include<stdio.h> main() { printf("%d", -11%2); }
Answer : B
Explanation
Modulus (%) operator is meant to give reminder for integer division.
Q 20 - An exception is __
Answer : A
Explanation
When the program is in execution phase the possible unavoidable error is called as an exception.
Q 21 - Does both the loops in the following programs prints the correct 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, both the loops prints the correct length
B - Only for loop prints the correct length
Answer : B
Explanation
In while loop ‘i’ gets incremented after checking for ‘\0’, hence giving 1 more than the length.
Q 22 - For the below definition what is the data type of ‘PI’
#define PI 3.141
C - There is no type associated with PI, as it’s just a text substitution
D - Syntax error, semi colon is missing with the definition of PI
Answer : C
Explanation
The text associated with the macro name gets expanded at the line of call. The expanded text is by default a double constant whereas no type is associated with PI.
Q 23 - Choose the invalid predefined macro as per ANSI C.
Answer : D
Explanation
There is no macro define with the name __C++__, but __cplusplus is defined by ANSI)
Q 24 - What is the output of the following program?
#include<stdio.h> main() { int a[] = {10, 20, 30}; printf("%d", *a+1); }
Answer : C
Explanation
*a refers to 10 and adding a 1 to it gives 11.
Q 25 - What is the output of the following program?
#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]); } }
Answer : B
Explanation
Arrays are always passed by reference.
Q 26 - What is the output of the following program?
#include<stdio.h> main() { char *s = "Hello, " "World!"; printf("%s", s); }
Answer : A
Explanation
Two immediate string constant are considered as single string constant.
Q 27 - What is the output of the following program?
#include<stdio.h> main() { fprintf(stdout,"Hello, World!"); }
Answer : C
Explanation
stdout is the identifier declared in the header file stdio.h, need to include the same.
Q 28 - What is the output of the following program?
#include<stdio.h> main() { fprintf(stdout,"Hello, World!"); }
Answer : A
Explanation
stdout is the identifier declared in the header file stdio.h which is connected to standard output device (monitor).
Q 29 - Which of the following is used in mode string to open the file in binary mode?
Answer : B
Explanation
To perform unformatted data I/O a file is opened in binary mode and is represented with the alphabet ‘b’ in the mode string.
Q 30 - What is the output of the following program?
#include<stdio.h> main() { char s[] = "Fine"; *s = 'N'; printf("%s", s); }
Answer : B
Explanation
*s=’N’, changes the character at base address to ‘N’.
Q 31 - What is the output of the following program?
#include<stdio.h> main() { char *s = "Fine"; *s = 'N'; printf("%s", s); }
Answer : D
Explanation
*s=’N’, trying to change the character at base address to ‘N’ of a constant string leads to runtime error.
Q 32 - What is the output of the following program?
#include<stdio.h> main() { int x; float y; y = x = 7.5; printf("x=%d y=%f", x, y); }
Answer : A
Explanation
‘x’ gets the integral value from 7.5 which is 7 and the same is initialized to ‘y’.
Q 33 - What is the built in library function to compare two strings?
Answer : B
Explanation
strcmp() is the built in function from “string.h” to compare two strings. Returns 0 if both are same strings. Returns -1 if first < second string. Returns 1 first > second.
Q 34 - What is the output of the following program?
#include<stdio.h> main() { char s1[50], s2[50] = "Hello"; s1 = s2; printf("%s", s1); }
Answer : C
Explanation
‘s1’ refers to base address and is constant. Hence raising to ‘lvalue’ required compile time error.
Q 35 - What is the output of the following program?
#include<stdio.h> int main(); void main() { printf("Okay"); }
Answer : D
Explanation
It’s compile error as the declaration of main() mismatches with the definition.
Q 36 - What is the output of the following program?
#include<stdio.h> void main() { char *s = "C++"; printf("%s ", s); s++; printf("%s", s); }
Answer : B
Explanation
After s++, s points the string “++”.
Q 37 - What is the output of the following program?
#include<stdio.h> void main() { char s[] = "C++"; printf("%s ",s); s++; printf("%s",s); }
Answer : D
Explanation
‘s’ refers to a constant address and cannot be incremented.
Q 38 - A local variable is stored in ___
Answer : B
Explanation
All the local variables are stored in a memory called as stack.
Q 39 - What is the output of the following statement?
#include<stdio.h> main() { printf("%d", -1<<1 ); }
Answer : B
Explanation
A negative number stored in two’s compliment of positive number. After shifting we get 1110, which is equivalent to -2.
Q 40 - What is the output of the following program?
#include<stdio.h> main() { int x = 3; x += 2; x =+ 2; printf("%d", x); }
Answer : A
Explanation
+ in unary form is dummy operator, therefore ‘x’ is overwritten with the value +2 finally.
Q 41 - What is the output of the following program?
#include<stdio.h> main() { char *s = "Abc"; while(*s) printf("%c", *s++); }
Answer : A
Explanation
Loop continues until *s not equal to ‘\0’, hence printing “Abc” where character is fetched first and address is incremented later.
Q 42 - What is the output of the following program?
#include<stdio.h> main() { char s[20] = "Hello\0Hi"; printf("%d %d", strlen(s), sizeof(s)); }
Answer : C
Explanation
Length of the string is count of character upto ‘\0’. sizeof – reports the size of the array.
Q 43 - What is the output of the following program?
#include<stdio.h> main() { char s[] = "Hello\0Hi"; printf("%d %d", strlen(s), sizeof(s)); }
Answer : A
Explanation
Length of the string is count of character upto ‘\0’. sizeof – reports the size of the array.
Q 44 - What is the output of the following statement?
#include<stdio.h> main() { printf("%d", !0<2); }
Answer : B
Explanation
Priority of ! is greater than <. Relational operator returns 1 if relation between the expressions is true otherwise 0.
Q 45 - What is the output of the following program?
#include<stdio.h> main() { struct student { int num = 10; }var; printf("%d", var.num); }
Answer : D
Explanation
Structure elements cannot be initialized
Q 46 - What is the output of the following program?
#include<stdio.h> #define sqr(i) i*i main() { printf("%d %d", sqr(3), sqr(3+1)); }
Answer : B
Explanation
The equivalent expansion is -> printf("%d %d",3*3,3+1*3+1);
Q 47 - What is the output of the following program?
#include<stdio.h> main() { char *s = "Hello"; while(*s!=NULL) printf("%c", *s++); }
Answer : A
Explanation
NULL is equivalent to ‘\0’ in value. Statement *s++ prints the character first and increments the address later.
Q 48 - What is the output of the following program?
#include<stdio.h> main() { #undef NULL char *s = "Hello"; while(*s != NULL) { printf("%c", *s++); } }
B - Compile error: there is no macro called “undef”
Answer : D
Explanation
NULL is equivalent to ‘\0’ in value. Statement *s++ prints the character first and increments the address later.
Answer : C
Explanation
B is a programming language developed at Bell Labs in 1969. It is derived from BCPL (Basic Combined Programming Language). It is designed by Ken Thompson with Dennis Ritchie.
Q 50 - Which of the following functions disconnects the stream from the file pointer.
Answer : B
Explanation
fclose(), it flushes the buffers associated with the stream and disconnects the stream with the file.
Answer Sheet
Question 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 |