According to this answer using function main() is illegal (§3.6.1.3) and a function is used if its name appears in a potentially evaluated expression (§3.2).
Suppose I have this code:
printf( "%p", &main );
in which name of function main()
appears in expression &main
.
Will the code above be illegal?
The address is the memory location where the entity is stored. Every block of code in the program has its own memory location in the program. Which means like any variable or object methods and functions also have memory address.
2) non-modifiable lvalues, which are const. rvalue — The expression that refers to a disposable temporary object so they can't be manipulated at the place they are created and are soon to be destroyed. An address can not be taken of rvalues. An rvalue has no name as its a temporary value.
Although you can call the main() function within itself and it is called recursion. Recursion is nothing but calling the same function by the function itself.
The main() function can call itself in C++. This is an example of recursion as that means a function calling itself.
Yes. As you quote, the standard says that you cannot use
main
.
Note too that the address of a function does not match "%p"
.
The corresponding argument must have type void*
; any other
type (except maybe char*
) is illegal, and results in undefined
behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With