1
I’m trying to understand a code about simply chained list. The function InserirInicio
has as a parameter Nodo **inicio, float dado
. I could not understand the use of two asterisks in the parameter in this function in expecifico, would be function requesting a pointer?
Struct and function:
typedef struct nodo
{
float dado;
struct nodo *proximo;
} Nodo;
int InserirInicio(Nodo **inicio, float dado) {
Nodo *nodo;
if ((nodo = (Nodo *) malloc(sizeof(Nodo))) == NULL)
return 0;
nodo->dado = dado;
nodo->proximo = NULL;
if (*inicio != NULL)
nodo->proximo = *inicio;
*inicio = nodo;
return 1;
}
Function call:
int main()
{
int i;
Nodo *inicio = NULL;
for(i = 0; i < 8; i++)
{
InserirInicio(&inicio, i * 15.0);
}
return(0);
}
The meaning of ** I understand, my doubt is because it was used in this function in expecifico.
– Eduardo Cardoso
It’s a chain list or some other list, right? When you pass the pointer to pointer reference, you will possibly change the position of that pointer being pointed, but keep its contents. Run a paper test simulating the interaction of that code and you’ll find out fast.
– Jhonatan Pereira