250+ TOP MCQs on Constants and Answers

’s MCQs on C helps anyone preparing for placement in TCS and other companies. Anyone looking for TCS placement papers should practice these questions continuously for 2-3 months, thereby ensuring a top position in placements.

Here is a listing of C problems on “Constants” along with answers, explanations and/or solutions:

1. enum types are processed by _________
a) Compiler
b) Preprocessor
c) Linker
d) Assembler
Answer: a
Clarification: None.

2. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         printf("rclassn");
  5.         return 0;
  6.     }

a) class
b)

   
   class

c) classundry
d)
Answer: c
Clarification: r is carriage return and moves the cursor back. sanfo is replaced by class.
Output:
$ cc pgm8.c
$ a.out
classundry

3. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         printf("rnclassn");
  5.         return 0;
  6.     }

a) class
b)

   
   class

c) classundry
d)
Answer: b
Clarification: rn combination makes the cursor move to the next line.
Output:
$ cc pgm9.c
$ a.out

class

4. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         const int p;
  5.         p = 4;
  6.         printf("p is %d", p);
  7.         return 0;
  8.     }

a) p is 4
b) Compile time error
c) Run time error
d) p is followed by a garbage value
Answer: b
Clarification: Since the constant variable has to be declared and defined at the same time, not doing it results in an error.
Output:
$ cc pgm10.c
pgm10.c: In function ‘main’:
pgm10.c:5: error: assignment of read-only variable ‘p’

5. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         int k = 4;
  5.         int *const p = &k;
  6.         int r = 3;
  7.         p = &r;
  8.         printf("%d", p);
  9.     }

a) Address of k
b) Address of r
c) Compile time error
d) Address of k + address of r
Answer: c
Clarification: Since the pointer p is declared to be constant, trying to assign it with a new value results in an error.
Output:
$ cc pgm11.c
pgm11.c: In function ‘main’:
pgm11.c:7: error: assignment of read-only variable ‘p’
pgm11.c:8: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘int * const’

6. Which of the following statement is false?
a) Constant variables need not be defined as they are declared and can be defined later
b) Global constant variables are initialized to zero
c) const keyword is used to define constant values
d) You cannot reassign a value to a constant variable
Answer: a
Clarification: Since the constant variable has to be declared and defined at the same time, not doing it results in an error.

7. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         int const k = 5;
  5.         k++;
  6.         printf("k is %d", k);
  7.     }

a) k is 6
b) Error due to const succeeding int
c) Error, because a constant variable can be changed only twice
d) Error, because a constant variable cannot be changed
Answer: d
Clarification: Constant variable has to be declared and defined at the same time. Trying to change it results in an error.
Output:
$ cc pgm12.c
pgm12.c: In function ‘main’:
pgm12.c:5: error: increment of read-only variable ‘k’

8. What will be the output of the following C code?

  1.     #include 
  2.     int const print()
  3.     {
  4.         printf(".com");
  5.         return 0;
  6.     }
  7.     void main()
  8.     {
  9.         print();
  10.     }

a) Error because function name cannot be preceded by const
b) .com
c) .com is printed infinite times
d) Blank screen, no output
Answer: b
Clarification: None.
Output:
$ cc pgm13.c
$ a.out
.com

  250+ TOP MCQs on Functions Returning Non-integers and Answers

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top