I made a code
#include <iostream>
#include<conio.h>
using namespace std;
void main()
{
int *x,*y;
x=new int[1];
y=new int;
cin>>y; //Gives error probably because y is a pointer and not a variable
cin>>*y //works fine
cin>>x[0]>>x[1];
cout<<x[0]<<x[1];
cout<<*x[0]; //gives error
cout<<y;
cout<<*y;
getch();
}
gives error.why?I remember i declared x as a pointer array and now i m doing the same i did with *y.Does it mean that a pointer array becomes a variable?plz help!
void main.xandyare both variables of type pointer to int. The reason for the first error is that istream has no overloaded extraction operator for reading a pointer (see cplusplus.com/reference/istream/istream/operator%3E%3E), and the reason for the second error is that you are attempting to dereference something not of pointer type (x[0]has typeint).intis deemed undefined behaviour by the C++ standard.