LearnFrenzy
Sign in Take a free test

Functions and Default Arguments · Functions MCQ · Question 4

Can a literal be passed to an int& parameter? Answer, explanation & discussion

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

Given void inc(int& x);, which call is valid?

  • A inc(5);
  • B int n = 5; inc(n); Correct
  • C inc(n + 1);
  • D inc(5.0);
Correct Answer: Option B

A non-const lvalue reference binds only to a modifiable variable. Literals and expression results are temporaries; they bind to const int& but not int&.

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