answersLogoWhite

0

What is (void)0?

Updated: 10/20/2021

A default argument is a function argument that has a default value. That is, if no value is specified for the argument, the default value is used. Only the trailing arguments of a function can be default arguments. That is, if an argument has a default value, all arguments that follow it must also have a default value:

// declarations:

void f (int=42); // ok

void g (int, int=42); // ok

void h (int=42, int); // compiler error (trailing default argument missing)

// calls:

f (); // ok -- invokes f(42);

f (0); // ok -- invokes f(0);

g (0); // ok -- invokes g (0, 42);

A default value cannot be repeated in a function's definition unless that definition is the only declaration:

// declarations:

void f (int=42);

void g (int=42);

// definitions:

void f (int x) { /* ... */ }; // ok

void g (int x=42) { /.../ }; // error

void h (int x=42) { /* ... */ }; // ok

User Avatar

Mara Denesik

Lvl 10
3y ago

What else can I help you with?