C++ Programmer Question:

Tell me how can a C function be called in a C++ program?

Tweet Share WhatsApp

Answer:

Using an extern "C" declaration:


//C code
void func(int i)
{
//code
}

void print(int i)
{
//code
}
//C++ code
extern "C"{
void func(int i);
void print(int i);
}

void myfunc(int i)
{
func(i);
print(i);
}

Download C++ Programmer PDF Read All 59 C++ Programmer Questions
Previous QuestionNext Question
Do you know what is the role of mutable storage class specifier?Tell us how to make sure a C++ function can be called as e.g. void foo(int, int) but not as any other type like void foo(long, long)?