(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
MYPROGRAMMINGLAB WITH PEARSON ETEXT
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)
- Define the term " pointer relational operators " .arrow_forwardProgramming Language: C++ 4. Select the two correct statements about stub functions: Select one or more: a. stubs are used to test the functionality of a program b. stubs must return a value c. stubs are programs that test if a called function returns the correct result d. stubs are simpler than the functions they replacearrow_forwardDescribe how to declare and manipulate pointer variables.arrow_forward
- Define term operator and operand. Explain different operator used in C programming.arrow_forward/* Programming concept: structures Program should: be a C program, define a structure to store the year, month, day, and high temperature. write a function get_data that has a parameter that is a pointer to a struct and reads from the user into the struct pointed to by the parameter. write a function print_data that takes the struct pointer as a parameter and prints the data. in main, declare a struct, call the get_data function, call the print_data function. */ #include <stdio.h> int main(int argc, char *argv[]) { return 0;}arrow_forwardDefine the term " operator assignment " .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