Find elements

C++ program to find product of two numbers using pointer

C++ program to find product of two numbers using pointer

In this tutorial, we will discuss a concept of  C++ program to find the product of two numbers using the pointer variable

In the C++ programming  language, we can use the pointer variable to find the product of two numbers

In this article, we are going to learn  how to Display product of two numbers using the  pointer variable

Program

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int num1,num2;      //1
    int *ptr1,*ptr2;    //2
    int product;              //3

     cout << "Please enter the value to num1: "<< endl;    //4
    cin>>num1;                           //5
     cout << "Please enter the value to num2: "<< endl;       //6
    cin>>num2;                            //7

    ptr1=&num1;                                      //8
    ptr2=&num2;

    product=*ptr1 * *ptr2;                                 //10

    cout<<"Product of the two integer values is: "<<product;  //11
    getch();
    return 0;
    return 0;
}

When the above code is executed, it produces the following results

Please enter the value to num1:
12
Please enter the value to num2:
13
Product of the two integer values is: 156

 

Methods

  1. Create two variables to store two numbers as input (num1 and num2) provided by the user.
  2. Create two pointer variables to store the address of the numbers: num 1 and num2
  3. Create a variable to store the sum of these numbers: sum.
  4. Request the user to enter the first input to store variable num1
  5. Using scanf() function, store the first input value in num1
  6. Request the user to enter the second number to store as variable num2
  7. Using scanf() function, store the second input value in num2.
  8. Assign the address of variable num1 to ptr1
  9. Assign the address of variable num2 to ptr2
  10. Find the product of two number using their addresses – find the product of num1 and num2 using their addresses or multiply them using the pointer variables.
  11. Finally, display result on the screen- the product of both numbers num1 and num1

 

Similar post

C program to add two numbers

C program to add two numbers using the pointer

C++ program to add two numbers

C++ program to add two numbers using pointer

C program to find the product of two numbers using the pointer

 

Suggested for you

Input-output function in C language

Data type in C language

Variable in C language

Operator n C language

Pointer in C language

 

 

C++ program to add two numbers using pointer
C program to find sum of two numbers without using arithmetic operators
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

View Comments

  • Modify the previous code to implement functions that uses
    call-by-reference (in pointers) to multiply these two numbers.

Recent Posts

Explanation of one dimensional array (Data structure)

Explanation of one dimensional array In this post, we will discuss the concept of "Explanation…

2 days ago

Python program to calculate the sum of odd and even numbers in a list

Python program to calculate the sum of odd and even numbers in a list In…

4 days ago

Python code to Calculate sum of odd and even in a list

Python code to Calculate sum of odd and even in a list In this tutorial,…

1 week ago

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

2 weeks ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

1 month ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

2 months ago