I’m doing a competitive programming question (thus ‘good practice’ isn’t necessary) where I find it necessary to quit the code while not in the main function. It doesn’t have to be good practice, it just has to work.

Is it possible to do this? exit(0); throws Illegal instruction (core dumped).


#include <bits/stdc++.h> 
using namespace std;

void foo() {
    print("message here");
    // what do I put here to terminate the program?

int main() {
    // stuff that will somehow call foo

Khám phá các thẻ bài đăng