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 - What is the following program doing?

#include<stdio.h>

main()
{
   FILE *stream=fopen("a.txt",'r');
}

A - Trying to open “a.txt” in read mode

B - Trying to open “a.txt” in write mode.

C - “stream” is an invalid identifier

D - Compile error

Answer : D

Explanation

Compile error, second argument for fopen is invalid, should be a string.

Q 3 - A macro can execute faster than a function.

A - true

B - false

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.

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

C - Only while loop prints the correct length

D - Compile error in the program.

Answer : B

Explanation

In while loop ‘i’ gets incremented after checking for ‘\0’, hence giving 1 more than the length.

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.

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

Answer : A

Explanation

randomize() picks the current time value as the SEED number to generate random numbers.

Answer : A

Explanation

Unary operator acts on single expression.

Q 10 - The maximum combined length of the command-line arguments as well as the spaces between adjacent arguments is – a) 120 characters, b) 56 characters, c) Vary from one OS to another

A - a

B - a, b

C - a, b, c

D - c

Answer : D

Explanation

The maximum combined length of the command-line arguments and the spaces between adjacent arguments vary from one OS to another.


cprogramming_questions_answers.htm

Advertisements