-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathin1.cpp
More file actions
76 lines (61 loc) · 1.78 KB
/
in1.cpp
File metadata and controls
76 lines (61 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include<iostream>
using namespace std;
// FUNCTIONS
/*int sum(int a,int b){
int c=a+b;
return c;
}*/
// main concept of prototype
/*int sum(int a,int b);
int main(){
int num1=10;
int num2=20;
cout<<"first number: "<<num1<<endl;
cout<<"second number: "<<num2<<endl;
cout<<"sum is: "<<sum(num1,num2);
return 0;
}
int sum(int a,int b){
int c=a+b;
return c;
}*/
// call by value or reference
//swaping two numbers
/*void swap(int a,int b){
int temp=a;
a=b;
b=temp; //this particular code doesnt change the values and it will be resolved using refernce(addressess of the values)
}
int main(){
int num1=10,num2=100;
cout<<"the given values are "<<num1<<" "<<num2<<endl;
swap(num1,num2); //this swap has only copied the values of num and has passed onto int a and b
cout<<"numbers after swapping "<<num1<<" "<<num2<<endl;
return 0;
}*/
// use of calling by refernce(with pointers)
/*void swapPointer(int* a,int* b){
int temp=*a;
*a=*b;
*b=temp;
}
int main(){
int num1=10,num2=100;
cout<<"the given values are "<<num1<<" "<<num2<<endl;
swapPointer(&num1,&num2);
cout<<"numbers after swapping "<<num1<<" "<<num2<<endl;
return 0;
}*/
// use of refernce in c++ (only address)
void swaprefernce(int &a,int &b){
int temp=a;
a=b;
b=temp;
}
int main(){
int num1=10,num2=100;
cout<<"the given values are "<<num1<<" "<<num2<<endl;
swaprefernce(num1,num2); //using refernce variable
cout<<"numbers after swapping "<<num1<<" "<<num2<<endl;
return 0;
}