Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

713
Views
Struct keyword in function parameters, what is the difference?

I wonder, what is the difference between:

struct Node
{
  int data;
  Node *next;
};

and

struct Node
{
  int data;
  struct Node *next;
};

Why do we need struct keyword in second example?

Also, what is the difference between

void Foo(Node* head) 
{
    Node* cur = head;
    //....
}

and

void Foo(struct Node* head) 
{
    struct Node* cur = head;
    //....
}
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Only the declarations including struct are valid in C. There is no difference in C++.

However, you can typedef the struct in C, so you don’t have to write it every time.

typedef struct Node
{
  int data;
  struct Node *next;  // we have not finished the typedef yet
} SNode;

SNode* cur = head;    // OK to refer the typedef here

This syntax is also valid in C++ for compatibility.

over 4 years ago · Santiago Trujillo Report

0

Struct node is a new user defined datatype that we create. And unlike classes the new data type using structures is "struct strct_name" , ie; u need the keyword struct in front of the struct_name. For classes u do not need keywords in front of the new data type name. eg;

class abc
{
  abc *next;
};

and when u declare variables

abc x;

instead of struct

abc x;

in case of structures . Also understand that by the statement

struct node * next;

we are trying to create a pointer that points to a variable of type "strcut node", which is called a self referential pointer in this case since it points to the parent structure.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!