473,213 views
38 votes
38 votes
Given the following class definition and the variable declaration:

class employee
char *name;
long id; }
class manager {
employee empl;
char* rank; } x

Which of the following assignment statement is correct?

a. x.empl->id = 12345;
b. x.id = 12345;
c. x->id = 12345;
d. x.empl.id = 12345;

User Aliton Oliveira
by
2.5k points

1 Answer

16 votes
16 votes

Answer:

The answer is "Option d".

Step-by-step explanation:

In the above-given code, two-class is defined that is "employee and manager", in which the first class "employee" defines two variables that are "name, id". In this name is pointer type character and id is a long type variable.

In the second class "manager" one variable "rank" and the employee object is created. In this class, the rank variable is a pointer type character, and outside this class, a reference "x" is created.

In this code, we use both class object that uses the "employee" class variable that is id to hold value in it.

User Amit Vujic
by
3.1k points