Placement Prep

int main() vs int main(void) in C and C++: The Difference Explained

In C++, int main() and int main(void) are identical. In C, empty parentheses mean unspecified arguments, void means none. The full breakdown with code examples.

By FACE Prep Team 4 min read
c-programming cpp technical-interview placement-prep programming-fundamentals c-standards c23

In C++, int main() and int main(void) are identical. In C, they are not, and the distinction applies to every function you write, not just main().

The Quick Answer: C++ vs C

The table below covers what each form means in each language:

FormIn C++In C (pre-C23)
int main()No parameters (same as void)Unspecified parameters (K&R legacy)
int main(void)No parametersNo parameters (explicit prototype)

C++ never had the “unspecified parameters” concept, so both forms have always meant the same thing there. C inherited a legacy from before prototypes existed, and that legacy is why the two forms diverge.

The short version for interviews: in C, if you want to be precise, use int main(void).

Why C Treats Empty Parentheses as Unspecified

Before ANSI C89 standardised function prototypes, C programmers wrote function declarations without parameter types:

/* Pre-ANSI K&R style: parameter types not specified */
void process();
int compute();

These declarations told the compiler that a function existed, but gave no information about what arguments it accepted. The compiler performed no type-checking on calls to these functions. This was the “unspecified parameters” model.

When C89 introduced prototypes, it needed a way to say “this function takes no parameters at all.” The answer was void in the parameter list:

/* C89 prototype: explicitly no parameters */
void process(void);
int compute(void);

The empty-parentheses form kept its original meaning for backward compatibility: unspecified, not zero. That choice created the divergence between fun() and fun(void) in C.

C++ was designed with prototypes from the start. It never had a “K&R declaration” phase. So in C++, empty parentheses and void are synonymous, and both signal no parameters. The C++ standard’s main function specification treats both forms as equivalent with no caveats.

The C standard’s main function specification defines two explicitly portable forms: int main(void) and int main(int argc, char *argv[]). The int main() form works in practice but sits in the “other implementation-defined forms” category.

Two Programs That Show the Difference

The following pair of programs makes the distinction concrete. Compile them as .c files to observe the C behavior.

Program 1: fun() with empty parentheses

This version compiles and runs in C, but fails in C++.

/* Program 1: save as prog1.c and compile with gcc prog1.c */
#include <stdio.h>

void fun() { }   /* empty parens: unspecified parameters in C */

int main(void)
{
    fun(10, "hello", "world");   /* C allows this: no prototype to check against */
    return 0;
}

In C, void fun() is a definition with an empty parameter list. No prototype means no constraint. The call fun(10, "hello", "world") passes three arguments to a function that ignores all of them. The compiler accepts it without complaint.

In C++, void fun() means “no parameters.” The call with three arguments is a compile-time error.

Program 2: fun(void) with explicit void

This version fails in both C and C++.

/* Program 2: save as prog2.c */
#include <stdio.h>

void fun(void) { }   /* explicit void: no parameters, full prototype */

int main(void)
{
    fun(10, "hello", "world");   /* ERROR in both C and C++ */
    return 0;
}

Here void fun(void) creates a complete prototype in C as well. The prototype tells the compiler that fun accepts exactly zero arguments. The call with three arguments violates that contract and fails compilation in both languages.

The key difference is that void inside the parentheses activates the prototype system in C. Empty parentheses do not.

This same behavior applies to main() directly. int main() in C does not create a prototype for main. In a hosted environment, main is called by the C runtime with no arguments in the standard form, so the practical effect is the same, but the formal semantics are looser. int main(void) creates the proper prototype and is unambiguous.

What C23 Changed

C23 (ISO/IEC 9899:2024, published December 2024) closed this gap. The standard deprecated empty parameter lists. In C23-compliant code, void fun() is now treated the same as void fun(void). The compiler is required to diagnose any call that passes arguments to a function declared with empty parentheses.

The practical effect for new code:

  • Use int main(void) (or int main(int argc, char *argv[]) when you need command-line arguments). Both are explicitly portable.
  • Avoid int main() in new C code. It still compiles, but compilers targeting C23 will issue a deprecation diagnostic.
  • Existing codebases that relied on calling fun() with arbitrary arguments need review. Those call sites are now diagnosed as errors under C23.

For most engineering students writing C programs for placement tests and coursework, the change is straightforward: int main(void) is the correct form, and it has been the recommended style since C89.

Why This Appears in Technical Interviews

Questions about int main() versus int main(void) appear in written tests and technical rounds at companies hiring for C-heavy roles: embedded-systems positions, compiler teams, OS-level work, and driver development. The question tests whether a candidate understands the prototype system, not just the surface syntax.

The related common data structures and C interview questions cover the broader set of C fundamentals that interviewers reach for. For hands-on C practice, array traversal problems in C build the comfort with pointers and memory that makes these conceptual questions easier to answer.

The precise answer to “what is the difference?” is:

  • In C++: no difference.
  • In C (pre-C23): int main() means unspecified parameters; int main(void) means explicitly no parameters.
  • In C23: both mean no parameters, and the old distinction is deprecated.

Knowing the C23 update signals to interviewers that you track language evolution, not just the introductory textbook.

The precision that separates int main(void) from int main() is about reading the specification rather than guessing at compiler tolerance. That same habit carries directly into working with LLM APIs: understand the parameter contract, test the boundaries, build something that holds up. TinkerLLM at ₹299 gives you a real environment with actual API calls, the kind of hands-on project that becomes a talking point the next time a technical round asks what you have shipped.

Primary sources

Frequently asked questions

Does int main() differ from int main(void) in C++?

No. C++ treats both forms as identical. The language does not have the K&R empty-parameter-list concept, so empty parentheses always mean no parameters in C++.

Why can C functions with empty parentheses accept any arguments?

In C, a function definition with empty parentheses is not a prototype. It does not constrain parameter types or count. This is a legacy of K&R C, which predates the C89 prototype system.

Is int main(void) required by the C standard?

No, both forms are accepted. But int main(void) is the recommended style because it explicitly declares that main accepts no arguments, creating a proper function prototype.

What did C23 change about empty parameter lists?

C23 deprecated empty parameter lists. In C23, void fun() is treated the same as void fun(void), aligning C with C++. Existing code that relies on empty parentheses for unspecified-argument semantics needs updating.

Does this distinction apply to all C functions, not just main?

Yes. Every C function declared or defined with empty parentheses follows the same rule. void process(), int compute(), and similar all share this behavior. main() is just the most visible example.

Build AI projects

A self-paced playground for building with LLMs.

TinkerLLM is FACE Prep's sister property. A guided environment for shipping real LLM applications, the kind of project that earns a paragraph on your resume, not a line.

Try TinkerLLM (₹299 launch)
Free AI Roadmap PDF