C Programming Online Quiz


Advertisements


Following quiz provides Multiple Choice Questions (MCQs) related to C Programming Framework. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.

Questions and Answers

Q 1 - What is the output of the following code snippet?

#include<stdio.h>

main() 
{
   short unsigned int i = 0; 
   
   printf("%u\n", i--);
}

A - 0

B - Compile error

C - 65535

D - 32767

Answer : A

Explanation

0, with post decrement operator value of the variable will be considered as the expression’s value and later gets decremented.

Q 2 - The type name/reserved word ‘short’ is ___

A - short long

B - short char

C - short float

D - short int

Answer : D

Explanation

short is used as an alternative of short int.

Q 3 - What is the output of the following program?

#include<stdio.h>

main()
{
   int i = 1;
   
   Charminar:
   printf("%d ",i++);
   if(i==3) break;
   if(i<=5) goto Charminar;
}

A - 1 2

B - 1 2 3

C - 1 2 4 5

D - Compile error

Answer : D

Explanation

Compile error, wrong place for ‘break’ to appear.

Q 4 - What is the output of the following program?

#include<stdio.h>

main() 
{
   char *p = NULL;
   
   printf("%c", *p);
}

A - NULL

B - 0

C - Compile error

D - Runtime error.

Answer : D

Explanation

It is invalid to access the NULL address hence giving run time error.

Q 5 - C is the successor of ___ programming language.

A - C++

B - B++

C - B

D - Mini C

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

Q 7 - 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 8 - In DOS, how many bytes exist for near, far and huge pointers?

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

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

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

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

Answer : C

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 9 - To print a float value which format specifier can be used?

A - %f

B - %lf

C - %Lf

D - None of the above

Answer : A

Explanation

%f can be use to print out float value and %lf can be use to print out  double value.

Q 10 - The library function strrchr() finds the first occurrence of a substring in another string.

A - Yes

B - Strstr()

C - strchr()

D - strnset()

Answer : B

Explanation

Strstr() finds the first occurrence of a substring in another string.


cprogramming_questions_answers.htm

Advertisements
E-Books Store