Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 933007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:45:44+00:00 2026-05-15T20:45:44+00:00

My code is: void main() { person student[10]; student[0].names[0] = ‘C’; student[0].names[1] = ‘a’;

  • 0

My code is:

void main() {
 person student[10];
 
 student[0].names[0] = 'C';
 student[0].names[1] = 'a';
 student[0].names[2] = 'm';
 student[0].names[3] = 'i';
 student[0].ages = 16;
 student[0].sex[0] = 'F';
 student[0].sex[1] = 'e';
 student[0].sex[2] = 'm';
 student[0].sex[3] = 'a';
 student[0].sex[4] = 'l';
 student[0].sex[5] = 'e';
 student[0].month = 8;
 student[0].day = 2;
 student[0].year = 1993;
}

All of the "student" is underlined saying expression must be a modifiable lvalue. How can i fix this?

person

typedef struct person 
{ 
char names[20][10]; 
char sex[6][10]; 
int ages[10]; 
int month[10]; 
int day[10]; 
int year[10]; 
} person;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:45:45+00:00Added an answer on May 15, 2026 at 8:45 pm

    Array usage

    You say you have:

    typedef struct person {
        char names[20][10];
        char sex[6][10];
        int ages[10];
        int month[10];
        int day[10];
        int year[10];
    } person;
    

    There’s no need for the [10]‘s. You already have that in the person student[10] declaration, which is the proper place for the [10]. Remove the extraneous arrays:

    typedef struct person {
        char name[20];
        char sex[6];
        int age;
        int month;
        int day;
        int year;
    } person;
    

    String handling

    Also your strings aren’t null-terminated. In C strings need to have an extra '\0' character at the end to indicate where the end of the string is. Your name assignment, for example, should be:

    student[0].name[0] = 'C';
    student[0].name[1] = 'a';
    student[0].name[2] = 'm';
    student[0].name[3] = 'i';
    student[0].name[4] = '\0';
    

    Actually though, there’s an easier way to assign to a string than to do it a character at a time. The strcpy function will copy an entire string in one go:

    strcpy(student[0].name, "Cami");
    

    Or, the easiest option of all is to use the string class available in C++. It makes string-handling a whole lot easier than the C way of manipulating character arrays. With the string class your code would look like this:

    // Modified struct declaration.
    typedef struct person {
        std::string name;
        std::string sex;
        int         age;
        // ...
    } person;
    
    // Modified assignment.
    student[0].name = "Cami";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this code: static void Main(string[] args) { var persons = new List<Person> {
have this code: void set(list<Person*>* listP){ Person timmy = Person(10); listP->push_back(&timmy); } int main()
I have this code : void Main() { System.Timers.Timer t = new System.Timers.Timer (1000);
this is my C# code: void main() { SystemEvents.SessionEnding += new SessionEndingEventHandler(SystemEvents_SessionEnding); } void
Consider this code: void res(int a,int n) { printf(%d %d, ,a,n); } void main(void)
I have some code static void Main(string[] args) { int j = 0; for
I've got really simple code: static void Main(string[] args) { var task = Task.Factory.StartNew(GetInt);
Consider the following code in C: void main() { int a=0; for(printf(\nA); a; printf(\nB));
Here is my code : public static void main(String[] args) { // System.setProperty( //
When i have a code block static void Main() { foreach (int i in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.