
- C - Home
- C - Overview
- C - Features
- C - History
- C - Standards
- C - Environment Setup
- C - Program Structure
- C - Hello World
- C - Compilation Process
- C - Comments
- C - Basic Syntax
- C - User Input
- C - printf Function
- C - Format Specifiers
- Lexical Elements in C
- C - Tokens
- C - Keywords
- C - Identifiers
- Variables and Constants
- C - Variables
- C - Constants
- C - Const Qualifier
- C - Linkage
- Data Types and Type Conversions
- C - Data Types
- C - Literals
- C - Escape sequences
- C - Booleans
- C - Integer Promotions
- C - Character Arithmetic
- C - Type Conversion
- C - Type Casting
- Operators in C
- C - Operators
- C - Arithmetic Operators
- C - Unary Operators
- C - Relational Operators
- C - Logical Operators
- C - Bitwise Operators
- C - Assignment Operators
- C - Increment and Decrement Operators
- C - Ternary Operator
- C - sizeof Operator
- C - Operator Precedence
- C - Miscellaneous Operators
- Decision Making & Control Statements
- C - Decision Making
- C - if statement
- C - if...else statement
- C - if...else if Ladder
- C - Nested if statements
- C - Switch statement
- C - Nested switch statements
- C - Switch Case Using Range
- Loops in C
- C - Loops
- C - For Loop
- C - While Loop
- C - Do...while Loop
- C - For Loop vs While Loop
- C - Nested Loop
- C - Infinite Loop
- C - Break Statement
- C - Continue Statement
- C - Goto Statement
- Functions in C
- C - Functions
- C - Function Prototype
- C - Main Function
- C - Function call by Value
- C - Function call by reference
- C - Nested Functions
- C - Variadic Functions
- C - User-Defined Functions
- C - Callback Function
- C - Return Statement
- C - Recursion
- C - Predefined Identifier __func__
- Scope Rules in C
- C - Scope Rules
- C - Static Variables
- C - Global Variables
- Arrays in C
- 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 - Dynamic Arrays
- Strings in C
- C - Strings
- C - Array of Strings
- C - Character Arrays
- C - Special Characters
- Structures and Unions in C
- C - Structures
- C - Structures and Functions
- C - Arrays of Structures
- C - Self-Referential Structures
- C - Dot (.) Operator
- C - Lookup Tables
- C - Enumeration (or enum)
- C - Structure Padding and Packing
- C - Nested Structures
- C - Anonymous Structure and Union
- C - Unions
- C - Bit Fields
- C - Typedef
- Pointers in C
- C - Pointers
- C - Pointers and Arrays
- C - Applications of Pointers
- C - Pointer Arithmetics
- C - Array of Pointers
- C - Pointer to Pointer
- C - Function Pointers
- C - Array of Function Pointers
- C - Passing Pointers to Functions
- C - Return Pointer from Functions
- C - Pointer to an Array
- C - Pointers vs. Multi-dimensional Arrays
- C - Character Pointers and Functions
- C - NULL Pointer
- C - void Pointer
- C - Const Pointers & Pointer to Const
- C - Dangling Pointers
- C - Dereference Pointer
- C - Near, Far and Huge Pointers
- C - Restrict Keyword
- C - Pointers to Structures
- C - Chain of Pointers
- C - Pointer vs Array
- C - Initialization of Pointer Arrays
- Storage Classes and Qualifiers
- C - Storage Classes
- Memory Management in C
- C - Memory Management
- C - Memory Address
- Preprocessors in C
- C - Preprocessors
- C - Pragmas
- C - Preprocessor Operators
- File Handling in C
- C - File I/O (File Handling)
- C - Input & Output
- Constants and Literals in C
- C - Macros
- C - Header Files
- Miscellaneous Topics
- C - Error Handling
- C - Variable Arguments
- C - Command Execution
- C - Math Functions
- C - Static Keyword
- C - Random Number Generation
- C - Command Line Arguments
- C Programming Resources
- C - Questions & Answers
- C - Quick Guide
- C - Cheat Sheet
- C - Useful Resources
- C - Discussion
- C Online Compiler
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 III
Q 1 - Choose the correct function which can return a reminder by dividing -10.0/3.0?
Answer : B
Explanation
In the C Programming Language, thefmod() functioncompute and returns the floating-point remainder whenxis divided byy.
#include <math.h> #include <stdio.h> int main( void ) { double x = -10.0, y = 3.0, z; z = fmod( x, y ); printf( "The remainder of %.2f / %.2f is %f\n", w, x, z ); }
Q 2 - How to round-off a value 5.77 to 6.0?
Answer : A
Explanation
ceil( ) function in C returns nearest integer value which is greater than or equal tothe argument passed to thefunction.
#include <math.h> #include <stdio.h> int main() { float x=5.77; printf("ceil of %f is %f\n", x, ceil(x)); return 0; }
Q 3 - The prototype of a function can be used to,
Answer : B
Explanation
Prototype of a function can be used to declare a function. It is necessary in order to provide information (return type, parameter list and function name, etc) about the function to the compiler.
Q 4 - int fun();- The declaration indicates the presence of a function defined inside the current module or in the same file.
Answer : A
Explanation
The function definition can even appear in another source code and can be linked from library while linking.
Q 5 - The types of linkages are,
A - Internal linkage and External linkage
B - Internal linkage, External linkage and None linkage
Answer : B
Explanation
- External Linkage-> A global, non-static variables and functions.
- Internal Linkage-> A static variables and functions with file scope.
- None Linkage-> A Local variables.
Q 6 - A Variable name in C includes which special symbols?
Answer : D
Explanation
Characters which are allowed and not allowed with variable name,
- Underscore(_) allowed
- Capital Letters ( A Z ) allowed
- Small Letters ( a z ) allowed
- Digits ( 0 9 ) allowed
- First Charactershould bealphabet or Underscore
- Blanks & Commasnot allowed
- Special Symbols not allowed, but Underscore(_)allowed
- Reserved Word not allowed
Q 7 - How do you specify double constant 3.14 as along double?
Answer : B
Explanation
The doubleconstant3.14can be convertedinto long double by adding L after the constant value, i.e;3.14L.
Q 8 - In normalized form, if the binary equivalent of 5.375 is 0100 0000 1010 1100 0000 0000 0000 0000 then what will be the output of the program in Intel core machine?
#include<stdio.h> #include<math.h> int main () { float a = 5.375; char *p; int i; p = (char*)&a; for(i=0; i <= 3; i++) printf("%02x\n", (unsigned char)p[i]); return 0; }
Answer : B
Explanation
Depends upon the machine whether its big endian or small endian machine. Byte by byte is fetched from right end.
#include<stdio.h> #include<math.h> int main () { float a = 5.375; char *p; int i; p = (char*)&a; for(i=0; i <= 3; i++) printf("%02x\n", (unsigned char)p[i]); return 0; }
Q 9 - Which header statement is missing in the given below program to get the desired output?
#include<stdio.h> #include<math.h> int main () { double x = 1234321; double result = sqrt(x); printf("The square root of %.2lf is %.2lf\n", x, result); return 0; }
D - Above program is absolutely correct to give desired result
Answer : B
Explanation
In C programming, math.his a header file in the standard library designed for basic mathematical operations.
Output of above code: The square root of 1234321.00 is 1111.00
#include<stdio.h> #include<math.h> int main () { double x = 1234321; double result = sqrt(x); printf("The square root of %.2lf is %.2lf\n", x, result); return 0; }
Q 10 - In the standard library of C programming language, which of the following header file is designed for basic mathematical operations?
Answer : A
Explanation
math.his a header file in the standard library designed for basic mathematical operations
Q 11 - Choose the correct program that round offx value (afloat value) to anintvalue to return the output value 4,
A - float x = 3.6;
int y = (int)(x + 0.5); printf ("Result = %d\n", y );
B - float x = 3.6;
int y = int(x + 0.5); printf ("Result = %d\n", y );
C - float x = 3.6;
int y = (int)x + 0.5 printf ("Result = %d\n", y );
D - float x = 3.6;
int y = (int)((int)x + 0.5) printf ("Result = %d\n", y );
Answer : A
Explanation
#include <math.h> #include <stdio.h> int main() { float x = 3.6; int y = (int)(x + 0.5); printf ("Result = %d\n", y ); return 0; }
Answer : A
Explanation
#include <stdio.h> int main() { longintdecimalNumber,remainder,quotient; intbinaryNumber[100], i = 1, j; printf("Enter any decimal number: "); scanf("%ld",&decimalNumber); quotient = decimalNumber; while(quotient!=0){ binaryNumber[i++]= quotient % 2; quotient = quotient / 2; } printf("Equivalent binary value of decimal number %d: ",decimalNumber); for(j = i -1 ;j> 0;j--) printf("%d",binaryNumber[j]); return0; }
Q 13 - Where to place f with a double constant 3.14 to specify it as afloat?
Answer : C
Explanation
A floating-point constant without anf,F,l, orLsuffix has typedouble. If the letterforFis the suffix, the constant has typefloat. If suffixed by the letterlorL, it has typelong double.
Q 14 - Choose the correct statement that can retrieve the remainder of the division 5.5 by 1.3?
Answer : C
Explanation
A floating-point constant without anf,F,l, orLsuffix has typedouble. If the letterforFis the suffix, the constant has typefloat. If suffixed by the letterlorL, it has typelong double.
Q 15 - In C programming language, a function prototype is a declaration of the function that just specifies the functions interface (function's name, argument types and return type) and extracts the body of the function. By defining the function, we get to know what action a particular function is going to perform.
Answer : A
Explanation
Explanation: The function body shall associate a specific task, hence representing the action.
Q 16 - In C, what are the various types of real data type (floating point data type)?
Answer : C
Explanation
There are three types of floating point data type = 1) float with storage size 4 byte, 2) double with storage size 8 byte, and 3) long double with storage size 10 byte.
Q 17 - Turbo C in 16 bit DOS OS, the correct range of long double is,
Answer : B
Explanation
Explanation: The integral and precession value varies depending upon the number of bytes designated for a particular data type.
Q 18 - What is (void*)0?
A - Symbolize the NULL pointer
B - Symbolize the void pointer
Answer : A
Explanation
In C programming, NULL indicates the value 0 of a pointer, which means; pointer that initializes with NULL value considered as NULL pointer.
Q 19 - The C library functionrewind()reposition the file pointer at the beginning of the file.
Answer : A
Explanation
void rewind(FILE *stream): In C, therewind functionreposition the file position to the beginning of the file of the givenstream. It also erases the error and end-of-file indicators forstream.
Q 20 - In Windows & Linux, how many bytes exist fornear, farandhugepointers?
Answer : B
Explanation
In DOS, numbers of byte exist for near pointer = 2,far pointer = 4andhuge pointer = 4.
In Windows and Linux, numbers of byte exist for near pointer = 4,far pointer = 4andhuge pointer = 4.
Q 21 - For a structure, if a variable behave as a pointer then from the given below operators which operator can be used to access data of the structure via the variable pointer?
Answer : C
Explanation
For a structure, Dot(.) operator can be used to access the data using normal structure variable and arrow (->)can be used to access the data using pointer variable.
Q 22 - The equivalent pointer expression by using the array elementa[i][j][k][2],
Answer : B
Explanation
If, the array elementis a[i][j] = *(*(a+i)+j)
If, the array elementis a[i][j][k]= *(*(*(a+i)+j)+k)
Q 23 - What is a pointer?
A - A keyword used to create variables
B - A variable used to store address of an instruction
Answer : C
Explanation
Ifvaris a variable then&varis an address in memory.
Q 24 - Which of the following operator can be used to access value at address stored in a pointer variable?
Answer : A
Explanation
Pointer operator,
* (Value Operator) = Gives Value stored at Particular address
& (Address Operator) = Gives Address of Variable
Q 25 - Which header file supports the functions -malloc()andcalloc()?
Answer : A
Explanation
void *malloc(size_t size) : Allocates the requested memory and returns a pointer to it.
void *calloc(size_t nitems, size_t size): Allocates the requested memory and returns a pointer to it.
Q 26 - What function can be used to free the memory allocated bycalloc()?
Answer : C
Explanation
calloc(): Allocates space for an array elements, initializes to zero and then returns a pointer to memory.
Free(): Dellocate the space allocated by calloc()
Q 27 - The given below program allocates the memory, what function will you use to free the allocated memory?
#include<stdio.h> #include<stdlib.h> #define MAXROW 4 # define MAXCOL 5 int main () { int **p, i, j p = (int **) malloc(MAXROW * sizeof(int*)); return 0; }
Answer : B
Explanation
free() is the function in C language to release the allocated memory by any dynamic memory allocating built in library function.
#include<stdio.h> #include<stdlib.h> #define MAXROW 4 # define MAXCOL 5 int main () { int **p, i, j p = (int **) malloc(MAXROW * sizeof(int*)); return 0; }
Q 28 - A bitwise operator & can turn-off a particular bit into a number.
Answer : A
Explanation
The bitwise AND operator & compares each bit of the first operand with the corresponding bit of the second operand. During comparison, if both operands bits are 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0.
Q 29 - Which header file can be used to define input/output function prototypes and macros?
Answer : C
Explanation
Thestdio.hheader is used to define variable types, macros, and various functions for performing input and output operation.
Q 30 - Which library functions help users to dynamically allocate memory?
Answer : C
Explanation
malloc():Allocates an area of memory that is large enough to hold "n number of bytes and initializes contents of memory to zeroes.
calloc(): Allocates "size" of bytes of memory and contains garbage values.
Q 31 - Which standard library function can return a pointer to the last occurrence of a character in a string?
Answer : B
Explanation
The strrchr() function finds string for the last occurrence of a character and place the pointer to the last occurrence of character.
Q 32 - In the given below code, if ashort intvalue is 5 byte long, then how many times thewhileloop will get executed?
#include<stdio.h> int main () { int j = 1; while(j <= 300) { printf("%c %d\n", j, j); j++; } return 0; }
Answer : C
Explanation
Ifwhile(j <= 300),then whatever the size short int value, the while loop condition will execute until j value becomes 300.
#include<stdio.h> int main () { int j = 1; while(j <= 300) { printf("%c %d\n", j, j); j++; } return 0; }
Q 33 - Similarity between a structure, union and enumeration,
A - All are helpful in defining new variables
B - All are helpful in defining new data types
Answer : B
Explanation
A structure, union and enumeration all of them can define a new data type.
Q 34 - In Decimal system you can convert the binary number1011011111000101very easily.
Answer : B
Explanation
Hexadecimal is also known ashexorbase 16. It is a system help in writing and presenting numerical values. Binary(base 2) is a popular numeral system (represent numbers by just two digit values 0 and 1), used to present the language of computers. Hexadecimal system can easily convert those numbers.
Answer : D
Explanation
&& = Called Logical AND operator. If both the operands are non-zero, then condition becomes true.
|| = Called Logical OR Operator. If any of the two operands is non-zero, then condition becomes true.
! = Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then
Logical NOT operator will make false.
Answer : C
Explanation
&& = Called Logical AND operator. If both the operands are non-zero, then condition becomes true.
|| = Called Logical OR Operator. If any of the two operands is non-zero, then condition becomes true.
! = Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then
Logical NOT operator will make false.
Q 37 - The correct order of mathematical operators in mathematics and computer programming,
A - Addition, Subtraction, Multiplication, Division
B - Division, Multiplication, Addition, Subtraction
Answer : B
Explanation
It is BODMAS.
Q 38 - Stderr is a standard error.
Answer : B
Explanation
Standard errorstream (Stderr) = Any program use it for error messages and diagnostics issue.
Answer : A
Explanation
Logical NOT operator will make false.
Q 40 - Which library function can convert aninteger/longto astring?
Answer : A
Explanation
In C, ltoa() function converts long/integer data type to string data type.
char *ltoa(long N, char *str, int base);
Q 41 - Which of the following statement can be used to free the allocated memory?
Answer : B
Explanation
The library functionfree()deallocates the memory allocated by calloc(), malloc(), or realloc().
Answer : B
Explanation
Two immediate ampersand (&) symbols is logical AND operator.
Q 43 - Which library function can convert an unsigned long to astring?
Answer : B
Explanation
ultoa() - Convert an unsigned long integer into a string.
Q 44 - Why to usefflush()library function?
A - To flush all streams and specified streams
B - To flush only specified stream
Answer : A
Explanation
In C programming, thefflush() functionwrites any unwritten data instream'sbuffer. If, streamis a null pointer, fflush() function will flush all streams with unwritten data in the buffer.
int fflush(FILE *stream);
Q 45 - In DOS, What is the purpose of the functionrandomize()in Turbo C?
A - Displays a random number generator with a random value based on time
C - Displays a random number generator in the specified range.
Answer : A
Explanation
randomize() picks the current time value as the SEED number to generate random numbers.
Q 46 - How many times the given below program will print "India"?
#include<stdio.h> int main () { int x; for(x=-1; x<=20; x++)int i; { if(x < 10) continue; else break; printf("India"); }
Answer : C
Explanation
Following for loop there is only one statement, that is int i; break & continue are appearing out side for block which is compile error
#include<stdio.h> int main () { int x; for(x=-1; x<=20; x++)int i; { if(x < 10) continue; else break; printf("India"); }
Q 47 - Which of the following variable cannot be used byswitch-casestatement?
Answer : C
Explanation
Switch Case only accepts integer values for case label, float values cant be accepted in case of Switch Case.
#include<stdio.h> int main () { i = 1.8 switch ( i ) { case 1.6: printf ("Case 1.6"); break; case 1.7: printf ("Case 1.7"); break; case 1.8: printf ("Case 1.8"); break; default : printf ("Default Case "); } }
Q 48 - The return keyword used to transfer control from a function back to the calling function.
Answer : A
Explanation
In C, thereturnfunction stops the execution of a function and returns control with value to the calling function. Execution begins in the calling function by instantly following the call.
Q 49 - How many times the given below program will print "IndiaPIN"?
#include<stdio.h> int main () { printf("IndiaPIN"); main(); return 0; }
Answer : D
Explanation
Astack over flowcomes when over loaded memory is used by the call stack. Here, main()functionis called repeatedly and its return address stores in the stack. When stack memory get filled, it displays the error stack overflow.
#include<stdio.h> int main () { printf("IndiaPIN"); main(); return 0; }
Q 50 - What do you mean by int (*ptr)[10]
A - ptris an array of pointers to 10 integers
B - ptris a pointer to an array of 10 integers
Answer : B
Explanation
Explanation: with or without the brackets surrounding the *p, still the declaration says its an array of pointer to integers.
Answer Sheet
Question Number | Answer Key |
---|---|
1 | B |
2 | A |
3 | B |
4 | A |
5 | B |
6 | D |
7 | B |
8 | B |
9 | B |
10 | A |
11 | A |
12 | A |
13 | C |
14 | C |
15 | A |
16 | C |
17 | B |
18 | A |
19 | A |
20 | B |
21 | C |
22 | B |
23 | C |
24 | A |
25 | A |
26 | C |
27 | B |
28 | A |
29 | C |
30 | C |
31 | B |
32 | C |
33 | B |
34 | B |
35 | D |
36 | C |
37 | B |
38 | B |
39 | A |
40 | A |
41 | B |
42 | B |
43 | B |
44 | A |
45 | A |
46 | C |
47 | C |
48 | A |
49 | D |
50 | B |