Monday 24 May 2021

Pointer Expression and Arithmetic in C

Similar to other variables, pointer variables can also be used in expressions. For example, if p1 and p2 are two pointer variables then the following statements are valid

As a pointer holds the memory address of a variable, some arithmetic operations can be performed with pointers. Such as addition, subtraction, increment and decrement ext. However the following operations are not possible with pointers.

  1. Addition of two pointer address 
  2. Multiplication of address
  3. Multiplication of address with a constant 

Example: Write a C program to perform different arithmetic operations using pointers

#include<stdio.h>
#include<conio.h.h>
void main()
{
int a=10,b=20;
int *p1,*p2;
p1=&a;
p2=&b;
printf(" addition is %d",*p1+*p2);
printf(" subtraction is %d",*p1-*p2);
printf(" Multiplication is %d",*p1+*p2);
printf(" division is %d",*p1+*p2);
getch();

0 comments :

Post a Comment

Note: only a member of this blog may post a comment.

Machine Learning

More

Advertisement

Java Tutorial

More

UGC NET CS TUTORIAL

MFCS
COA
PL-CG
DBMS
OPERATING SYSTEM
SOFTWARE ENG
DSA
TOC-CD
ARTIFICIAL INT

C Programming

More

Python Tutorial

More

Data Structures

More

computer Organization

More
Top