Programming with C

⌘K
  1. Home
  2. Docs
  3. Programming with C
  4. Functions and Pointers
  5. Pointer Arithmetic
  6. Pointer Decrement

Pointer Decrement

Pointer Decrement

Example: Post Decrement

#include<stdio.h>
int main()
{
	int *ptr = (int *) 2000;
	int *fptr;
	printf("Initial value of ptr = %u\n",ptr);
	fptr = ptr--;
	printf("Resultant value of fptr = %u\n",fptr);
	printf("Final value of ptr = %u",ptr);
	return 0;
}

Output

Initial value of ptr = 2000
Resultant value of fptr = 2000
Final value of ptr = 1998

Example: Pre Decrement

#include<stdio.h>
int main()
{
	int *ptr = (int *) 2000;
	int *fptr;
	printf("Initial value of ptr = %u\n",ptr);
	fptr = --ptr;
	printf("Resultant value of fptr = %u\n",fptr);
	printf("Final value of ptr = %u",ptr);
	return 0;
}

Output

Initial value of ptr = 2000
Resultant value of fptr = 1998
Final value of ptr = 1998

Views: 0

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments