Function inside a function

Can you call a function inside a function? For example:

#include <iostream>

using namespace std;

char end;

void function() {


cout << "Do you want to end the program? (Y) (N)" << endl;
cin >> end;

if (end != 'Y' && end != 'y' && end != 'n' && end != 'N') {
function();
}
}

int main() {

function();

}
yes
What about for the int main () {} function?
The way you did it above it will work
What about for the int main () {} function?

Yes, of course you can call functions from inside the main() function. If you couldn't, then how could you call any functions from anywhere, ever?

If you're asking whether or not you can call the main() function from a function, then no, you can't. It's illegal to explicitly call main() from anywhere.
1
2
3
4
5
6
void foo() {
  if ( something )
  {
    foo();
  }
}

Yes, and that is called recursion.
Topic archived. No new replies allowed.