| |

VerySource

 Forgot password?
 Register
Search
View: 15|Reply: 6

Pointer problem

[Copy link]

1

Threads

1

Posts

2

Credits

Newbie

Rank: 1

Credits
2

 China

Post time: 2020-3-8 14:00:02
| Show all posts |Read mode
char * s1, * s2, * p;
* (p-s1 + s2) can be compiled and passed
But * (s2 + p-s1) does not compile, why?
Reply

Use magic Report

0

Threads

66

Posts

43

Credits

Newbie

Rank: 1

Credits
43

 Invalid IP Address

Post time: 2020-5-28 21:15:01
| Show all posts
The two pointers are subtracted to get an integer. The integer can be added to the pointer, but the two pointers cannot be added.
Reply

Use magic Report

0

Threads

66

Posts

43

Credits

Newbie

Rank: 1

Credits
43

 Invalid IP Address

Post time: 2020-5-29 00:30:01
| Show all posts
In addition, the priority of "+" and "-" are the same, and they are all left-associated, so for the expressions in those two brackets, the compiler tries to understand from the left to the right. Report an error.
Reply

Use magic Report

2

Threads

49

Posts

30

Credits

Newbie

Rank: 1

Credits
30

 China

Post time: 2020-5-29 08:00:02
| Show all posts
And it must be a pointer to an array to perform pointer arithmetic
Reply

Use magic Report

2

Threads

49

Posts

30

Credits

Newbie

Rank: 1

Credits
30

 China

Post time: 2020-5-31 09:00:01
| Show all posts
Are two pointers to the same array, so it makes sense to perform calculations between the pointers,
The behavior of pointer arithmetic between two pointers is undefined
Grammatically, it is "possible", but logically it is "undefined", which means that the calculation result is meaningless, which is more accurate.
Reply

Use magic Report

0

Threads

25

Posts

21

Credits

Newbie

Rank: 1

Credits
21

 China

Post time: 2020-5-31 10:45:01
| Show all posts
Not too boring, adding two pointers is meaningless.
Reply

Use magic Report

0

Threads

51

Posts

40

Credits

Newbie

Rank: 1

Credits
40

 Invalid IP Address

Post time: 2020-6-4 10:30:01
| Show all posts
Pay attention to the error prompts given by the compiler.
Reply

Use magic Report

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

Points Rules

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

Quick Reply To Top Return to the list