
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Precedence of postfix ++ and prefix ++ in C/C++
Here we will see the precedence of postfix++ and prefix++ in C or C++. The precedence of prefix ++ or -- has higher priority than dereference operator ‘*’ and postfix ++ or -- has priority higher than both prefix ++ and dereference operator ‘*’.
When ptr is a pointer, then *ptr++ indicates *(ptr++) and ++*prt refers ++(*ptr)
Example
#include<iostream> using namespace std; int main() { char arr[] = "Hello World"; char *ptr = arr; ++*ptr; cout << *ptr; return 0; }
Output
I
So here at first ptr is pointing ‘H’. after using ++*ptr it increases H by 1, and now the value is ‘I’.
Example
#include<iostream> using namespace std; int main() { char arr[] = "Hello World"; char *ptr = arr; *ptr++; cout << *ptr; return 0; }
Output
e
So here at first ptr is pointing ‘H’. after using *ptr++ it increases the pointer, so ptr will point to the next element. so the result is ‘e’.
- Related Articles
- Difference between prefix and postfix operators in C#?
- Prefix to Postfix Conversion in C++
- Prefix and Postfix Expressions in Data Structure
- What is the difference between prefix and postfix operators in C++?
- Differentiate between the prefix and postfix forms of the ++ operator in java?
- Operator Precedence and Associativity in C
- Operators Precedence in C++
- C++ Operators with Precedence and Associativity
- Postfix to Infix in C++
- match_results prefix() and suffix() in C++
- What is C Operator Precedence and Associativity?
- What are postfix operators in C++?
- What are postfix operators in C#?
- What is Evaluation, Precedence and Association in C language?
- Evaluation of Prefix Expressions in C++

Advertisements