Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

invalid pointer conversion C++

Tags:

c++

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 :)

like image 828
Iheb Avatar asked May 09 '26 07:05

Iheb


1 Answers

The * binds to the variable name, not the type. So what you really want is:

int *pa,*pb,*pc,a,b,c;
like image 107
Mark Ransom Avatar answered May 11 '26 22:05

Mark Ransom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!