Function return type for a chained list

Asked

Viewed 172 times

1

What kind of return to use in a chained list? For example, insert at the beginning of the list.

void inserir(pessoas **pessoa, int valor) 

no return (void). Or return a pointer from the list.

pessoas* inserir(pessoas **pessoa, int valor)

Which would be more appropriate?

1 answer

1


The first may be well suited because it probably modifies pessoa with the new element and do not need to return anything.

The second is only useful if you are not changing the data structure or if you want as ease leave the function inserir() was used as expression somewhere. The first can only be used as statement.

If you use the first one it may be useful to return a true or false one if the operation occurred ok. In some scenarios you may not be able to complete it and it would be interesting inform that an error has occurred in a simple way.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.