Q: Are the standard library I/O functions still available for use with
the C++ iostreams library?
A: Yes, using
#include
functions such as printf() and scanf() will continue to be
available. However, using them in conjunction with stream oriented
functions can lead to unpredictable behaviour.
Q. In C++, given two variables of the same name, one local and one global,
how do I access the global instance within the local scope?
A. Use the scope (::) operator.
int x = 10;
for(int x=0; x < ::x; x++)
{
cout << "Loop # " <<>
}
Q. Will the following two functions be overloaded by the compiler, or
will the compiler flag it as an error? Why?
void test( int x, double y); & int test( int a, double b);
A. The compiler will flag this as a redeclaration error because
neither return types nor argument names are considered when determining
unique signatures for overloading functions. Only number and type
of arguments are considered.
Q. If I pass a character to a function which only accepts an int,
what will the compiler do? Will it flag it as an error?
A. No. The compiler will promote the char to an int and use the integer
representation in the function instead of the character itself.
Q. I was trying to allocate an array of function pointers using the new
operator but I keep getting declaration syntax errors using the following
syntax: new int(*[10])(); What's wrong?
A. The new operator is a unary operator and binds first to the int keyword
producing the following: (new int) (*[10])();
You need to put parentheses around the expression to produce the
expected results: new (int (*[10]());
Q. What are inline functions? What are their advantages? How are they
declared?
A. An inline function is a function which gets textually inserted by
the compiler, much like macros. The advantage is that execution time
is shortened because linker overhead is minimized. They are declared
by using the inline keyword when the function is declared:
No comments:
Post a Comment