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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:04:00+00:00 2026-05-16T04:04:00+00:00

I have a simple question in understanding the pointers and struct definitions in the

  • 0

I have a simple question in understanding the pointers and struct definitions in the linked list code.

1)

typedef struct node
{
 struct node* next;
 int val;

}node;

here if I use two “node” when i initialize node *head; which node I am referring to?

2) Here I use an int val in the struct. If I use a void* instead of int is there any thing thats going to change ?

3)Also if I pass to a function

reverse(node* head)
{
    node* temp = head; or node* temp = *head;     
    //what is the difference between the two
}

I am sorry if these are silly question I am new to c language.

Thanks & Regards,
Brett

  • 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-16T04:04:00+00:00Added an answer on May 16, 2026 at 4:04 am

    <1>
    in C you need to specify struct node for structs

        struct node 
        {
    ...
        } node;
    

    the last ‘node’ is variable of type struct node
    e.g.

    node.val = 1;
    

    and not a type.

    if you want to use ‘node’ as a type you need to write

    typedef struct node { .. } node;
    

    <2>
    if you use void* you will need a mechanism to handle what the pointers point to e.g. if void* points to an integer you need keep the integer either on the stack or the heap.

    node n;
    int value = 1;
    n.val = &value; // pointing to a single integer on stack
    
    int values[]={1,2,3};
    n.val = values; // pointing to an array of integers on stack
    
    void* ptr = malloc(sizeof(int));
    n.val = ptr;  // pointing to a single (uninit) integer allocated on heap
    int* ptrval = (int*)ptr; // setting an int ptr to the same memory loc.
    *ptrval = value; // ptrval now points to same as n.val does
    

    <3>
    reverse(node* head)
    head is a pointer to your list, *head is the content of what the pointer points to (first node below)

    head->[node next]->[node next]->[node
    next]

    EDIT: rephrased and edited.
    EDITx2: apparently the question got edited and a typedef was added so the question was altered.

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

Sidebar

Related Questions

I have a simple question. I'm trying to get a list of the indicators
I have another simple question about Node. I'm trying to make a simple http
I have an simple understanding question: Why can I only send Binary Data from
I have a question about some code I'm testing to start understanding posix threads.
Very simple question here: I have an android project in Eclipse. Not understanding how
I have simple question. User supplies URL to my PHP script where I fetch
I have simple type Question : public class Question { public string[] Tags {
i have a simple question: i have this var: $v = 24000,1500,1500,1500,1500,1500,; i would
i have a simple question, there is a function with parameter emp_id that opens
I have a simple question: how exactly are array variables such as $_SESSION and

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.