Domanda

I've a C++ program like this:

typedef struct _nodo
{
    ...
} node;    

void cuenta(node& *Lista, char c);

When I compile don`t show any error. Now, when I want to use this code for a C program, the compiler show error:

error: expected ')'
void cuenta(node* &Lista, char c);

What its the difference between & and * in C++ and C?

È stato utile?

Soluzione

node& *Lista would be a pointer to a reference to some node in C++ (but that is not possible in C++), but reference types don't exist in C, so it is invalid syntax in C. BTW, you probably meant node* &Lista -a reference to a pointer- ...

So in C you'll pass a pointer to a pointer, and e.g. declare your parameter node**pLista and use everywhere inside your function *pLista instead of the Lista reference of C++.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top