0

Why removing * producing error?

#include <iostream> using namespace std; void myFunc(int x) { x = 100; } int main() { int var = 20; myFunc(&var); cout << var; }

22nd Mar 2017, 4:03 PM
Shuvam Pal
Shuvam Pal - avatar
5 Answers
+ 1
In C++, Pointer variables are more used for dynamic memory management rather than merely handling references as they do in C language.
22nd Mar 2017, 4:12 PM
देवेंद्र महाजन (Devender)
देवेंद्र महाजन (Devender) - avatar
+ 1
Okay for that question. Sometimes we need work directly on the location where the variable is being store. To access, that address, C++ provide two ways: 1. Pointer Variables 2. Reference Variables.
22nd Mar 2017, 4:21 PM
देवेंद्र महाजन (Devender)
देवेंद्र महाजन (Devender) - avatar
0
I'm lost. So why it's not working 4 int?
22nd Mar 2017, 4:13 PM
Shuvam Pal
Shuvam Pal - avatar
0
The above code needs few changes #include <iostream> using namespace std; void myFunc(int &x) { x = 100; } int main() { int var = 20; myFunc(var); cout << var; }
22nd Mar 2017, 4:13 PM
देवेंद्र महाजन (Devender)
देवेंद्र महाजन (Devender) - avatar
0
Why can't we only use int x. Why */&? And how's this working?
22nd Mar 2017, 4:14 PM
Shuvam Pal
Shuvam Pal - avatar