-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path26_Function_With_Pointer.cpp
More file actions
55 lines (40 loc) · 895 Bytes
/
Copy path26_Function_With_Pointer.cpp
File metadata and controls
55 lines (40 loc) · 895 Bytes
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
#include <iostream>
using namespace std;
void print(int *p){
cout<<*p<<endl;
}
void update(int *p){
// p=p+1;
// cout<<"inside:"<<p<<endl;
*p=*p+1;
}
int getSum(/*int arr[]*/ int *arr , int n){
// dono tarike se likh sakete hai..
// pointer pass hota ..
cout<<"size:"<<sizeof(arr)<<endl;
int sum=0;
for(int i=0; i<n; i++){
sum += i[arr];
}
return sum;
}
int main(){
/*
int value=5;
int *p=&value;
// print(p);
// Address cannot be updated..
cout<<"Before:"<<p<<endl;
update(p);
cout<<"After:"<<p<<endl;
// value can be updated..
cout<<"Before:"<<*p<<endl;
update(p);
cout<<"After:"<<*p<<endl;
*/
int arr[6]={1,2,3,4,5,8};
// last ke 3 block hi beje hai..
// benefit of passing array as pointer in function..
cout<<getSum(arr+3,2)<<endl;
return 0;
}