Question

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?

Was it helpful?

Solution

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++.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top