cpp tips
various usage of const keyword with variable:
1.char* const ptr1 ="Good";
2.int const *ptr2 = &m ; //content is constant
3.const char* const cp = "xyz" ; //Both address and content is constant
can u differentiate the above three usage ?
...
Ans :
1.char* const ptr1 ="Good"; //address is constant
2.int const *ptr2 = &m ; //content is constant
3.const char* const cp = "xyz" ; //Both address and content is constant
Is there any difference between new() and malloc() ?
new operator advantages than malloc :
1.new operator will automatically computes the size of the object.
No need to use sizeof() operator.
2.It automatically returns the correct pointer type. So there is no need to use a type cast.
3.It is possible to initialize the object while creating the memory space.
4. like any other operator, new operator can be overloaded.
1.char* const ptr1 ="Good";
2.int const *ptr2 = &m ; //content is constant
3.const char* const cp = "xyz" ; //Both address and content is constant
can u differentiate the above three usage ?
...
Ans :
1.char* const ptr1 ="Good"; //address is constant
2.int const *ptr2 = &m ; //content is constant
3.const char* const cp = "xyz" ; //Both address and content is constant
Is there any difference between new() and malloc() ?
new operator advantages than malloc :
1.new operator will automatically computes the size of the object.
No need to use sizeof() operator.
2.It automatically returns the correct pointer type. So there is no need to use a type cast.
3.It is possible to initialize the object while creating the memory space.
4. like any other operator, new operator can be overloaded.
Labels: Cpp
0 Comments:
Post a Comment
<< Home