question - pinter.array

hello guys;
would any of u tell me what bug does this have? ma compiler can't continue after the part "Number 1 :". :(

[
int *p,*w;

int in(int x[3],int y[3])
{
int i=0;
do
{cout<<"Number "<<i+1<<" : ";
cin>>x[i];
i++;}while(i<3);

cout<<endl;

for(int j=0;j<3;j++)
{cout<<"Number "<<j+1<<" : ";
cin>>y[j];}

p=x;
w=y;
return y[3],x[3];
}

and then in function main i call :
in(p,w);
]
Could you please post all your code and put it in code tags
How to use tags: http://www.cplusplus.com/articles/z13hAqkS/

int* and int[] are not the same.
Your function has a return type of int, which works with return y[3],x[3];, but it does not do whatever it is that you probably intended for it to do.
return y[3],x[3]; will return the value of the thirdfourth integer in the array called x.
Some information on how the comma operator works: http://stackoverflow.com/questions/54142/how-does-the-comma-operator-work
x[3] when used in an expression is the thirdfourth value in the array called x, but when used in a function prototype it refers to an array that has 3 elements.

Now on to your actual question
would any of u tell me what bug does this have? ma compiler can't continue after the part "Number 1 :". :(

Would you please post the exact error your compiler reports? What compiler are you using? Is your entire code short enough to post here?
Last edited on
Just a quick question: did you allocate memory for p and w arrays?
@miinipaa
yes actually they are global and are NULL by the time i define em.
@kevin
thanks
i really needed that!
x[3] when used in an expression is the third value in the array called x

Actually, it's the 4th value, to be accurate.

Edit: I'm sure you know that, but I just wanted to make sure the OP isn't confused.
Last edited on
Thanks MikeyBoy, I meant fourth not third.
Topic archived. No new replies allowed.