Why it throw error?

Write your question here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;
int main()
{
char s[]="C++";
cout << s << endl;
*s++;
cout << s << endl;
return 0;
}

output:error: lvalue required as increment operand
 *s++;
   ^
Because *s++ is interpreted as *(s++). You can't increment s because it's an array.
And if you were trying to print out D++, try this:
 
(*s)++;

http://web.ics.purdue.edu/~cs240/misc/operators.html
Last edited on
Thanks for ur support !
Now I understand it.
Topic archived. No new replies allowed.