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 6117287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:18:12+00:00 2026-05-23T15:18:12+00:00

Sorry for asking a basic question, I am learning C and I got confused

  • 0

Sorry for asking a basic question, I am learning C and I got confused with assigning a value for a list. I got confused with my own question that pops into my head.. 🙁

So for instance, I have a struct below

typedef struct {
    int value_in_use;
} structA;

typedef struct structB {
    structA conn;
    struct structB *next, *prev;
} structB

typedef struct {
    structB *head, *tail;
} structC;

and I want to assign the value of “value_in_use” equal 1. I am totally confused, as what I understand, that in a list, I need to traverse from the head first(StructC), and I need to go inside the list until I get into structA and assign value to it. So something like

 structC *C = NULL;
 C = (structC *) malloc(sizeof(structC));
 int assign=1;
 &C->structB.head->conn.value_in_use=assign;

Meanwhile, I was thinking that I can actually assign a pointer to structA directly and assign value to it. So I can just say

structA *ue = NULL;
ue = (structA *) malloc(sizeof(structA));
ue->value_in_use = 100;

How does it differ for assigning the value of a list in run time in the first part and second part? I believe I can use both for assigning value (or?) ..

Thank you so much for sharing your knowledge with me.

  • 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-23T15:18:13+00:00Added an answer on May 23, 2026 at 3:18 pm

    The first one in fact won’t actually work. You’re trying to follow a head pointer from C, but you have no idea where that pointer points to (i.e. malloc is not recursive).

    For the first case, you would need to do something like this:

    structC * c = malloc(sizeof(structC));
    structB * b = malloc(sizeof(structB));
    c->head = b;
    c->tail = b;
    b->next = NULL;
    b->prev = NULL;
    c->head->conn.value_in_use = 1;
    

    Note that we do not have to allocate a structA separately, since there is one embedded in B.

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

Sidebar

Related Questions

I might be asking a very basic question and I am sorry for that.
Sorry for asking this question, but I searched all Java-related questions, but I got
Sorry for asking a basic question like this but I've been reading on this
Guys, sorry for asking basic question, i have a problem here where I have
sorry a basic question and I have resorted to asking as I can't find
I'm sorry for asking a question on something that I'm sure is easily found,
Sorry for the basic question - I'm a .NET developer and don't have much
I'm sorry for maybe making such a basic question but in ASP.NET websites what
Sorry if the question is confused, as I'm confused myself. I'm working around these
sorry for asking this dumb question i will try to explain as good as

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.