• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
June 15, 2022 |910 Views

C++ Program to Add Two Numbers using Pointer

Description
Discussion

In this video, we will see a C++ program to add two numbers using a pointer. The process of creating an address or location for some piece of data in memory and accessing this data is achieved through a pointer variable. This variable contains the categorical location which could include other pointers as well as addresses to which each variable should point out at runtime (hence address-pointer). So, Pointers are the variables that have memory addresses or references. There are three main kinds of pointers in the C++ programming language: 1) An argument of a function is passed by value, and the function has an internal parameter with pointer type. 2) Objects and arrays point to objects which have some complex attributes. 3) The programmer directly uses pointers in a specified time as an address or number value. These three kinds of pointers share the same principle- they use the * operator to indicate they hold some value. Example: Input: Int num1 = 5 , num2 = 6 Int *ptr1 = &num1, *ptr2 = &num2; Int sum = *ptr1 + *ptr2; Output: 11