answersLogoWhite

0

Why use in c programming void main?

Updated: 8/11/2023
User Avatar

Wiki User

12y ago

Best Answer

The compiler needs to know where a program starts. This is called the entry point of a program. The main function is just the standard way of denoting where the entry point of your program is.

User Avatar

Wiki User

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

Wiki User

14y ago

Every program starts with the main function because that is how the run-time library startup routines work. It is the established convention. There has to be some entry point, otherwise the program could not do anything, and main() is the defined entry point.

That is, main() is the entry point after run-time library startup.

Note: Not the program starts with main, only its execution. In the source the main can be at the very end of the file.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

The use of void main in C (or C++) is deprecated because it is expected that the main function of a program must return an int that reflects the results of the execution of that run. By convention, 0 means success, and anything else means failure. The actual value of the return value is by agreement with the programmer and the invoking program, but the main point here is that main should return an int, not a void.

This answer is:
User Avatar

User Avatar

Wiki User

7y ago

The global main function provides the entry point of an application, without which our application would be invalid. We can actually have as many main functions as we want, however we can only have one global main function. The global main function has two common signatures:

int main (void);

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

The second version is used when a program expects command-line arguments. However, even if our program doesn't use any arguments, it is is best to use the second version to obtain the fully-qualified path to the executable from the command-line processor. The argument names are conventional; we can use any names we wish, but it's best to use the conventional names for consistency:

argv: null-terminated array of pointers to null-terminated strings

argc: count of arguments in the array

argv[0] always refers to the fully-qualified path to the executable, thus argc is always at least 1. argv[argc] is always nullptr (the array's null-terminator).

It is generally useful for the main function to iterate over the array and create a vector of strings which can then be more easily passed to a process function to decide what actions (if any) to take. This helps keep our main function as brief as possible, even with the inclusion of a catch-all exception handler:

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

std::vector<std::string> command {};

for (int i=0; i<argc; ++i) command.push_back (std::string{argv[i]});

try {

return process (command);

}

catch (...) {

// catch any and all exceptions here...

}

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

A c program doesn't begins with main function, but during execution of that program execution begin with the first statement of the main function.

This answer is:
User Avatar

User Avatar

Wiki User

7y ago

The global main function serves as the entry point of the application. When an application is executed, all static objects are initialised first and then the global main function is executed.

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

That's a convenient way to specify a program's starting point.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why use in c programming void main?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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..


How do you make a proposal in C programming?

#include &lt;stdio.h&gt; int main (void) { puts ("Marry me"); return 0; }


What is the use of return function in C programming?

To return the exp. or const to the main fumction.


C progamme for conversion of Celsius to Fahrenheit using array?

main void void void (void) { float temp1 [13]= {1,4,2,3,4,5,7,88,9,4,3,23,12};


How do you use call by reference in c plus plus?

Call by reference means calling a function using a reference to a variable or a pointer. You call a function by passing refrences to a variable. For eg: void x(int &amp;a) { a=2; } void main() { int s=3; x(s); } OR void a(int &amp;c) { c=5;}void main(){ int *p; *p=2a(*p);}

Related questions

What an example of a function?

In C-programming: int main (void) { 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.


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..


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)


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 &lt;stdio.h&gt; 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)


Why do you use void main in C language?

it returns nothing


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

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


Why you are using VOID in C programming?

You don't use 'VOID', but 'void'. It means different things, such as:- void as function type means no return value- void as function parameter means no parameters- 'void *' as pointer-types means generic pointer


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&deg; is 1/2"); return 0; }