What is the benefit of using a pointer C++ -


this question has answer here:

i confused on part of using pointer on c++.. might say, "a pointer memory adress of variable , there certaintly conditions in program need them". dont mean pointer in general, mean pointer use "simulate" class... think code explain more:

#include <iostream> #include <string> #include "book.h"   int main() {     book book1;     book *bookpointer = &book1;       book1.setbooksid(123);     std::cout << "book id: " << book1.getbookid() << std::endl;      (*bookpointer).setbooksid(300);     std::cout << (*bookpointer).getbookid() << std::endl;      /*when usage of arrow member selection member, left pointer.        same thing above, better practice!       */      bookpointer->setbooksid(100);     std::cout << "pointer arrow  : " << bookpointer->getbookid() << std::endl;     return 0; } 

here see have pointer called bookpointer same original instance of book class book1... dont it.. advantage of using this? give me scenario if can! helping!!

there no "simulation" happening @ all. book1 has address too, , this pointer set address of book1 when book1.setbooksid(123);. there no difference.


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -