In C, when is void main used and when is main used?

Updated on science 2024-02-16
8 answers
  1. Anonymous users2024-02-06

    It is the return value of the subfunction, and the main function also has a return value, but it is generally not used and ignored.

    So, in general, the return value is the return value of the subfunction.

    Another point to note is that a subfunction must only return one value. This can only be done with arrays or pointers.

    There are generally two kinds of return values for functions, and the standard type is required regardless of whether there is a return value or not.

    One is void. This is generally not used, it is an empty return value. That is, when the return value is not needed, the type of the function is marked void. In fact, this will also return a value, as if the call returns 1 when it succeeds, and 0 when it is unsuccessful

    The other is non-void. It is to write the type in front of the function, such as int, float, char, etc., which is the return value type of the function. This is usually done at the end of a subfunction or somewhere in the program with a return.

    But when you encounter the return subfunction, it must be ended.

    In fact, there is also a return value, which is the system functions such as scanf and printf, which I know that the return value of printf is the number of characters it prints.

  2. Anonymous users2024-02-05

    If you don't need a return value, use void main() and use main if you have a return value

  3. Anonymous users2024-02-04

    The standard usage is int main(

    main does not need to be returned.

    void main doesn't need to be returned, int main needs to be returned int

  4. Anonymous users2024-02-03

    When there is no return value, void is used. . .

  5. Anonymous users2024-02-02

    Actually, it's all the same, there's no difference.

  6. Anonymous users2024-02-01

    This is a way to declare the main function in C, which indicates that the main function returns a value without arguments.

    void is often used in program writing to declare the parameter type, return value, and pointer type of the function that defines the function.

    However, in the recommended writing of the C language, it is recommended to use int main, because although some compilers can compile Viod main, other compilers will report errors. In order to have better portability, int main is generally written.

    Similarly: in C, a program, no matter how complex or simple, is generally a "function"; This function is called the "main() function", which is the "main function". For example, if there is a "cooking" program, then the process of "cooking" is the "main function".

    In the main function, depending on the situation, you may also need to call subfunctions such as "buy vegetables, cut vegetables, stir-fry vegetables".

    The main function is mandatory for most applications, but there are exceptions, such as the possibility of writing a Dynamic Link Library (DLL) module in Windows programming, which can be used by other Windows programs. Since the DLL module is not a stand-alone program, the main function is not required. As another example, programs used in professional environments--- such as control chips in robots – may not require the main function.

  7. Anonymous users2024-01-31

    The difference between void main and int main is whether there is a return value or not.

    1. The function defined by void does not return a value, and the function defined by int returns an integer value.

    2. void, which literally means "untyped", is commonly used in program writing to declare the parameter type, return value, and pointer type in the function of defining the function, and has the function of commenting and restricting the program.

  8. Anonymous users2024-01-30

    Review:void main actually returns as well, but with the default 0, while int main can choose what value to return.

    void main means that the main function has no return value, and there is no need to write a return statement; If you write a type such as void or int before main, you need to write return 0 at the end of the main function. But the requirements are not very strict when learning C, and it is okay to just write main(), but if you want to be stricter when learning C++, it must be int main(), and you must write return 0 at the end.

    The main function, also known as the main function, is the starting point of the program's execution, and the main is relative, just as the main tone of the phonological theory is the overtone, which is the function in the program other than main, which caters to people's way of thinking and generates a rather than a necessary pattern. There are primary and secondary, and the execution is clear and detailed, which can not only modularize the program but also realize a closed whole.

    main

    Program execution always starts from the main function, if there are other functions, it will complete the call to the other functions and then return to the main function, and finally the main function will end the whole program. When executing a program, the main function is called by the system. The main function is called after initializing a non-local object with a static storage period during program startup.

    It is the entry point specified by the program in a hosted environment (i.e., with an operating system).

Related questions
6 answers2024-02-16

Define the struct:

typedef struct _legaladdress_{ >>>More

18 answers2024-02-16

Why they are taken in this way, and why x is from 1 to 14, this needs to be carefully calculated. Because the amount of calculation in this problem is very small, sometimes I try to save my own effort (calculate a little less) and let the computer calculate a little more. >>>More

6 answers2024-02-16

Understand the following rules: 1) Overloading an operator does not change the priority of the operator. >>>More

5 answers2024-02-16

It's hard. The Italian team should defend well, especially the central defenders, who basically represent the defense of the Italian national team. Juventus are also the team with the fewest goals in the top four. >>>More

20 answers2024-02-16

You can use it when you describe it normally. It's just plain narration, with no emphasis on anything. >>>More