- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Scope resolution operator
The scope resolution operator ( :: ) is used for several reasons. For example: If the global variable name is same as local variable name, the scope resolution operator will be used to call the global variable. It is also used to define a function outside the class and used to access the static variables of class.
Here an example of scope resolution operator in C++ language,
Example
#include <iostream> using namespace std; char a = 'm'; static int b = 50; int main() { char a = 's'; cout << "The static variable : "<< ::b; cout << "\nThe local variable : " << a; cout << "\nThe global variable : " << ::a; return 0; }
Output
Here is the output
The static variable : 50 The local variable : s The global variable : m
Advertisements