[edit]
Been doing some research and my page needs some work. Thanks for the input though. I appreciate it.
[/edit]
[edit]
Been doing some research and my page needs some work. Thanks for the input though. I appreciate it.
[/edit]
Last edited by kermit; 08-31-2003 at 07:02 PM.
Hmmm... I think it's great when people write tutorials, so just consider the following to be me proof reading for you
ackward/confusing wordingThis is not to say that there are not many programmers who need no clarification on functions.
Explain WHAT a function is before you explain how to use it.
You might want to consider throwing in a return after the statements.return-type function-name ( parameter declarations, if any)
{
declarations
statements
}1
Not entirely accurate. Only declare it with a void in C (well, I guess this is on the C board, but people will probably read it for C++ too), or when you want that function to ONLY take 0 parameters.If a function has no parameters when it is defined, then the keyword void should be used. For example,
int main()
Here we have the main function with no parameters given. This will work, but to be correct, it should be written
int main(void)
Windows programs don't have main, they have winmain. They can also be written in C.Every C program has at least one function, that being the main() function. Here is an example of a C program with a main function:
Code:#include <stdio.h> int main(void) { printf( "Hello, cruel world..." ); return 0; } //lol, the board made me put this in code tags
It doesn't?as main does not always return an int.
I could be wrong, but I thought that the operating system expected an int? You might want to just say that other functions can return floats, doubles, pointers, etc. I've never seen main() return a float. (Someone correct me if I'm wrong here)We have already discussed that main() can return different types, the default being int, but it can also return a double or a float etc.
Anyway, it looks pretty good. Revise it and fix up the formatting and stick it on a site You might write some other tutorials as well, if it helps you learn or something.
Away.
you're not wrong the OS or whatever calls the program looks for an integer as a return type. There is a table of integers defined somewhere in the calling program/OS that defines different return codes for example
I could write a program to call a hello world program and if hello world could not be output I could return a -1 instead of 0 and I could write my program to interpret the -1 as a segmentation fault error or something. (However, segmentation faults are usually signals sent to the program that causes it to abort())
however the standard (I believe) desires the return value on a successful run to be 0
main could return a double, float etc. but it would be truncated and the behavior is UNDEFINED. The standard says that main should return an int, this has been discussed so many times its giving even me a headache when people still post void main questions. At least he didn't write void main anywhere and say it was the right way! ^_^
If salem saw it he would probably delete the post and replace it with a big SIGH.
I am not sure but I believe the return value is popped into the stack and read off the stack when the program exits but I could be completely wrong but I think I heard that somewhere before, If I learn of differnet or if someone corrects me I'll edit this post.
-LC
Asking the right question is sometimes more important than knowing the answer.
Please read the FAQ
C Reference Card (A MUST!)
Pointers and Memory
The Essentials
CString lib
The reason I wanted you guys to look at my page was for the critique. I learn a lot of stuff that way. You see now I can go back and fine tune some things. It is very helpful for me, and in the end I am hoping it will help others. I have spent a lot of time looking around here and there on the web for the kind of things that you guys are pointing out to me now. I have not found all the answers, obviously. Anyway, this is good. I will go back and rework some stuff. I am aware that besides tweaking some of the information, that some of it needs to be rewritten so that it is easier to understand. I am not a writer, I'm a carpenter - heh.
Thanks for your input
kermit
Ok, will have to check back on some things about the value that int can return. I am almost certain that I read somewhere that you could return a double, but I gambled when I wrote you could return a float. lol... I knew that somebody would ferret the truth out. I guess that is bad, but its done now.Originally posted by Lynux-Penguin
main could return a double, float etc. but it would be truncated and the behavior is UNDEFINED. The standard says that main should return an int, this has been discussed so many times its giving even me a headache when people still post void main questions. At least he didn't write void main anywhere and say it was the right way! ^_^
If salem saw it he would probably delete the post and replace it with a big SIGH.
-LC
ergh...out of room here...
There is actually a dude with an avatar that is against int main - he promotes void main - heh. I don't use void main.Originally posted by Lynux-Penguin
At least he didn't write void main anywhere and say it was the right way! ^_^
If salem saw it he would probably delete the post and replace it with a big SIGH.
-LC
What is a SIGH?