Pointers and Function

0 everettebosanqu November 13, 2020

In last tutorials, WQe have learn about pointer. In this tutorials, We will learn pointers and functions.

A pointer can be passed to a function as an argument. Passing a pointer means pasing address of a variable instead of the value of the variable. As address is passed in this case, this mechanism is also known as call by address or call by reference

W#hen pointer is passed to a function while functiuon calling, the formal argument of the function must be compatible with the passing pointer i.e. if integer pointer is being passed, the formal argument in function must be pointer of the type integer and so forth. As Addressof variable is passd in this mexhanism, if value in the passed address is changed within function definition, the valu of actual variable also changed.

Lets look an example to make clear concepts on pointer and functions.

// C++ program to illustrate Array Name as Pointers in C++ 
#include <iostream> 
using namespace std;

void addMarks(int *m) 
	*m = *m + 10;
//Driver program 
int main() 
	int marks;
  	cout << "Enter actual marks" << endl;
  	cin >> marks;
  	cout << "The Final Marks is " << marks << endl;
  	return 0;

The output of the above program is:

Enter actual marks    22
The Final Marks is  32