-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLecture26.cpp
More file actions
115 lines (81 loc) · 2.35 KB
/
Copy pathLecture26.cpp
File metadata and controls
115 lines (81 loc) · 2.35 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include<iostream>
using namespace std;
void update(int *p) {
// p = p + 1;
//cout << "inside "<< p <<endl;
*p = *p + 1;
}
void print(int *p) {
cout << *p << endl;
}
int getSum(int *arr, int n) {
cout << endl << "Size : " << sizeof(arr) << endl;
int sum = 0;
for(int i=0;i<n;i++) {
sum += arr[i];
}
return sum;
}
int main () {
// array pointer
//int arr[10] = {23, 122, 41, 67};
// cout <<" address of first memory block is " << arr << endl;
// cout << arr[0] << endl;
// cout <<" address of first memory block is " << &arr[0] << endl;
// cout << "4th " << *arr << endl;
// cout << "5th " << *arr + 1 << endl;
// cout << "6th " << *(arr + 1) << endl;
// cout << "7th " << *(arr) + 1 << endl;
// cout << "8th " << arr[2] << endl;
// cout << "9th " << *(arr+2) << endl;
// int i = 3;
// cout << i[arr] << endl;
int temp[10] = {1,2};
cout << sizeof(temp) << endl;
cout << " 1st " << sizeof(*temp) << endl;
cout << " 2nd " << sizeof(&temp) << endl;
// int *ptr = &temp[0];
// cout << sizeof(ptr) << endl ;
// cout << sizeof(*ptr) << endl ;
// cout << sizeof(&ptr) << endl ;
// int a[20] = {1,2,3,5};
// //cout << " ->" << &a[0] << endl;
// // cout << &a << endl;
// //cout << a << endl;
// int *p = &a[0];
// //cout << p << endl;
// //cout << *p << endl;
// cout << "-> " << &p << endl;
// */
// int arr[10];
// //ERROR
// //arr = arr+1;
// int *ptr = &arr[0];
// cout << ptr << endl;
// ptr = ptr + 1;
// cout << ptr << endl;
// // character pointer
// int arr[5] = {1,2,3,4,5};
// char ch[6] = "abcde";
// cout << arr << endl;
// //attention here
// cout << ch << endl;
// char *c = &ch[0];
// //prints entire string
// cout << c << endl;
// char temp = 'z';
// char *p = &temp;
// cout << p << endl;
// // function pointer
// /*
// int value = 5;
// int *p = &value;
// //print(p);
// cout <<" Before " << *p << endl;
// update(p);
// cout <<" After " << *p << endl;
// */
// int arr[6] = {1,2,3,4,5,8};
// cout << "Sum is " << getSum(arr+3 ,3) << endl ;
return 0;
}