---
title: "Comment by Luke Li on \"Dubious code using pre-increment operator in C++\" | Hashnode"
description: "This is undefined behavior in C++ and you should never write code like this, and do not bother to make sense of the compiler&#39;s output, it&#39;s a waste of t"
url: "https://hashnode.com/posts/dubious-code-using-pre-increment-operator-in-c/637cf801de1a8abc80caf993/comment/638401ed43c7ea1599a5f216"
---

[Discussion](https://hashnode.com/posts/dubious-code-using-pre-increment-operator-in-c/637cf801de1a8abc80caf993)

Comment [Dubious code using pre-increment operator in C++](https://hashnode.com/posts/dubious-code-using-pre-increment-operator-in-c/637cf801de1a8abc80caf993)

[Luke Li](https://hashnode.com/@infgeoax)

[Nov 28, 2022](https://hashnode.com/posts/dubious-code-using-pre-increment-operator-in-c/637cf801de1a8abc80caf993/comment/638401ed43c7ea1599a5f216)

This is undefined behavior in C++ and you should **never** write code like this, and do not bother to make sense of the compiler's output, it's a waste of time.

It boils down to "unsequenced multiple modifications" to the same memory location `n`, i.e. they can happen in any order.

P.S. Always add `-Wall` when compiling with gcc.
