Difference ( pointer and reference arguments) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Difference ( pointer and reference arguments)

During swapping what will be the difference if the function arguments are pointer variables and when they are reference varibles

19th Aug 2021, 6:33 AM
Viraj
Viraj - avatar
2 Answers
0
#include<iostream> using namespace std; void swap(int*,int*); int main() { int a=5; int b=6; swap(&a,&b); cout<<"value of a after swapping is :"<<a<<endl; cout<<"value of b after swapping is :"<<b<<endl; return 0; } void swap(int*p,int*q) { int temp; temp=*p; *p=*q; *q=temp; } I mean what is the main difference if we use function arguments as int&p, int&q
19th Aug 2021, 6:35 AM
Viraj
Viraj - avatar