In C, the void function cannot be assigned for the following reasons: type mismatch: the void function has no return value, the type is void, and is incompatible with the assignment operator operand type. The essence of function pointers: The void function has no return address, making it impossible to store it in the function pointer, causing the assignment to be invalid. Avoid confusion: prohibiting assignment prevents the mistaken belief that void functions can return values. Keep it simple: disabling assignment simplifies the language and improves consistency and readability.
The reason why the void function cannot be assigned a value in c
In C, the void function cannot be assigned a value. This is because The following reasons:
Type mismatch
The essence of function pointers
Avoid confusion
Keep the language simple
The above is the detailed content of Why can't void function be assigned a value in c++?. For more information, please follow other related articles on the PHP Chinese website!