C Programming - Online Quiz



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

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

#include<stdio.h>

main() 
{
   for(;;)printf("Hello");
}

A - Infinite loop

B - Prints Hello once.

C - No output

D - Compile error

Answer : A

Explanation

infinite loop, with second expression of for being absent it is considered as true by default.

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

#include<stdio.h>

main()
{
   int x = 65, *p = &x;
   
   void *q=p;
   char *r=q;
   printf("%c",*r);
}

A - Garbage character.

B - A

C - 65

D - Compile error

Answer : B

Explanation

A, void pointer is a generic pointer and can hold any variables address. ASCII character for the value 65 is A

Answer : B

Explanation

(b). Linker links the object code of your program and library code to produce executable.

Q 4 - Which of the following is used in mode string to open the file in binary mode?

A - a

B - b

C - B

D - bin

Answer : B

Explanation

To perform unformatted data I/O a file is opened in binary mode and is represented with the alphabet b in the mode string.

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

#include<stdio.h>

main()
{ 
   char s1[50], s2[50] = "Hello";
   
   s1 = s2;
   printf("%s", s1);
}

A - Hello

B - No output

C - Compile error

D - Runtime error

Answer : C

Explanation

s1 refers to base address and is constant. Hence raising to lvalue required compile time error.

Q 6 - 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.

Q 7 - Which library function can convert aninteger/longto astring?

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

Answer : A

Explanation

In C library, NULL Macrois the value of a null pointer constant. It may be defined as((void*)0), 0or0Ldepending on the compiler merchant.

Q 9 - What is the role of "r+" on the file "NOTES.TXT" in the given below code?

#include<stdio.h>

int main ()
{
   FILE *fp;
   
   fp = fopen("NOTES.TXT", "r+");
   return 0;
}

A - "r+" open the file "NOTES.TXT" file for reading

B - "r+" open the file "NOTES.TXT" file for writing

C - "r+" open the file "NOTES.TXT" file for appending

D - "r+" open the file "NOTES.TXT" file for reading & writing both

Answer : D

Explanation

fopen() function is used to open a file and r++ enable the file for reading and writing.

#include<stdio.h>

int main ()
{
   FILE *fp;
   
   fp = fopen("NOTES.TXT", "r+");
   return 0;
}

Q 10 - extern int fun(); - The declaration indicates the presence of a global function defined outside the current module or in another file.

A - True

B - False

Answer : A

Explanation

Extern is used to resolve the scope of global identifier.

Advertisements