i want to do an if-else statement where the if statement would call the function again...is that possible
Can a function call itself?
Collapse
X
-
Yes it is. Any function can call any other function including itself. Heck, you can even call main() from your function.
It's your responsibility to control this so you don't call yourself forever.
Research recursion. -
Actually you can only call main in C. In C++ the standard expressly forbids it in clause 3.6.1.
Originally posted by C++ Standard 3.6.13 The function main shall not be used (3.2) within a program. The linkage (3.5) of main is
implementation-defined. A program that declares main to be inline or static is ill-formed. The
name main is not otherwise reserved. [Example: member functions, classes, and enumerations can be
called main, as can entities in other namespaces. ]Comment
-
That only applies to an inline main() or a static main().
A regular global main() has no restrictions.Comment
Comment