RE: A Question About C 10-16-2015, 10:40 AM
#2
(10-15-2015, 04:26 AM)CPU Wrote: I am learning the C programming language, and have a question to ask experienced C programmers on this forum: Does putting "void" in a function declaration's parameter list have a difference between an empty parameter list?There is no difference between the two.
Example:
Code:my_function(void);
Versus
Code:my_function();
Do these prototypes have any difference in any way at all?
Quote: Also, I was reading on how the "main" function's return type could be "void". Is it true that the main function's return type can be void? If so, why, and is it different from the integer return type? Thank-you.Yes, the main function can have a return type of void. Declaring an int was used to return a status value back to the DOS batch file that called the executable.
For example, this could be the code for SomeFile.exe:
Code:
int main()
{
int x = 5;
if x == 5 return 1;
}In your batch file you could have something like this:
Code:
SomeFile.exe
IF %ERRORLEVEL% NEQ 0
(
ECHO error - SomeFile.exe returned an error code!!!
)
![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)