Hey guys

-----------------
Truck t;

Car c;

Vehicle *broom = &c;

broom->drive();

broom = &t;

broom->drive();

-----------------

by saying Vehicle *broom = &c; what do you actually do ? what it means?

*broom is a pointer located on c's adress in memory ? Is that right?

thanks

Recommended Answers

All 2 Replies

Right. I infer that you've inherited class car from the base class vehicle.

*broom is a pointer located on c's adress in memory ? Is that right?

Broom is a pointer pointing to c's adress in the memory.

Take this example.

Lets say address of c be 0x8000 and address of broom be 0x5000. If you go and read 4 bytes at 0x5000 you will find 0x8000 written.

A pointer is like a address board of your house. It stors address you can read address and reach to right location.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.