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; }
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.
+ 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.
0
I'm lost. So why it's not working 4 int?
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;
}
0
Why can't we only use int x. Why */&? And how's this working?