Hello all,
Im starting to play around with pointers in c++, i made a little program to see how pointers work. I cant seem to compile the code. it gives me error. can anyone take a look at the code that i included and see if i left anything out?
1st error - error C2440: '=' : cannot convert from 'int *' to 'int'
2nd error - error C2100: illegal indirection
#include <iostream.h>
int main()
{
int x;
x = 10;
cout << "x = " << x << '\n' <<endl;
int *p;
p= new int(10);
cout << "P = " << *p << endl;
int* p1,p2;
p1= new int;
*p1 = 42;
p2 = p1; // first error is here.
cout << "*p1 = " << *p1 << endl;
cout << "*p2 = " << *p2 << endl; //2nd type of error C2100: illegal indirection error here i dunno why =|
*p2 = 53; // 2nd type error here also
cout << "*p1 = " << *p1 << endl;
cout << "*p2 = " << *p2 << endl; // 2nd type error here also.
p1 = new int;
*p1 = 88;
cout << "*p1 = " << *p1 << endl;
cout << "*p2 = " << *p2 << endl; // 2nd error here also
return 0;
}
any help or comments would be great!
thanks
laura
Im starting to play around with pointers in c++, i made a little program to see how pointers work. I cant seem to compile the code. it gives me error. can anyone take a look at the code that i included and see if i left anything out?
1st error - error C2440: '=' : cannot convert from 'int *' to 'int'
2nd error - error C2100: illegal indirection
#include <iostream.h>
int main()
{
int x;
x = 10;
cout << "x = " << x << '\n' <<endl;
int *p;
p= new int(10);
cout << "P = " << *p << endl;
int* p1,p2;
p1= new int;
*p1 = 42;
p2 = p1; // first error is here.
cout << "*p1 = " << *p1 << endl;
cout << "*p2 = " << *p2 << endl; //2nd type of error C2100: illegal indirection error here i dunno why =|
*p2 = 53; // 2nd type error here also
cout << "*p1 = " << *p1 << endl;
cout << "*p2 = " << *p2 << endl; // 2nd type error here also.
p1 = new int;
*p1 = 88;
cout << "*p1 = " << *p1 << endl;
cout << "*p2 = " << *p2 << endl; // 2nd error here also
return 0;
}
any help or comments would be great!
thanks
laura