I am a bit confused about void main() vs int main().
My book says the void is included when the function returns no value. Can someone explain to me what is meant by "returns no value."
I am a bit confused about void main() vs int main().
My book says the void is included when the function returns no value. Can someone explain to me what is meant by "returns no value."
The simple rule of thumb is to use int main because it is undeniably standard.
As for "returns no value": do you know what is meant by "a function returns a value"?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
The keay word void means that the function does not return any value but int means that the function returns an integer value..
As in, what do you know about calling and defining functions where return values are concerned? If you don't know anything, then you should re-read the part of your book that talks about it.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Yes, that is incorrect. Control returns to the caller, i.e., the function that called the function.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I think that's what I meant, but phrased poorly.
So in the following program:
Code:int stringLength (const char string[]) { int count = 0; while ( string[count] != '\0' ) ++count; return count; } int main (void) { int stringLength (const char string[]); const char word1[] = { 'a', 's', 't', 'e', 'r', '\0' }; const char word2[] = { 'a', 't', '\0' }; const char word3[] = { 'a', 'w', 'e', '\0' }; printf ("%i %i %i\n", stringLength (word1), stringLength (word2), stringLength (word3)); return 0; }
the stringLength function returns the value of count for each word array defined. Basically the value of count is stringlength (word).
So the value that is returned is equal to the function(respective argument)?
Yes.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)