Operators in C++
Introduction
C++ has all C operators plus new ones: scope resolution ::, insertion/extraction <</>>, new/delete, manipulators.
Definition
Scope resolution :: accesses global/hidden variables and class members.
Code Example
#include <iostream>
using namespace std;
int x=10;
int main(){
int x=20;
cout<<x<<endl; // 20
cout<<::x<<endl; // 10 (global)
return 0;
}Important Questions
Short Questions
- What is :: ?
- Name new operators in C++.
- What is typeid?
- Difference between . and ::?
Long Questions
- Explain scope resolution operator.
- List C++ specific operators.
MCQ Practice
1. :: is:
- Scope resolution
- Insertion
- Extraction
- Pointer
Answer: scope resolution.
2. new is:
- Operator
- Function
- Macro
- Keyword only
Answer: operator.
3. << in C++ is:
- Insertion operator
- Left shift only
- Scope
- Pointer
Answer: insertion.
4. C++ operators include all C operators:
- True
- False
- Only arithmetic
- None
Answer: true.
5. :: can access:
- Global variable
- Only locals
- Nothing
- Only classes
Answer: global variable.
Quick Revision
- C++ adds ::, new/delete, <</>>.
- :: resolves scope.