LearnFrenzy
Sign in Take a free test

Basic Syntax and Data Types · Basic Syntax MCQ · Question 6

What does int x{7.9}; do? Answer, explanation & discussion

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

What happens with int x{7.9};?

  • A x becomes 7
  • B x becomes 8
  • C Compilation error: narrowing conversion from double to int Correct
  • D x becomes 0
Correct Answer: Option C

Brace initialization forbids narrowing conversions. int x = 7.9; would compile (with a warning) and store 7.

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