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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:47:51+00:00 2026-05-14T14:47:51+00:00

This probably is one of the easiest question ever in C programming language… I

  • 0

This probably is one of the easiest question ever in C programming language…

I have the following code:

typedef struct node
{
  int data;
  struct node * after;
  struct node * before;
}node;

struct node head = {10,&head,&head};

Is there a way I can make head to be *head [make it a pointer] and still have the availability to use ‘{ }’ [{10,&head,&head}] to declare an instance of head and still leave it out in the global scope?

For example:

 //not legal!!!
 struct node *head = {10,&head,&head};
  • 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-14T14:47:52+00:00Added an answer on May 14, 2026 at 2:47 pm

    Solution 1:

    #include <stdlib.h>
    #include <stdio.h>
    
    
    typedef struct node
    {
      int data;
      struct node * after;
      struct node * before;
    }node;
    int main() {
    
        struct node* head = (struct node *)malloc(sizeof(struct node)); //allocate memory
        *head = (struct node){10,head,head}; //cast to struct node
    
        printf("%d", head->data);
    
    }
    

    Something as simple as struct node *head = {10, head, head} is not going to work because you haven’t allocated the memory for the struct (the int and two pointers).

    Solution 2:

    #include <stdlib.h>
    #include <stdio.h>
    
    
    typedef struct node
    {
      int data;
      struct node * after;
      struct node * before;
    }node;
    int main() {
    
        struct node* head = &(struct node){10,head,head};
    
        printf("%d", head->data);
    
    }
    

    This will go out of scope – Solution 1 is superior for this reason and since you’re creating a linked list, I believe you need heap allocated memory – not stack allocated.

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

Sidebar

Related Questions

This is probably a basic html/css question... I have a simple one-button form that
This is probably one of the most common tasks / problems when programming; You
This is probably an easy one. I have about 20 TextViews/ImageViews in my current
This is probably one of the silliest questions i have asked. I'm trying to
I probably have one of the easiest questions of the day, but I'm having
This is probably one of those easiest things to deal with but for some
I know this is probably one of those you just have to try it
This is probably an easy one... I have a Listbox with a ContextMenu embedded
This is probably easiest to explain with code (this is of course not the
This is probably one of those easy questions.. I'm trying to redirect the user

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.