Home
31.
Why not inline every function? It increases execution speed, right?

That really depends. However, inlining every function results in functions that are used in multiple places to be placed at the point where they're called, and this results in code bloat. That apart, most modern compilers are better judges of what calls can be inlined and do so for the programmer, depending on the compiler's performance settings.

32.
Can I supply default parameter values to all parameters in a function?

Yes, that is definitely possible and recommended when that makes sense.

33.
I have two functions, both called Area. One takes a radius and the other takes height. I want one to return float and the other to return double. Will this work?

Function overloading needs both functions with the same name to also have the same return types. In this case, your compiler shows an error as the name has been used twice in what it expects to be two functions of different names.

34.
What is the scope of variables declared in a function's prototype?

The scope of these variables is the life of the function.

35.
What is the nature of the value passed to this function?
int Func(int &someNumber );

someNumber is a reference to the variable in the calling function. It does not hold a copy.

36.
Why dynamically allocate when you can do with static arrays where you don't need to worry about deallocation?

Static arrays have a fixed size and will neither scale upward if your application needs more memory nor will they optimize if your application needs less. This is where dynamic memory allocation makes a difference.

37.
I have two pointers:
int* pointToAnInt = new int;
int* pCopy = pointToAnInt;
Am I not better off calling delete using both to ensure that the memory is gone?

That would be wrong. You are allowed to invoke delete only once on the address returned by new. Also, you would ideally avoid having two pointers pointing to the same address because performing delete on any one would invalidate the other. Your program should also not be written in a way that you have any uncertainty about the validity of pointers used.

38.
When should I use new(nothrow)?

If you don't want to handle the exception std::bad_alloc, you use the nothrow version of operator new that returns NULL if the requested allocation fails.

39.
I can call a function to calculate area using the following two methods:
void CalculateArea (const double* const ptrRadius, double* const
ptrArea);
void CalculateArea (const double& radius, double& area);
Which variant should I prefer?

Use the latter one using references, as references cannot be invalid, whereas pointers can be. Besides, it's simpler, too.

40.
Why should I bother passing values to a function by reference?

You don't need to so long as it doesn't affect your program performance much. However, if your function parameters accept objects that are quite heavy (large in bytes), then passing by value would be quite an expensive operation. Your function call would be a lot more efficient in using references. Remember to use const generously, except where the function needs to store a result in a variable.