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

#include<stdio.h>

main()
{	
    register int x = 5;

    int *p;
    p=&x;
    x++;
    printf("%d",*p);
}

A - Compile error

B - 5

C - 6

D - Garbage value

Answer : A

Explanation

Compile error, we cannot take the address of a register variable.

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

#include<stdio.h>

main()
{ 
   struct { int x;} var = {5}, *p = &var;
   
   printf("%d %d %d",var.x,p->x,(*p).x); 
}

A - 5 5 5

B - 5 5 garbage value

C - 5 5 0

D - Compile error

Answer : A

Explanation

5 5 5, the two possible ways of accessing structure elements using pointer is by using -> (arrow operator) OR *.

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

#include<stdio.h>

main()
{ 
   int a[3] = {2,,1};
   
   printf("%d", a[a[0]]); 
}

A - 0

B - 1

C - 2

D - Compile error

Answer : D

Explanation

Compile error, invalid syntax in initializing the array.

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

#include<stdio.h>

main()
{	
   fprintf(stdout,"Hello, World!");
}

A - Hello, World!

B - No output

C - Compile error

D - Runtime error

Answer : A

Explanation

stdout is the identifier declared in the header file stdio.h which is connected to standard output device (monitor).

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 - 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 - 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 8 - In the following code, what is 'P'?

   Typedef char *charp;
   
   const charp P;

A - P is a constant

B - P is a character type

C - P is a pointer

D - None of the above

Answer : A

Explanation

Const charp P;

Although, the code itself indicates the keyword "const", so that; P is a constant.

Q 9 - In the given below code, what will be return by the function get ()?

#include<stdio.h>

int get();

int main()

{
   const int x = get();
   
   printf("%d", x);
   return 0;
}
   int get()
   {
    return 40;
}

A - 40

B - 20

C - 0

D - Error

Answer : A

Explanation

Firstly, “int get()” which is a get() function prototype returns an integer value without any parameters.

Secondly, const int x = get(); The constant variable x is declared as an integer data type and initialized with the value of get(). Hence, the value of get() is 40, printf("%d", x); will print the value of x, that means; 40. So, the program output will be 40.

#include<stdio.h>

int get();

int main()

{
   const int x = get();
   
   printf("%d", x);
   return 0;
}
   int get()
   {
    return 40;
}

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.


cprogramming_questions_answers.htm

Advertisements