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

  • Home
  • SEARCH
  • 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 8805139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:47:13+00:00 2026-06-14T01:47:13+00:00

I have the following form in c (gcc): typedef struct { mem 1; mem

  • 0

I have the following form in c (gcc):

typedef struct {
  mem 1;
  mem 2;
  mem n;
} *obj;

How do I get a specific member from that type of structure, initialized with obj var;?

  • 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-06-14T01:47:15+00:00Added an answer on June 14, 2026 at 1:47 am

    First, that declaration is invalid, you’re trying to declare members whose identifiers are numbers. I’ll assume you actually want this:

    typedef struct foo {
        int mem_1;
        int mem_2;
        ...
    } *obj;
    

    You access plain struct members with a dot (.):

    struct foo bar;
    bar.mem_1 = 2;
    

    This is perfectly fine, the compiler allocates stack space of the correct size automatically.
    Now, since your obj var is a pointer1, we’d access its members with an arrow (->):

    obj var;
    var->mem_1 = 3;
    

    Of course, if you’re lucky, this will segfault. If not, you’re likely to have a very long and enlightening session with the debugger. Unlike declaring a struct foo itself, Declaring obj var or its equivalent struct foo *var does not create anything except an uninitialized pointer. You need to provide the memory for this yourself:

    obj var = malloc(sizeof(*var));
    

    Note that this merely provides the memory, its contents are still undefined, but you can safely assign to them.


    1: This is the problem with typedefing away pointers like you’ve done; it’s impossible to know whether you need to use . or -> without seeing the typedef or being told off by the compiler. Don’t use typedef to hide a pointer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following form: <form action= method=get> <input name=form1 type=radio onclick=document.forms[0].testbox.value='0.00'; /> <input
I have the following form in a Struts2 JSP that contains some radio buttons.
I have the following form: @model Teesa.Models.SearchModel @using (Html.BeginForm(Index, Search, FormMethod.Get, new { id
I'm looking at some Java classes that have the following form: public abstract class
I have form with checkboxes loaded from database (I use entity field type). Checkboxes
I have a following form Form3 that is opened by another form Form1, and
I have the following form that has 2 selects: <form id=form class=form_visitar method=post action=ajax/selects.php>
I have following html form: <form method=post action=> <input type=hidden name=userid id=user value=<?php echo
I have the following form: <label>One</label> Product ID:<input type=text name=productid[] value=> Product Quantity: <input
I have the following form <form id=enter_email method=post action=> <input type=text value=enter email />

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.