Thursday, 3 March 2011

56. Difference between pointer and reference


POINTER
1.   Its not necessary to initialize the pointer at the time of declaration. Like
      Code:
     int a=10;
     int *p=&a; //it is not necessary
Another way is:
   Code:
   int a=10;
   int *p;
   p=&a;
2.   You can create the array of pointer.
3.   You can assign NULL to the pointer like
   Code:
   int *p=NULL; //valid
4.   You can use pointer to pointer.

REFERENCE:

1.   Its necessary to initialize the Reference at the time of declaration. Like
      Code:
      int &a=10
      int &a; //Error here but not in case of pointer.
2.   You can not create the Array of reference.
3.   You can not assign NULL to the reference like.
    Code:
    int &a=NULL; //Error
4.   You can not use reference to reference.

55. Difference between C and C++

Ø  In case of C, the data is not secured while the data is secured(hidden) in C++
Ø  C is a low-level language while C++ is a middle-level language
Ø  C is function-driven while C++ is object-driven
Ø  C++ supports function overloading while C does not
Ø  We can use functions inside structures in C++ but not in C.
Ø  The NAMESPACE feature in C++ is absent in case of C
Ø  The standard input & output functions differ in the two languages
Ø  C++ allows the use of reference variables while C does not

54.Difference between class and structure

1.   Classes are usually used for large amounts of data, whereas structs are usually used for smaller amount of data.
2.   Classes could be inherited whereas structures no
3.   A structure couldn't be Null like a class.
4.   A structure couldn't have a destructor such as class.
5.   A structure can't be abstract, a class can.
6.   You can't use sizeof with classes but you can with structures.
7.   The structure can't contain a volatile field wheatears the class does.
8.   classes support polymorphism, whereas structures do not.