Void main in C Programming

April 27, 2023 · Team EasyExamNotes · 1 min read (est.) · 0 comments

Share on WhatsApp

In C programming, the void main() function is used to define the starting point of a program. However, it is not a recommended practice to use void main() in modern C programming.

Instead, it is recommended to use int main() or int main(int argc, char *argv[]) as the starting point of the program. These functions return an integer value that indicates the exit status of the program. A return value of zero indicates that the program executed successfully, while a non-zero value indicates an error.

Here’s an example of how to use int main():

#include <stdio.h>

int main() {
   printf("Hello, World!");
   return 0;
}

In this example, the main() function prints “Hello, World!” to the console and returns a value of zero.

Using void main() is considered bad practice because it does not return a value, which can cause issues with some compilers and operating systems. It is recommended to always use a return type of int for the main() function.

Discussion

Ask a question, share your thoughts or report an error.

Sign in to participate in the discussion.

Join the discussion