Home / Tips / C Tips / C: What will be the output of the following program?

“Chishiki” is Japanese for “knowledge.” e-chishiki.com aims to bring software developers, information security professionals, IT executives and other IT pros a rich body of knowledge in the form of articles, interviews, tutorials and technical discussions. Our contributors are among the biggest names in the Indian IT industry and include noted authors, educators and practitioners.

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.

On Sale From April 2008

Let Us C
8th Ed.
C programming classic & best seller. 1 million+ copies sold!

Y. Kanetkar

On Sale From April 2008

Introduction to Object Oriented Programming & C++

Y. Kanetkar

On Sale From Fall 2008

Microsoft .NET Framework: Web Application Security

Vijay Mukhi

On Sale From Nolvember 2008

Quest C++ Courseware
12+ hours of instructional audio and animated slides.

Y. Kanetkar Asang Dani

On Sale From November 2008

A Programmer's Guide to Web Application Security

Vijay Mukhi

Latest Forum Posts