• C Programming Video Tutorials

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.

Questions and Answers

C Programming Mock Test III

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?

A - ceil(5.77)

B - round-off(5.77)

C - round-up(5.77)

D - floor(5.77)

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;
}

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.

A - True

B - False

Answer : A

Explanation

The function definition can even appear in another source code and can be linked from library while linking.

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?

A - * (asterisk)

B - # (Hash)

C - + (Addition)

D - _ (underscore)

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

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;
}

A - 40 AC 00 00

B - 00 00 AC 40

C - 00 00 CA 04

D - None

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;
}

A - #include<defs.h>

B - #include<math.h>

C - #include<stdlib.h>

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?

A - math.h

B - conio.h

C - dos.h

D - stdio.h

Answer : A

Explanation

math.h is a header file in the standard library designed for basic mathematical operations

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; 

}

Q 12 - The binary equivalent of 50 is,

A - 110010

B - 1010110

C - 101

D - 101.011.00.00

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?

A - (float)(3.14)(f)

B - (f)(3.14)

C - 3.14f

D - f(3.14)

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?

A - rem = modf(5.5 % 1.3)

B - rem = modf(5.5, 1.3)

C - rem = fmod(5.5, 1.3)

D - rem = f(5.5, 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.

A - True

B - False

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)?

A - Float, long double

B - long double, short int

C - float, double, long double

D - short int, double, long int, float

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,

A - 3.4E-4932 to 3.4E+4932

B - 3.4E-4932 to 1.1E+4932

C - 4.1E-4932 to 5.1E+4932

D - 0.7E-4932 to 1.8E+4932

Answer : B

Explanation

Explanation: The integral and precession value varies depending upon the number of bytes designated for a particular data type.

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.

A - True

B - False

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?

A - Near: 1, far: 4, huge: 7

B - near: 4, far: 4, huge: 4

C - near: 0, far: 4, huge: 4

D - near: 4, far: 5, huge: 6

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?

A - .

B - %

C - ->

D - #

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],

A - ((((a+m)+n)+o)+p)

B - *(*(*(*(a+i)+j)+k)+2)

C - *( (((a+m)+n)+o+p)

D - *( ((a+m)+n+o+p)

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 24 - Which of the following operator can be used to access value at address stored in a pointer variable?

A - *

B - #

C - &&

D - @

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()?

A - stdlib.h

B - memory.h

C - math.h

D - stdio.h

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()?

A - dealloc();

B - strcat();

C - free();

D - memcpy();

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;
}

A - memfree(int p);

B - free(p);

C - dealloc(p);

D - Both, free(p); & dealloc(p);

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.

A - Yes

B - &&

C - *

D - ||

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?

A - math.h

B - memory.h

C - stdio.h

D - dos.h

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?

A - memalloc()and alloc() 

B - malloc() and memalloc()

C - malloc() and calloc()

D - memalloc() and calloc()

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?

A - stchar()

B - strrchr()

C - strchar() & stchar()

D - strrchar()

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;
}

A - Unlimited times

B - 0 times

C - 300 times

D - 5 times

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;
}

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.

A - Yes

B - Hexadecimal system

C - Octal system

D - Both, Octal & Decimal

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.

Q 35 - Which of the following is a logical operator?

A - !

B - &&

C - ||

D - All of the above

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.

Q 36 - Which of the following is a logical OR operator?

A - &

B - &&

C - ||

D - None of the above

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.

Answer : B

Explanation

It is BODMAS.

Answer : B

Explanation

Standard error stream (Stderr) = Any program use it for error messages and diagnostics issue.

Q 39 - Which of the following is a logical NOT operator?

A - !

B - &&

C - &

D - All of the above

Answer : A

Explanation

Logical NOT operator will make false.

Q 40 - Which library function can convert an integer/long to a string?

A - ltoa()

B - ultoa()

C - sprintf()

D - None of the above

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?

A - remove(var-name);

B - free(var-name);

C - vanish(var-name);

D - erase(var-name);

Answer : B

Explanation

The library function free() deallocates the memory allocated by calloc(), malloc(), or realloc().

Q 42 - Which of the following is a logical AND operator?

A - !

B - &&

C - ||

D - &

Answer : B

Explanation

Two immediate ampersand (&) symbols is logical AND operator.

Q 43 - Which library function can convert an unsigned long to a string?

A - ltoa() 

B - ultoa()

C - system() 

D - unsigned long can’t be converted to a string

Answer : B

Explanation

ultoa() - Convert an unsigned long integer into a string.

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);

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");
}

A - Unlimited times

B - 21 times

C - 0 times

D - 20 times

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?

A - char

B - int

C - float

D - Double

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.

A - Yes

B - Switch

C - go back

D - goto

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;

}

A - Unlimited times

B - 0 times

C - 100 times

D - Till stack run over

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;

}

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
cprogramming_questions_answers.htm
Advertisements