(Scope Resolution Operator) What’s the purpose of the scope resolution operator?
To write the purpose of the scope resolution operator.
Explanation of Solution
The scope resolution operator is mainly used in C++ and it is denoted by double colon (: :).
Suppose in a program, there are two variables one local variable and another global variable with the same name, now if there is a need to access the global variables, scope resolution operator (: :) operator will be used. Thus it is used in order to differentiate the member functions of the class and the normal functions of the class.
The main purpose of the scope resolution operator is to identify and specify the context of an identifier. It defines the already declared member in .h extension or .cpp header files of the particular class.
Example program to describe the purpose of Scope Resolution Operator (: :)
#include<iostream> usingnamespacestd; /*initialize a global variable*/ int a=10; intmain() { /*initialize the local variable with the same name*/ int a=15; /*print the global variable using scope resolution operator*/ cout<<"The global variable is: "<<::a<<endl; /*print the local variable*/ cout<<"The local variable is: "<<a<<endl; return0; }
Output:
The global variable is: 10
The local variable is: 15
Want to see more full solutions like this?
Chapter 17 Solutions
C How to Program (8th Edition)
Additional Engineering Textbook Solutions
Starting Out with Java: From Control Structures through Objects (6th Edition)
Differential Equations: Computing and Modeling (5th Edition), Edwards, Penney & Calvis
Introduction to Programming Using Visual Basic (10th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Absolute Java (6th Edition)
- - Pure Javascript in console- Use camelCase- use functions to call each case- all cases must be user inputarrow_forwardHi Please help When I try to call the given_name function from the main, my error says "use of undeclared identifier given_name" even though I already included the proper librariesarrow_forward-use loops and functions -Separate the implementation file from the definition file and header filearrow_forward
- Could you write the function comment. Please explain what the function does step-by-step. Thanks!arrow_forwardSubject : numerical methods Please write the code in c++. Provide code in text format so that I can run. Explain in detail.arrow_forwardWhy is it OK for a function to sometimes produce side effects?arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education