The difference is: the timing of incrementing the value of variable "a" is different; "a" and "a" are both auto-increment operators; "a" takes the value first and then increments it "1"; "a" is first incremented by "1" and then taken.
a and a are both auto-increment operators. The difference is that the timing of incrementing the value of variable a is different. a is taken first and then incremented. a is auto-incremented first and then taken.
Example
For example: Suppose x=3, y=4;
(1) (x) (x)=8
Explanation: For the first (x), because x takes the value first and then increments, the value obtained by (x) is 3, and then x increments, at this time x=4; for the first Two (x), because x is incremented first and then takes the value, so the value obtained by (x) is 5. At this time, x=5, so the result is 8.
(2) (x )/3 (--y)*2-(x--)%6 (y )*3-(y--)
1 6-4 9-4=8
Explanation: First (x) takes the value 3, then x=4; then (--y) takes the value 3, at this time y=3; Then (x--) takes the value 4, then x=3; then (y) takes the value 3, then y=4; finally (y--) takes the value 4, then y=3;
Note :() can increase the arithmetic priority, so the expression in the brackets is calculated first, but the value of x is x, and then x is incremented.
Key points: The operation priority is very high
Interview question:
int i = 10 i = i++ ;
At this time, what is the value of i?
Answer: The value of input i is 10
Analysis: First, the value of i is 10, then i is incremented, at this time, i=11, and finally the value is assigned. So the final output value of i is 10.
For more related knowledge, please visit PHP Chinese website! !
The above is the detailed content of What is the difference between a++ and ++a?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software