C++ syntax check: a reference is declared using which symbol? Select the correct token used in declarations.

Difficulty: Easy

Correct Answer: &

Explanation:


Introduction / Context:
Understanding the basic declaration syntax of references is foundational in C++. This question asks which symbol denotes a reference in a type declaration.



Given Data / Assumptions:

  • We are declaring lvalue references (e.g., int &r).
  • Standard C++ tokens apply.
  • We distinguish between logical operators and reference declarators.



Concept / Approach:
The ampersand '&' in a declaration forms an lvalue reference type: 'T &'. Although '&&' denotes an rvalue reference in type syntax (since C++11), the plain lvalue reference uses a single '&'. The other tokens are logical OR and logical NOT operators, which are unrelated to declaring reference types.



Step-by-Step Solution:
1) Recall examples: 'int &r = x;' binds r to x.2) Distinguish from rvalue references: 'int &&rr = 5;' uses '&&'.3) Recognize that '||' and '!' are not used in type declarations.4) Choose '&' for lvalue references in general declarations.



Verification / Alternative check:
Compile minimal code declaring both lvalue and rvalue references to see the required tokens.



Why Other Options Are Wrong:
'&&': rvalue reference (a different category), not the generic reference symbol asked by the question.'||' / '!': logical operators, not type declarators.



Common Pitfalls:
Forgetting that '&' in expressions is address-of, while in declarations it forms a reference type. Context determines meaning.



Final Answer:
&


More Questions from References

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion