LearnFrenzy
Sign in Take a free test

C Const · const MCQ · Question 3

Can a const local be initialised at run time? Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 3 Back to Exercise

Is const double pi = acos(-1.0); valid inside a function?

  • A No, const needs a literal
  • B Yes – a const local may be initialised with any expression and is read-only afterwards Correct
  • C Only with static
  • D Only in C23
Correct Answer: Option B

const means "not modified after initialisation", not "known at compile time". Only objects with static storage (globals, static locals) need constant initializers.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links