Is there any difference between function() and function (void)?

In C language, both are different, but in C++ both are same.

In C, function(void) means function takes no argument, but function() means the function can take any number of arguments/parameters, for example:

In C,

int function(void)
{
————-
}

void main()
{
function(10); // error , as void is given as argument in function definition
}

BUT,

int function()
{
————–
}
void main()
{
function(10); // fine, no error
function(1,2,3); // fine , no error
}

On the other hand, in C++, both function() and function(void) are the same and defines that the function takes no argument or parameter.

In C++,

int function()
{
*********
*********
}

void main()
{
function(10); // error
}

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.