+ 5
i wanted to know..can we include pointers in the parameters directly..as we use int,double,char,etc..
can someone help me with this.??
2 Antworten
+ 2
#include <iostream>
using namespace std;
void myFunc(int *p) {
*p = *p + 1; // or ++*p
}
int main() {
int n = 5;
myFunc(&n);
cout << n;
return 0;
}
+ 1
Yes we can pass a pointer as a parameter but keep in mind that while calling the function you need to pass the address of the required variable otherwise it would result in garbage