Operators in C++

Unit 1 Β· Topic 1.8⏱ 8 min read❓ 5 MCQs

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

  1. What is :: ?
  2. Name new operators in C++.
  3. What is typeid?
  4. Difference between . and ::?

Long Questions

  1. Explain scope resolution operator.
  2. 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.