|
Contributor
|
|
| 26Feb2008,18:17 | #21 |
|
good info
|
|
Go4Expert Member
|
|
| 26Feb2008,18:39 | #22 |
|
good one
|
|
Contributor
|
|
| 5Mar2008,18:36 | #23 |
|
Quote:
Originally Posted by DaWei |
|
Go4Expert Member
|
|
| 7May2008,17:00 | #24 |
|
Quote:
Originally Posted by aisha.ansari84 |
|
Newbie Member
|
|
| 10Jul2008,06:53 | #25 |
|
there is a class Date and a function
the function is non static Date& and *this is same in representation and they are explain plzzzzzzz......... Code:
class Date
{
Date& add_year(int);
Date& add_month(int);
Date& add_day(int);
}
int main()
{
Date a();
a.add_year(1).add_month(2).add_day(2);
return 0;
}
Date& Date::add_year(int n)
{
if(d==29&&m==2&&!leapyear(y+n)
{
d=1;
m=3;
}
y+=n;
return *this;
}
Date& Date::add_month(int n)
{
return *this;
}
Date& Date::add_day(int n)
{
return *this;
}
plzzzzzzzzzzzzz........... Last edited by shabbir; 10Jul2008 at 09:32.. Reason: Code block |
|
Go4Expert Member
|
|
| 28Jan2011,00:27 | #26 |
|
A pointer can be re-assigned any number of times while a reference can not be reassigned after initialization.
A pointer can point to NULL while reference can never point to NULL You can't take the address of a reference like you can with pointers There's no "reference arithmetics" (but you can take the address of an object pointed by a reference and do pointer arithmetics on it as in &obj + 5). As a general rule, Use references in function parameters and return types to define attractive interfaces. Use pointers to implement algorithms and data structures. |
|
Ambitious contributor
|
![]() |
| 29Jan2011,19:05 | #27 |
|
Shishir pointed out in the very first post of this discussion that " Its not necessary to initialize the pointer at the time of declaration". I think its not mandatory but still we should always make sure that a pointer is initialized to NULL whenever it is declared because :
Code:
int main()
{
char *ptr;
int retval = 0;
retval = someFunc();
if(retval)
ptr = "I got some address";
someOtherFunc(ptr);
}
void someOtherFunc(char *ptr)
{
if(ptr)
{
// use ptr
}
}
|
|
Banned
|
|
| 3Feb2011,14:48 | #28 |
|
1. A pointer can be re-assigned any number of times while a reference can not be reassigned after initialization.
2. A pointer can point to NULL while reference can never point to NULL 3. You can't take the address of a reference like you can with pointers 4. There's no "reference arithmetics" (but you can take the address of an object pointed by a reference and do pointer arithmetics on it as in &obj + 5). 1) A pointer can be re-assigned: int x = 5; int y = 6; int *p; p = &x; p = &y; *p = 10; assert(x == 5); assert(y == 10); A reference cannot, and must be assigned at initialization: int x = 5; int y = 6; int &r = x; A pointer needs to be dereferenced with * to access the memory location it points to, whereas a reference can be used directly. A pointer to a class/struct uses -> to access it's members whereas a reference uses a . A pointer is a variable that holds a memory address. Regardless of how a reference is implemented, a reference has the same memory address the item it references. References cannot be stuffed into an array, whereas pointers can be (Mentioned by user @litb) |
|
Banned
|
|
| 1Mar2011,12:40 | #29 |
|
Hello dear
Pointers and references are the different 1. pointers use the “*” and “->” operators and references use “.“ 2. A pointer can be re-assigned any number of times while a reference can not be reassigned after initialization. 3.A pointer can point to NULL while reference can never point to NULL 4. You can't take the address of a reference like you can with pointers 5. There's no "reference arithmetics" (but you can take the address of an object pointed by a reference and do pointer arithmetics on it as in &obj + 5). |
|
Go4Expert Member
|
|
| 8Mar2011,12:10 | #30 |
|
Really nice tutorial, thanks for sharing!!..
|

