Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

716
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda