0

C++ POINTERS

Hi, I wanted to ask a couple of questions about some things I didn't understand about pointers in c ++. 1) What are they for, and if you can give me examples of programs, where pointers are necessary; 2) If they are useful in 2020; 3) When for example in the C ++ code I declare a variable like *p = &a. This contains the memory address of the variable 'a', and I wanted to know if this address (I HAVE USED VISUAL STUDIO), is that of the memory of my computer or one chosen at random from visual studio; I sincerely thank anyone who will help me solve this problem

19th Dec 2020, 8:40 PM
Hammad Yaqub
Hammad Yaqub - avatar
3 odpowiedzi
+ 3
For example, if we are making dynamic array, and we want user to declare size of it int a; cin >> a; int tab[a]; Code above will result in error. We need to use pointer instead of tab[a] like this: int * tab = new int[a] ; There are plenty of examples on how useful pointers are, you can just type in browser for "pointers usage"
19th Dec 2020, 10:23 PM
Michal Doruch
+ 2
pointer is a base in c++. they are used everywhere!!!
19th Dec 2020, 9:18 PM
george
george - avatar
+ 1
ok thanks
19th Dec 2020, 10:39 PM
Hammad Yaqub
Hammad Yaqub - avatar