Virtual functions in C++


 C++ virtual function is a member function of a class, whose functionality can be over-ridden in its derived classes. The whole function body can be replaced with a new set of implementation in the derived class. The concept of c++ virtual functions is different from C++ Function overloading.

C++ Virtual Function - Properties:

   C++ virtual function is,
  • A member function of a class
  • Declared with virtual keyword
  • Usually has a different functionality in the derived class
  • A function call is resolved at run-time
   The difference between a non-virtual c++ member function and a virtual member function is, the non-virtual member functions are resolved at compile time. This mechanism is called static binding. Where as the c++ virtual member functions are resolved during run-time. This mechanism is known as dynamic binding.

C++ Virtual Function - Reasons:

   The most prominent reason why a C++ virtual function will be used is to have a different functionality in the derived class.
   For example a Create function in a class Window may have to create a window with white background. But a class calledCommandButton derived or inherited from Window, may have to use a gray background and write a caption on the center. The Create function for CommandButton now should have a functionality different from the one at the class called Window.

C++ Virtual function - Example:

   This article assumes a base class named Window with a virtual member function named Create. The derived class name will be CommandButton, with our over ridden function Create.
     class Window // Base class for C++ virtual function example
     {
       public:
          virtual void Create() // virtual function for C++ virtual function example
          {
               cout <<"Base class Window"<

     class CommandButton : public Window
     {
       public:
          void Create()
          {
              cout<<"Derived class Command Button - Overridden C++ virtual function"<create();="" x="new" y->create();="" y="new" {="" };="" }<="" }="">

Vivid Technologies Interview Questions


1. What is the diff. between pointer variable and reference variable
2. What is static library and dynamic library
3. What is soft link
4. What is virtual function in C++
5. What is polymorphism in C++
6. What is the diff between Inline and Macro
7. What is the output of $WC | ls –l > file

Where does global static local register variables free memory and C Program instructions get stored?


Local Variables    are stored in Stack.
 Register variables are stored in Register. 
Global & static variables are stored in data segment. 
The memory created dynamically are stored in Heap  And 
The C program instructions get stored in code segment.
  

To be a good programmer is very necessary to understand the memory structure.


Memory organization


(1) What is memory cell?
Answer:

Entire RAM has divided in number of equal part, which is known as memory cell.Capacity of each cell is to store one-byte data.
i.e char a reserve one memory cell while float a reserve four memory cell.
Each memory cell has unique address.Address are always in whole number an increasing order.

(2) What is residence memory?


Answer:


RAM has divided into two parts:
(1) Extended memory (useless)
(2) Residence memory :
When any program is executed it is stored in the residence memory .For turbo c, it has 1MB residence memory i.e when we open turbo c it store 1MB in the RAM.

(3) What is physical address ?



Answer: 





20 bit address of the memory cell is known as physical address or real address.In 20 bit we can represent address from 0x00000 to 0xFFFFF.

(4) What is segmentation?

Ans:



Residential memory of RAM of size 1MB has divided into 16 equal part.These part is called segment.Each segment has size is 64KB.
1MB=16*64KB
This process of division is known as segmentation.

(5) What is necessity of segmentation?

Ans:

Physical address are 20 bit.But we have no pointer of 20 bit.So pointer can not access whole residential address .So to solve this problem we have three different pointer and segmentation has done.

Difference between .com program and .exe program. AND Warning code in c programming


Difference between .com program and .exe program.
Answer:
Both .com and .exe program are executable program but .com program execute faster than .exe program. All drivers are .com program.


Warning code in c programming

S.N.
Warning message
Code
ANSI Violations
1
Assigning 'type' to 'enumeration'
eas
2
Bit fields must be signed or unsigned int
bbf
3
Both return and return with a value used
ret
4
Declare type 'type' prior to use in prototype
dpu
5
Division by zero
zdi
6
Hexadecimal value contains more than 3 digits
big
7
Initializing 'enumeration' with 'type'
bei
8
'identifier' is declared as both external and static
ext
9
Ill-formed pragma
ill
10
Initialization is only partially bracketed
pin
11
Redefinition of 'macro' is not identical
dup
12
Suspicious pointer conversion
sus
13
Undefined structure 'structure'
stu
14
Void functions may not return a value
voi
Frequent Errors
1
Code has no effect
eff
2
Function should return a value
rvl
3
Parameter 'parameter' is never used
par
4
Possible use of 'identifier' before definition
def
5
Possibly incorrect assignment
pia
6
Unreachable code
rch
Less Frequent Errors
1
Ambiguous operators need parentheses
amb
2
Array variable 'identifier' is near
ias
3
Call to function with no prototype
pro
4
Call to function 'function' with no prototype
pro
5
Condition is always false
wccc
6
Condition is always true
wccc
7
'identifier' declared but never used
use
8
'identifier' is assigned a value that is never used
aus
9
No declaration for function 'function'
nod
10
Structure passed by value
stv
11
Superfluous & with function
amp
Portability Warnings
1
Constant is long
cln
2
Constant out of range in comparison
rng
3
Conversion may lose significant digits
sig
4
Non portable pointer comparison
cpt
5
Non portable pointer conversion
rpt
6
Mixing pointers to signed and unsigned char
ucp