I'm happy to post my first question here .
so i was play a little bit with pointers to understand the concept and i found this error
error: invalid conversion from ‘int*’ to ‘int’ [-fpermissive]
here is the code :
#include <iostream>
using namespace std;
int main(){
int* pa,pb,pc,a,b,c;
pa = &a;
cin >> a;
cout <<"the value of a :"<<a<<endl;
cout <<"the value of pointer of a :"<<*pa<<endl;
// the problem begins when reading values of b :
pb = &b; //<== error
cin >> b;
cout << "the value of b : "<<b<<endl;
cout <<"the value of pointer of b" <<*pb<<endl;
return 0;
}
i don't know why it went successfully with variable a but failed with the same syntax in b ?
EDIT : thanks for everyone , i know this question is very simple but i've learned from you :)
The * binds to the variable name, not the type. So what you really want is:
int *pa,*pb,*pc,a,b,c;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With