- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Suppose we have two numbers a and b. We shall have to define a function that can calculate (a + b) and (a - b) both. But using a function in C, we can return at most one value. To find more than one output, we can use output parameters into function arguments using pointers. Here in this problem we shall update a with a+b and b with a-b. When we call the function we shall have to pass the address of these two variables.

So, if the input is like a = 5, b = 8, then the output will be a + b = 13 and a - b = -3

To solve this, we will follow these steps −

define a function solve(), this will take addresses of a and b

temp := sum of the values of variable whose addresses are given

b := difference of the values of variable whose addresses are given

a = temp

Let us see the following implementation to get better understanding −

#include <stdio.h> int solve(int *a, int *b){ int temp = *a + *b; *b = *a - *b; *a = temp; } int main(){ int a = 5, b = 8; solve(&a, &b); printf("a + b = %d and a - b = %d", a, b); }

a = 5, b = 8

a + b = 13 and a - b = -3

- Related Questions & Answers
- C Program to find sum of perfect square elements in an array using pointers.
- C program to find sum and difference of two numbers
- Difference between Array and Pointers in C.
- C program to find array type entered by user using pointers.
- Pointers, smart pointers and shared pointers in C++
- How to calculate sum of array elements using pointers in C language?
- C Program to insert an array element using pointers.
- C program to delete an array element using Pointers
- C program to search an array element using Pointers.
- Program to find minimum absolute sum difference in Python
- C program to calculate sum of series using predefined function
- Matrix row sum and column sum using C program
- Function pointers in Java
- C++ program to find addition and subtraction using function call by address
- C++ program to Find Sum of Natural Numbers using Recursion

Advertisements