| |

VerySource

 Forgot password?
 Register
Search
Author: 112233qwe

About pointers and references

[Copy link]

0

Threads

23

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-2-1 00:00:02
| Show all posts
Moreover, as I said in my first reply, the existence of null pointers will inevitably lead to the existence of "null references"
Reply

Use magic Report

0

Threads

11

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-2-1 18:54:02
| Show all posts
1.Passed a reference to int&a;
The first sentence in the function is int * p =&a;
After that, all operations are performed on p, so there is no difference from passing pointers.
2.Pass a pointer int * p;
The first sentence in the function is int&a = * p;
After that, all operations are performed on a, so there is no difference from passing by reference.
3.If you say
int * p = NULL;
int * p = (int *) 1;
Is dangerous
4, then
int&a = * ((int *) 0);
int&a = * ((int *) 1);
Also dangerous

In favor ofverance, I personally feel that pointers and references have no essential difference except for writing.
Reply

Use magic Report

0

Threads

24

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-2-1 20:45:02
| Show all posts
They are similar to each other. In fact, references are also implemented by pointer methods at the bottom.
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-2-10 20:45:01
| Show all posts
Thank you
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list