Thread: lvalue required error

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    3

    lvalue required error

    code below is showing lvalue required error. why is it? how can it be corrected?
    Code:
     char c[10];
    c='!';
    Last edited by bluerose; 02-16-2012 at 02:28 PM.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    You can't assign to an array in the manner you are attempting. In your code, c is the array and in the above context represents the address of the array on the stack. This can't be changed by assigning a new value to it as it is fixed when the program is executed. You probably wanted something more like this:
    Code:
    c[0] = '!';
    The above code assign a char to a specific element/position within the array.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    3
    thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error: lvalue required, pretty sure it's an lvalue
    By brandones in forum C Programming
    Replies: 18
    Last Post: 08-22-2011, 08:06 PM
  2. Replies: 3
    Last Post: 06-01-2010, 06:22 AM
  3. Lvalue required error
    By Dink87522 in forum C Programming
    Replies: 4
    Last Post: 10-04-2009, 08:34 PM
  4. Lvalue required error
    By eklavya8 in forum C Programming
    Replies: 5
    Last Post: 01-03-2009, 04:47 PM
  5. Lvalue required --compile error--
    By cecu in forum C++ Programming
    Replies: 2
    Last Post: 05-19-2006, 07:40 PM