The difference between *p and (*p) is: 1. *p is a combination of postfix increment operators, (*p) is a postfix increment operator applied to *p expression; 2. *p The expression first returns the value pointed to by "p" and then increments "p", (*p) returns the value pointed to by "p" and then increments that value.
# Operating system for this tutorial: Windows 10 system, C18 version, Dell G3 computer. The difference between
*p and (*p)
*p and (*p) are two different expressions:
*p: This is a combination of postfix increment operators. First, the *p expression will dereference the pointer p and return the value pointed to by the pointer. Then, the pointer p is incremented and points to the next element. Therefore, this expression first returns the value pointed to by p and then increments p.
(*p) : This is a postfix increment operator applied to the *p expression. First (*p) dereferences the pointer p and returns the value pointed to by the pointer. Then, the value is incremented. Therefore, this expression first returns the value pointed to by p and then increments that value.
Here is a sample code to illustrate the difference between the two:
#include <iostream> int main() { int arr[] = {1, 2, 3}; int* p = arr; std::cout << *p++ << std::endl; // 输出: 1 std::cout << *p << std::endl; // 输出: 2 p = arr; std::cout << (*p)++ << std::endl; // 输出: 1 std::cout << *p << std::endl; // 输出: 2 return 0; }
In the above example, *p outputs p first The value pointed to is 1, then p is incremented to the next element, and now p points to 2. And (*p) first outputs the value pointed to by p, 1, and then increments the value. Now the value pointed by p is 2. This shows the difference between the two.
The above is the detailed content of What is the difference between *p++ and (*p)++. For more information, please follow other related articles on the PHP Chinese website!