- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between ++*p, *p++ and *++p in C
Pointer Airthmetics
In C programming language, *p represents the value stored in a pointer. ++ is increment operator used in prefix and postfix expressions. * is dereference operator. Precedence of prefix ++ and * is same and both are right to left associative. Precedence of postfix ++ is higher than both prefix ++ and * and is left to right associative. See the below example to understand the difference between ++*p, *p++ and *++p.
Example (C)
#include <stdio.h> int main() { int arr[] = {20, 30, 40}; int *p = arr; int q; //value of p (20) incremented by 1 //and returned q = ++*p; printf("arr[0] = %d, arr[1] = %d, *p = %d, q = %d
", arr[0], arr[1], *p, q); //value of p (20) is returned //pointer incremented by 1 q = *p++; printf("arr[0] = %d, arr[1] = %d, *p = %d, q = %d
", arr[0], arr[1], *p, q); //pointer incremented by 1 //value returned q = *++p; printf("arr[0] = %d, arr[1] = %d, *p = %d, q = %d
", arr[0], arr[1], *p, q); return 0; }
Output
arr[0] = 21, arr[1] = 30, *p = 21, q = 21 arr[0] = 21, arr[1] = 30, *p = 30, q = 21 arr[0] = 21, arr[1] = 30, *p = 40, q = 40
- Related Articles
- Difference between ++*p, *p++ and *++p in c++
- Difference between const char* p, char * const p, and const char * const p in C
- Difference between %p and %x in C/C++
- Difference between P-Type and N-Type Semiconductor
- Difference between P-N Junction Diode and Zener Diode
- Simplify:$(2x + p - c)^2 - (2x - p + c)^2$
- Simplify and verify the result for $p=1$.$4 p^{3} \times 3 p^{4} \times( -p^{5})$"\n
- Subtract \( 4 p^{2} q-3 p q+5 p q^{2}-8 p+7 q-10 \) from \( 18-3 p-11 q+5 p q-2 p q^{2}+5 p^{2} q \).
- Given that \( \frac{4 p+9 q}{p}=\frac{5 q}{p-q} \) and \( p \) and \( q \) are both positive. The value of $\frac{p}{q}$ is
- If $p,\ q,\ r$ are in A.P., then show that $p^2( p+r),\ q^2( r+p),\ r^2( p+q)$ are also in A.P.
- Count pairs (p, q) such that p occurs in array at least q times and q occurs at least p times in C++
- If $ p=-10$ find the value of $p^{2}-2 p-100 $
- From an external point \( P \), tangents \( P A \) and \( P B \) are drawn to a circle with centre \( O \). At one point \( E \) on the circle tangent is drawn, which intersects \( P A \) and \( P B \) at \( C \) and \( D \) respectively. If \( P A=14 \mathrm{~cm} \), find the perimeter of \( \triangle P C D \).
- In \( \Delta P Q R \), right-angled at \( Q, P Q=3 \mathrm{~cm} \) and \( P R=6 \mathrm{~cm} \). Determine \( \angle P \) and \( \angle R \).
- Solve \( 2 p^{2} q^{2}-3 p q+4,5+7 p q-3 p^{2} q^{2} \).

Advertisements