answersLogoWhite

0

What is void main in C programming?

Updated: 8/11/2023
User Avatar

Wiki User

12y ago

Best Answer

The main function in C serves as the entry point of your application. A C program is not valid without a main function.

There can only be one main function in your program, but you may use a choice of prototypes:

int main (void);

int main (int argc, char* argv[]);

You use the first version when your program has no need for command line arguments (also known as command line switches). The second version passes the full command line in the argv argument as a null-terminated array of null-terminated strings. The argc argument holds the count of strings in argv and is always at least 1 since the program name is part of the command line (stored in argv[0]). Any switches passed to the program will be found in argv[1] through argv[argc-1]. The last argument, argv[argc], is always the null-terminator (a pointer to null).

The return value allows you to return an integer to the host environment. Typically you will return 0 to indicate success and -1 to indicate failure.

The void main (void); prototype is allowed in most implementations of C (but not in C++). This simply indicates no return value is expected. However, the prototype is non-standard and if your program makes use of the exit() function to terminate, your program will return whatever value you pass to the exit() function.

Your implementation of C may also allow additional prototypes, however only the first two shown above are standard across all implementations. For portability, it is best to use one of these at all times.

User Avatar

Wiki User

8y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

The point where the execution of the program begins; and when function 'main' terminates, the program-execution terminates as well.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

When a C programme runs it always executes the main() procedure first.

void main means that the procedure does not return anything to the OS when it exits.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is void main in C programming?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What an example of a function?

In C-programming: int main (void) { return 0; }


What is token in C programming?

They're things that keep the variables in line with the void main and your functions


How do you make a proposal in C programming?

#include <stdio.h> int main (void) { puts ("Marry me"); return 0; }


Why are using the void main in C programming?

Because you misunderstood something. The correct usage: int main (int argc, char **argv)


How can you write a c programming which say you that day is holyday?

int main (void) {puts ("day is holyday");return 0;}


Why is void main kept in c programming?

Not all host environments make use of a C program's return value, thus some implementations still allow the void main function signature. C++ does not permit it, however. All C++ programs must return an integer whether the environment uses it or not.


What is the commands to create diractly ABC under C or inside the C?

Is this question about programming? If so, try this:int main (void) { puts ("ABC"); return 0; }


Example of a Cosine of a given number in C programming?

int main (void) { puts ("Cosine of 60° is 1/2"); return 0; }


Why to write void main in c programing?

it is always not necessary to write "void main " in c programming.it depends on the source code we use if we have to return a value then void is not necessary because void returns the null.While coding in borland C++ we need to write void main but we dont need it in dav c++.In C (and C++) the standard allows int main (void) and int main (int argc, char **argv)


How do you display 'hello world' using c programming language?

#include<stdio.h> int main (void) { printf ("Hello world!\n"); return 0; }


Why you use void res in c programming?

since, the word 'void' in C programming language means that it does not return any value to the user or calling function....this is usually used to specify a type of function...... for this reason w use 'void'in c program..


Types of main function in C programming?

minimalist: int main (void); standard: int main (int argc, char **argv); unix-only: int main (int argc, char **argv, char **envp);