46.6k views
1 vote
Assume you are given a variable x below:

int x = 10;

Create a pointer and save the memory address the variable x to the pointer:

Answer:

4.) You are given a class below, create a accessor and mutator function for field age.

class Student

{

public:

string name;

private:

int age;

}

User Catrinel
by
4.5k points

1 Answer

2 votes

Answer:

int x=10;

int *p=&x;

4)

class Student

{

public:

string name;

private:

int age;

public:

int accessor() //accessor

{

return age;

}

void mutator(int value) //mutator function.

{

age=value;

return;

}

}

Step-by-step explanation:

The above written statement creates a pointer of name p.Then the address of variable x is stored in the pointer p and it is done by using the & referencing operator.By doing this the address of the variable x is stored in pointer p.

In the next question two public functions are created with the names accessor and mutator respectively.Accessor function are used to access private values in the class and the Mutators are used to set the prviate values.That is what the accessor and mutator function is doing in the class.

User Onlyf
by
5.2k points