- 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 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, the fmod() function compute and returns the floating-point remainder when x is divided by y.
#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 to the 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 Character should be alphabet or Underscore
- Blanks & Commas not allowed
- Special Symbols not allowed, but Underscore(_)allowed
- Reserved Word not allowed
Q 7 - How do you specify double constant 3.14 as a long double?
Answer : B
Explanation
The double constant 3.14 can be converted into 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.h is 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.h is a header file in the standard library designed for basic mathematical operations
Q 11 - Choose the correct program that round off x value (a float value) to an int value 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() { long int decimalNumber,remainder,quotient; int binaryNumber[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]); return 0; }
Q 13 - Where to place “f” with a double constant 3.14 to specify it as a float?
Answer : C
Explanation
A floating-point constant without an f, F, l, or L suffix has type double. If the letter f or F is the suffix, the constant has type float. If suffixed by the letter l or L, it has type long 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 an f, F, l, or L suffix has type double. If the letter f or F is the suffix, the constant has type float. If suffixed by the letter l or L, it has type long double.
Q 15 - In C programming language, a function prototype is a declaration of the function that just specifies the function’s 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 function rewind() reposition the file pointer at the beginning of the file.
Answer : A
Explanation
void rewind(FILE *stream): In C, the rewind function reposition the file position to the beginning of the file of the given stream. It also erases the error and end-of-file indicators for stream.
Q 20 - In Windows & Linux, how many bytes exist for near, far and huge pointers?
Answer : B
Explanation
In DOS, numbers of byte exist for near pointer = 2, far pointer = 4 and huge pointer = 4.
In Windows and Linux, numbers of byte exist for near pointer = 4, far pointer = 4 and huge 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 element a[i][j][k][2],
Answer : B
Explanation
If, the array element is a[i][j] = *(*(a+i)+j)
If, the array element is 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
If var is a variable then &var is 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() and calloc()?
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 by calloc()?
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
The stdio.h header 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 a short int value is 5 byte long, then how many times the while loop 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
If while(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 number 1011011111000101 very easily.
Answer : B
Explanation
Hexadecimal is also known as hex or base 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 error stream (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 an integer/long to a string?
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 function free() 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 a string?
Answer : B
Explanation
ultoa() - Convert an unsigned long integer into a string.
Q 44 - Why to use fflush() library function?
A - To flush all streams and specified streams
B - To flush only specified stream
Answer : A
Explanation
In C programming, the fflush() function writes any unwritten data in stream's buffer. If, stream is 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 function randomize() 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 by switch-case statement?
Answer : C
Explanation
Switch Case only accepts integer values for case label, float values can’t 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, the return function 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
A stack over flow comes when over loaded memory is used by the call stack. Here, main()function is 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 - ptr is an array of pointers to 10 integers
B - ptr is a pointer to an array of 10 integers
Answer : B
Explanation
Explanation: with or without the brackets surrounding the *p, still the declaration says it’s 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 |