some basic questions about C++

This is a discussion on some basic questions about C++ within the C++ Programming forums, part of the General Programming Boards category; Hi
Please help me with the following queries to understand C++ conceptually. It would be really nice of you if ...

some basic questions about C++

Please help me with the following queries to understand C++ conceptually. It would be really nice of you if you keep your explanation simple so that I can understand it.

1: What is a 'library function'? Is it the function included in the standard C++ library - i.e. the header #include <cstdlib>?

2: What is the difference between a function and function call?

3: Can I say the function "int main()" is the 'mother' function and all (or, most others) are its children functions such as sqrt()?

4: The book says:Library Function exit()
This function causes the program to terminate, no matter where it is in the listing.It has no return value. Its single argument, 0 in our example, is returned to the operating system when the program exits. (This value is useful in batch files, where you can use the ERRORLEVEL value to query the return value provided by exit(). The value 0 is normally used for a successful termination; other numbers indicate errors.)

What is "return value"? So far I have only seen int main() with which "return 0;" is used, and that too I have been told is optional.

Using exit(0), exit(1), exit(2),..., doesn't affect the working of the below given code but the above passage says only "0" value is used for successful termination.

5: The book says:The last statement in the function body is return 0;. This tells main() to return the value 0 to whoever called it, in this case the operating system or compiler. In older versions of C++ you could give main() the return type of void and dispense with the return statement, but this is not considered correct in Standard C++.

I don't understand it. What is "void"?

Is return 0; a kind of signal at the end or somewhere else to tell that the job has been done and it's time to call it a day. Suppose if you have return 0; at the end of the code then the return 0; statement would only be reached when the execution of the code has successfully executed the above lying statements and once reached it tells job is done.

3: Can I say the function "int main()" is the 'mother' function and all (or, most others) are its children functions such as sqrt()?

What is your definition of "mother function"? What does it mean?

What is "return value"? So far I have only seen int main() with which "return 0;" is used, and that too I have been told is optional.

Consider:

Code:

int foo() { return 5; }
int main()
{
int ret = foo();
}

The return value of foo is what foo returns, in this case. In main, the variable ret will hold the return value for foo.

Using exit(0), exit(1), exit(2),..., doesn't affect the working of the below given code but the above passage says only "0" value is used for successful termination.

exit is simply a function that terminates your program. Typically, your program will end when the main function ends, but you can force it to end before (typically not recommended, however).
Whatever you send as argument to exit will be the return value of the program. 0 is typically used to indicate success, but there is no standard, so it can be whatever you mean it to be.
The return value of a program is basically some information some other program can acquire to know the status of success of an executed program.

I don't understand it. What is "void"?

void is a return type, just as int.
Example:

Code:

void foo1();
int foo2();

foo1 returns nothing (hence void).
foo2 returns an int.

Is return 0; a kind of signal at the end or somewhere else to tell that the job has been done and it's time to call it a day. Suppose if you have return 0; at the end of the code then the return 0; statement would only be reached when the execution of the code has successfully executed the above lying statements and once reached it tells job is done.

No. A return statement simply says that the currently executing function shall end and it may return a value.
The caller of this function can then store whatever this function returned.
0 is not a special number; it can be anything you want and you must decide on how to interpret it.

Thanks a lot, Elysia. It was very helpful indeed. Though I do have some follow-on questions, I think it's better to first digest well the material I have been given in your previous post. Once again, thanks.

3: Can I say the function "int main()" is the 'mother' function and all (or, most others) are its children functions such as sqrt()?

You should say that main is the entry point, since that is true unless there are (user defined) global objects. An entry point is where a program begins executing, which is probably what you mean. If there are global objects though, then technically the first one defined would be the entry point. Other functions would be children of main if main calls them. If you use parent and children while talking to someone about functions, you might get an odd response: parent and children usually refer to processes, instead. A parent process spawns a child process.

1: What is a 'library function'? Is it the function included in the standard C++ library - i.e. the header #include <cstdlib>?

For someone who isn't working on a team of programmers, a library function is pretty much anything you call that you didn't write yourself.

2: What is the difference between a function and function call?

What's the difference between a car, and driving a car? Same thing.

3: Can I say the function "int main()" is the 'mother' function and all (or, most others) are its children functions such as sqrt()?

You can say anything you like. If you want to talk about a call graph which depicts the caller/callee relationships between functions, then yeah, you can think of main() as a parent and sqrt() as a child, but it depends on the code.

I don't understand it. What is "void"?

void is nothing. In certain places in the language, a type name is required. "void" is the type name you use when you mean "nothing." This is unrelated to "void *" which means a pointer to an unspecified type, not "pointer to nothing."