C++ Programming Question and Answers

26. Write the characteristics of member functions?
 
  • Data members are the data variables that represent the features or properties of a class.
  • Member functions are the functions that perform specific tasks in a class.
  • Member functions are called as methods, and data members are also called as attributes.
 
Your Name Your Email-ID
Your Answer
27. Explain Stack and Heap Objects?
  The memory a program uses is divided into four areas:
  • The code area: this is where the compiled program sites in memory.
  • The global area: the place where global variables are stored.
  • The heap: the place where dynamically allocated variables are allocated from.
  • The stack: the place where parameters and local variables are allocated from.
 
Your Name Your Email-ID
Your Answer
28. What is Polymorphism?
  Polymorphism means that some code or operations or objects behave differently in different contexts. In C++, following features support polymorphism.
  • Compile Time Polymorphism: means compiler knows which function should be called when a polymorphic call is made. C++ supports compiler time polymorphism by supporting features like templates, function overloading and default arguments.
  • Run Time Polymorphism: is supported by virtual functions. The idea is virtual functions are called according to the type of object pointed or referred, not according to the type of pointer or reference. In other words, virtual functions are resolved late, at runtime.
 
Your Name Your Email-ID
Your Answer
29. What is the use of void type?
  Void type has two important purposes:
  • To indicate that a function does not return a value.
  • To declare a generic pointer.
 
Your Name Your Email-ID
Your Answer
30. What is the main purpose of using function prototype?
 
  • The main purpose of function prototype is to help the compiler to check the data requirement of the function. With function prototyping, a template is always used when declaring and defining a function.
  • When a function is called, the compiler uses the template to ensure that proper arguments are passed, and the return value is treated correctly.
  • Any violation in matching of the arguments or the return types will be treated as errors by compiler, and flagged at the time of compilation.
 
Your Name Your Email-ID
Your Answer
123456789101112


131415 Page 6 of 15