Scope: Gosh how I hate dealing with scopes. Anything you declare inside of one scope is inaccessible outside of it.
1 2 3 4 5 6 7 8 9 10
|
void Function()
{
cout << “Hello World << endl;
{
cout << “Body inside function body” << endl;
int x = 0; //Let's declare x
}
x = 4; //oops, "x" is not in scope, so we cannot access it out here.
}
|
You don't have to use a "new" body inside a function (with some exceptions - like exceptions or blocks of code (inside a for-loop, an if-statement block, etc)).
2: As far as I know, no. Both will accomplish the same goal (maybe someone with more skill than I posses can answer this in more depth).
3: I have never used "sizeof" other than finding the size of a type. I don't really know of any other reason to use it.
4: Use "inline" when you NEED to increase speed. It replaces the function call with the code of the function. Function calls are costly in terms of time (it takes a "relatively" long time to call a function - passing arguments, waiting for returns, etc), so using "inline" can really increase speed, but it comes at the cost of space. Using "inline" will increase the size of your program (by a lot if you use it a lot or the function is a really long one). You sacrifice one thing for another - it depends on which is more important to you, space or time.
5: Structs. I don't use them - I always define classes (the two are similar, with some differences).
object names at the end before the semi colon allows you to declare objects of that struct at the same time you are defining the struct. You do not have to do that, but it is an option.
Some more info on structs:
http://www.cplusplus.com/doc/tutorial/structures/