You can use references.
In C (not C++) pointer is used for many things where in C++ you can avoid it.
Because almost nobody show any examples, here they are:
Suppose following:
// C pass by reference
void doSomething(int *a){
a = 5;
}
same thing in C++
// C++ pass by reference
void doSomething(int &a){
a = 5;
}
another example:
// old C++ pass const object by reference
void doSomething(const Object *o){
o->method();
}
Same can be done using:
// new C++11 pass const object by reference
void doSomething(const Object &o){
o.method();
}
You can do some very trivial things without pointers in C++ but the reality is all languages use pointers but they are hidden from you. Another name for a pointer is an address, which is how the CPU finds things in memory.
To learn C , C++, Java , Data Structure , Python at TCCI
Call us 98256 18292.
Visit us @ http://tccicomputercoaching.com/
In C (not C++) pointer is used for many things where in C++ you can avoid it.
Because almost nobody show any examples, here they are:
Suppose following:
// C pass by reference
void doSomething(int *a){
a = 5;
}
same thing in C++
// C++ pass by reference
void doSomething(int &a){
a = 5;
}
another example:
// old C++ pass const object by reference
void doSomething(const Object *o){
o->method();
}
Same can be done using:
// new C++11 pass const object by reference
void doSomething(const Object &o){
o.method();
}
You can do some very trivial things without pointers in C++ but the reality is all languages use pointers but they are hidden from you. Another name for a pointer is an address, which is how the CPU finds things in memory.
To learn C , C++, Java , Data Structure , Python at TCCI
Call us 98256 18292.
Visit us @ http://tccicomputercoaching.com/
No comments:
Post a Comment