-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPointer.c
191 lines (143 loc) · 2.76 KB
/
Pointer.c
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
1.
#include<stdio.h>
int main()
{
int A;
int B;
int C;
int *p;
int *q;
int *r;
A = 10;
B = 20;
p = &A;
q = &B;
r = &C;
*r = *p * *q ;
printf("Multiply of A and B is %d.",*r);
return 0;
}
2.
#include<stdio.h>
int main()
{
float P ;
float R ;
float T ;
float S;
float *p;
float *q;
float *r;
float *SI;
p = &P;
q = &R;
r = &T;
SI = &S;
printf("Enter Principle : ");
scanf("%f",p); // Because <code>p</code> has address of <code>P</code>,
// So we can write <code>p</code> insted of <code>&P</code>.
printf("Enter Rate : ");
scanf("%f",q);
printf("Enter Time : ");
scanf("%f",r);
*SI = (*p * *q * *r)/100; // or *SI = (*p**q**r)/100;
printf("Simple Intrest is %.2f%%.",*SI);
return 0;
}
3.
#include<stdio.h>
int main()
{
int x = 90;
int y = 67;
int sum;
void sum_of_2_number( int * , int * , int * );
// In above statement we are talling that we give Address of variable as argument,
// And receve them in pointers.
sum_of_2_number( &x, &y, &sum );
// Giving Address of variables.
printf("Sum of x and y is %d.",sum);
return 0;
}
void sum_of_2_number( int *a , int *b , int *c )
// Here we are reseving addresses in a, b and c.
{
*c = *a + *b;
}
4.
#include<stdio.h>
int main()
{
int x = 90;
int y = 67;
void swap( int * , int * );
printf("Values of x and y before calling function : \nx = %d y = %d \n",x,y);
swap( &x, &y );
printf("Values of x and y after calling function : \nx = %d y = %d \n",x,y);
return 0;
}
void swap( int *a , int *b )
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
5.
#include<stdio.h>
int main()
{
float r;
float area;
void Area_of_circle( float * , float * );
printf("Enter Radius of Circle : ");
scanf("%f",&r);
Area_of_circle( &r, &area );
printf("Area of circle is %.3f.",area);
return 0;
}
void Area_of_circle( float *a , float *b )
{
*b = 3.14* *a * *a;
}
6.
#include<stdio.h>
int main()
{
int a[5] = {23,54,56,67,78};
int *p , i;
p = a; // or p = &a[0];
for ( i = 0 ; i < 5 ; i++ )
printf("%d\n",*(p+i));
return 0;
}
7.
#include<stdio.h>
int main()
{
int a[5] = {23,54,56,67,78};
int i;
for ( i = 0 ; i < 5 ; i++ )
printf("%d\n",*(a+i));
return 0;
}
8.
#include<stdio.h>
int main()
{
int a[5] = {23,54,56,67,78};
int i , *p;
for ( p = a ; p < a+5 ; p++ )
printf("%d\n",*p);
return 0;
}
9.
#include<stdio.h>
int main()
{
int a[5] = {23,54,56,67,78};
int *p , i;
for ( i = 4, p = a ; i >= 0 ; i-- )
printf("%d\n",*(p+i));
return 0;
}