0
Can anyone tell me why we need pointer and what will happend if we use it? What is the use of pointer?
2 ответов
+ 7
Ahem Zzzz😪
#include <iostream>
using namespace std;
void changeValue(int *a){
*a = 1;
}
int main(){
int b = 2;
changeValue(&b);//&b give its memory value to this function so value of b was changed
cout << b;
}
What is the result? 2 or 1?
+ 5
we use pointers to "point" to a section of memory that stores our variables data. the pointer allows us to save memory among other things.
we dont need pointers per-se but they are very useful to help keep your program from consuming lots of memory.
someone else may be (easily) able to explain in better detail and expand on the reasons to use pointers and the benefits of doing so.
hope this helps