C: What will be the output of the following program?
What will be the output of the following program?
main( )
{
int i ;
char a[ ] = "Hello" ;
while ( a != '\0' )
{
printf ( "%c", *a ) ;
a++ ;
}
} The above program on compilation flashes an error message, "Lvalue Required" on line number 8. This is because we are incrementing a which is nothing but a constant pointer to zeroth element of the array. We know that the increment operator ++ cannot operate on a constant object. It is the equivalent of saying 5++ which is not permitted, since it is same as:
5 = 5 + 1 ;
Since on the left hand side of the assignment operator something other than what is required (a variable) the error "Lvalue Required" results.




Comments
Log in or create a user account to comment.