
- 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
Explain Arithmetic operations using pointers in C language?
Pointer is a variable which stores the address of other variable.
Pointer declaration, initialization and accessing
Consider the following statement −
int qty = 179;
Declaring a pointer
int *p;
‘p’ is a pointer variable that holds the address of another integer variable.
Initialization of a pointer
Address operator (&) is used to initialize a pointer variable.
int qty = 175; int *p; p= &qty;
Arithmetic operations using pointers
Pointer variables can be used in expressions. For example, if pointer variables are properly declared and initialized then the following statements are valid.
a) *p1 + *p2 b) *p1- *p2 c) *p1 * *p2 d) *p1/ *p2 Note: There must be a blank space between / and * otherwise it is treated as beginning of comment line e ) p1 + 4 f) p2 - 2 g) p1 - p2 Note: returns the no. of elements in between p1 and p2 if both of them point to same array h) p1++ i) – – p2 j) sum + = *p2 j) p1 > p2 k) p1 = = p2 l) p1 ! = p2 Note: Comparisons can be used meaningfully in handling arrays and strings
The following statements are invalid −
a) p1 + p2 b) p1 * p2 c) p1 / p2 d) p1 / 3
Program
#include<stdio.h> main (){ int a,b,x,y,z; int *p1, *p2; a =12; b = 4; p1= &a; p2 = &b; x = *p1 * * p2 – 6; y= 4 - *p2 / *p1+10; printf (“Address of a = %d”, p1); printf (“Address of b = %d”, p2); printf (“a= %d b =%d”, a,b); printf (“x= %d y =%d”, x,y); }
Output
Address of a = 1234 Address of b = 5678 a = 12 b= 4 x = 42 y= 14
Explanation
- Related Articles
- Explain the concept of pointers in C language
- Explain array of pointers in C programming language
- Explain the pointers to unions in C language
- Explain Near Far Huge pointers in C language
- Explain pointers and one-dimensional array in C language
- Explain pointers and two-dimensional array in C language
- What are different pointer operations and problems with pointers in C language?
- Explain the Character operations in C language
- How to perform the arithmetic operations on arrays in C language?
- Explain the concepts of Pointers and arrays in C language
- Explain the pointers for inter-function communication in C language.
- Explain the concept of Arithmetic operators in C language
- Demonstrate the concept of pointers using C language
- Arithmetic operations using OpenCV in Python
- Explain the characteristics and operations of arrays in C language

Advertisements