C Program to Add Two Numbers Using Call by Reference2 min read

The program takes the two numbers from the user and passes the reference to the function where the sum is calculated. You may go through the topic below.

Output:

Enter the first number: 15.5
Enter the Second number: 20.5
Sum of the result: 36.000000


This is a simple C program that demonstrates the use of a user-defined function to add two floating-point numbers. Let’s break down the code:

Function Declaration:

  • This line declares a function named addFunc that takes two float pointers (a and b) as parameters and returns a float value.

Function Definition:

  • Inside the addFunc function, it calculates the sum of the values pointed to by a and b and returns the result.

Main Function:

  • The main function is the entry point of the program.
  • It declares three float variables num1, num2, and result.
  • It takes user input for num1 and num2 using scanf.
  • Calls the addFunc function, passing the addresses of num1 and num2.
  • Prints the result.

Execution:

  • The program prompts the user to enter two floating-point numbers.
  • It then calculates the sum of these numbers using the addFunc function.
  • Finally, it prints the result to the console.

So, if the user enters, for example, 5.3 and 2.7, the program would output:


MORE

C Program to search an element in an array using Pointers

A separate function( search_function()) will be created where the array pointer will be declared and the searched element along with the size of an array …

C Program to find the sum of the digits of a number using recursion function

This C program calculates the sum of digits of a given number using recursion. Here’s a concise explanation: Function Definition: sumDigits(int n) This function calculates …

C program to find factorial of a number using Ternary operator with Recursion

Recursion refers to the function calling itself directly or in a cycle. Before we begin, you should have the knowledge of following in C Programming: …

C Program to Add Two Numbers Using Call by Reference

The program takes the two numbers from the user and passes the reference to the function where the sum is calculated. You may go through …

Find the output ab, cd, ef, g for the input a,b,c,d,e,f,g in Javascript and Python

In this tutorial, we will write a program to find a pairs of elements from an array such that for the input [a,b,c,d,e,f,g] we will …

String Pattern Programs in C

In this tutorial, we will write various C pattern programs for String. Before that, you may go through the following topics in C. for loop …