Lvalue Required Error

Can someone explain why "p=ch" gives an error: Lvalue Required in the following code. Also, What should be done to remove the error.

I use Borland C++ Version 3.0
Also, I am a beginner in Pointers. (Also C++)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
	char ch[2][20],*p[2];
	for(int i=0;i<2;i++)
	{
		gets(ch[i]);
	}
	p=ch;
	for(i=0;i<2;i++)
	{
		cout<<"\n"<<*(p+i);
	}
	getch();
}
You have a very old C++ compiler which is non-standard and riddled with bugs. Change it to something modern.
YOur code is not valid C++:
1) There is not header <iostream.h>. There is only <iostream>
2) void main() is illegal. Only int main() is allowed
3) line 12: i is undefined.

As for line 11: p is an array of pointers. You cannot assign anything to array. If you intended p to be pointer to array, you have to write (*p)[2]. However assigment would still fail as array dimensions do not match. (*p)[20] would work
Topic archived. No new replies allowed.