C Online Compiler
Example: C Program to Perform Arithmetic Operations using Pointers
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C Program to Perform Arithmetic Operations using Pointers #include <stdio.h> int main() { int p, q; int *ptr1, *ptr2; int sum, sub, mul, mod; float div; // It will take two integer numbers printf("Enter any two positive integer numbers:\n"); scanf("%d%d", &p, &q); // To store the address of `p` & `q` ptr1 = &p; ptr2 = &q; // It will perform all arithmetic operations sum = *ptr1 + *ptr2; sub = *ptr1 - *ptr2; mul = *ptr1 * *ptr2; div = (float)*ptr1 / *ptr2; mod = *ptr1 % *ptr2; // It will print the final output of the program printf("\n"); printf("Addition of %d + %d = %d\n", *ptr1, *ptr2, sum); printf("Subtraction of %d - %d = %d\n", *ptr1, *ptr2, sub); printf("Multiplication of %d * %d = %d\n", *ptr1, *ptr2, mul); printf("Division of %d / %d = %f\n", *ptr1, *ptr2, div); printf("Modulus of %d %% %d = %d\n", *ptr1, *ptr2, mod); return 0; }
5 7
Output
Clear
ADVERTISEMENTS