HSC Science (Computer Science) 12th Board ExamMaharashtra State Board
Share
Notifications

View all notifications

Explain the use of Scope resolution Operator and Memory Management Operators in C++ with examples . - HSC Science (Computer Science) 12th Board Exam - Computer Science 1

Login
Create free account


      Forgot password?

Question

Explain the use of Scope resolution Operator and Memory Management Operators in C++ with examples .

Solution

Use of Scope resolution Operator ( :: )
The scope resolution operator (::) is used to access the data of global version of variable. C++ is a block-structured language. Different  blocks can be used in a program. The same variable name can be used in different blocks with different values. They are stored at  different memory locations.

Example:
#include<iostream.h>
void main( )
{
int a=10; // local to main
cout<<“a=”<<a; // a=10
{
int a=25; // local to inner block
cout<<a;// a=25
cout<<::a; // a=10 outer block variable is accessed
}
}

Use of memory management operator : new and delete
The new operator is used to create objects of any type. The syntax is as follows:

Pointer_variable = new data type;

Example : p = new int; // p is pointer of type int .
The delete operator is used to destroy the variable from the  memory space so that the same space can be used for another use. The syntax of delete is as follows: 

delete pointer variable;
Example: delete p; // delete pointer variable p from memory.

  Is there an error in this question or solution?

APPEARS IN

 2016-2017 (March) (with solutions)
Question 4.2.2 | 4.00 marks
Solution Explain the use of Scope resolution Operator and Memory Management Operators in C++ with examples . Concept: C++ Programming.
S
View in app×