13. What is inline function?
When you call the function, execution of the program jumps to those instructions, and when the function returns, execution jumps back to the next statement in the calling function. Performance degradation occurs in jumping into and out of functions. When a function is small, the program can be speeded-up using inline functions. The use of inline functions avoids have the program jump into and out of the same function over and over again.If a function is declared with the keyword 'inline', the compiler does not create a real function; it copies the code from the inline function directly into the calling function. No jump is made.
14. List down the advantages of class templates
• One C++ Class Template can handle different types of parameters.
• Compiler generates classes for only the used types. If the template is instantiated for int type, compiler generates only an int version for the c++ template class.
• Templates reduce the effort on coding for different data types to a single set of code.
• Testing and debugging efforts are reduced.
15. Write a short notes on recursion with example.
Recursion is defined as a function calling itself. It is in some ways similar to a loop because it repeats the same code, but it requires passing in the looping variable and being more careful. Many programming languages allow it because it can simplify some tasks, and it is often more elegant than a loop. void recurse()
{
recurse();
}
void main()
{
recurse();
}
16. Is it possible to accept command line argument in C++?
Yes, In C++ it is possible to accept command line arguments. To do so, you must first understand the full definition of int main(). It actually accepts two arguments, one is number of command line arguments, the other is a listing of the command line arguments. Ex.
int main( int argc, char *argv[])
17. Explain typecasting.
Typecasting is making a variable of one type, such as an int, act like another type, a char, for one single operation. To typecast something, simply put the type of variable you want the actual variable to act as inside parentheses in front of the actual variable. (char)a will make 'a' function as a char.
18. What's the difference between public, private and protected?
• A member (either data member or member function) declared in a private section of a class can only be accessed by member functions and friends of that class
• A member (either data member or member function) declared in a protected section of a class can only be accessed by member functions and friends of that class, and by member functions and friends of derived classes
• A member (either data member or member function) declared in a public section of a class can be accessed by anyone
19. What are some advantages/ disadvantages of using friend functions?
Member functions and friend functions are equally privileged. The major difference is that a friend function is called like f(x), while a member function is called like x.f(). Thus the ability to choose between member functions (x.f()) and friend functions (f(x)) allows a designer to select the syntax that is deemed most readable, which lowers maintenance costs. The major disadvantage of friend functions is that they require an extra line of code when you want dynamic binding.
20. What's the difference between the keywords struct and class in c++?
The members and base classes of a struct are public by default, while in
No comments:
Post a Comment