search
HomeCommon ProblemWhat is the difference between *p++ and (*p)++

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.

What is the difference between *p++ and (*p)++

# 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:

  1. *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.

  2. (*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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.