Thursday, December 30, 2010

#include"problem8.h"

What is the type of this pointer and when does a this pointer get created?

Monday, December 27, 2010

#include"problem7.h"

What is a dangling pointer?

Ans:

Suppose we allocate a chunk of memory and store its address in a pointer. If this chunk of memory is freed and if the pointer continues to point to that location, the pointer is said to be a dangling pointer.

Example:
#include<iostream.h>
void main()
{
int *p;
int *q=new int;
p=q;
delete q;
//code
}

Explanation:
Here the p and q are pointing to the same memory location.After delete q statement p becomes a dangling pointer.As p is pointing to the deleted memory location.

Saturday, December 25, 2010

#include"problem6.h"

What is interface?


Ans:
 An interface is a named collection of method definitions without implementations.


Ex:
 The interface of the keyboard always look like same...But the keys are implemented as mechanical or capacitor based internally... 

Friday, December 24, 2010

#include"problem5.h"

What is the difference between classes and objects?

Ans:
A class is a blueprint for objects. From one class several objects can be created.
Each object is know as an instance of a particular class.

Simple term:
'Cricketers' is a class whereas 'Sachin','Ganguly' are instances of 'Cricketer' class (hence they are objects).

Programmers term:

In "int i",'int' is a class where as 'i' is an object.
In user defined class 'employee' is a class where as e1,e2,e3 are objects. 

Thursday, December 23, 2010

#include"problem4.h"

How many ways we can pass variable to a function?

Ans: There are three ways in which we can pass variables to a function:

1)By Value
   void fun(int,int); //declaration
   fun(a,b); //call
   void fun(int x,int y) //definition
   {statements;}

Explanation:
    Here the values of a and b will be passed, which is assigned to x and y.
    Changing the values of x and y will not affect the values of a and b.
    x and y are additionally created(occupies memory) as integers.

2)By Reference
   void fun(int&,int&); //declaration
   fun(a,b); //call
   void fun(int &x,int &y) //definition
   {statements;}

Explanation:
    Here the variable is itself passed and its address is captured by the function.
    Changing the values of x and y will affect the values of a and b.
    x and y are not created(dont occupies memory).
 

3)By Address
   void fun(int*,int*); //declaration
   fun(&a,&b); //call
   void fun(int *x,int *y) //definition
   {statements;}

Explanation:
    Here the address of the variables are passed and it is captured by pointer of the same type.
    Changing the values of *x and *y will affect the values of a and b.
    x and y are additionally created(occupies memory) as integer pointers.       

Wednesday, December 22, 2010

#include"problem3.h"

What is the difference between VB and VC++?

Ans:

VB is Object-Based-Language
VC++ is Object-Oriented-Language

Object-Based-Language : Languages that supports only objects and classes
Object-Oriented-Language : Along with the Objects and classes it supports features like inheritance and polymorphism

Tuesday, December 21, 2010

#include"problem2.h"

#include<iostream.h>
int i=5;
void main
{
  int i=10;
  cout<<i<<endl<<::i;
   {
      int i=15;
      cout<<endl<<i<<endl<<::i;
   }
}

Output:
10
5
15
5
Explanation:
i always prints the local variable of that particular scope
::i always prints the global variable