- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpointer.c
More file actions
Latest commit
138 lines (117 loc) · 2.44 KB
/
Copy pathpointer.c
File metadata and controls
138 lines (117 loc) · 2.44 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// ================================================
// * Language: C
// * Topic: Pointer
// =================================================
// pointer example 1️⃣
#include<stdio.h>
intmain(){
intage=20 ;
int*ptr=&age;
int_age=*ptr ;
printf(" Output is %d\n" , _age);
return0;
}
// Print Address
#include<stdio.h>
intmain()
{
intage=10;
int*ptr=&age;
int_age=*ptr;
//printf("Output is %p\n" ,&age );
printf("Output is %u\n", &ptr); // Different
printf("Output is %u\n", ptr);
printf("Output is %u\n", &age);
return0;
}
// Print value
#include<stdio.h>
intmain(){
intage=12 ;
int*ptr=&age ;
int_age=*ptr;
printf("Output is : %d\n", age);
printf("Output is : %d\n" , *ptr);
printf("Output is : %d\n" , *(&age)) ;
return0;
}
// ================================================
// * Language: C
// * Topic: Pointer to Pointer
// =================================================
// pointer example 2️⃣
#include<stdio.h>
intmain()
{
intprice=100;
int*ptr=&price;
int**pptr=&ptr;
return0;
}
// 3️⃣ Call by value
#include<stdio.h>
voidnum(intn);
intmain(){
intnumber=10;
num(number);
printf("Number is %d\n" , number );
return0;
}
voidnum(intn){
n=n*n;
printf("Square is %d\n " , n);
}
// 4️⃣ Call by Reference
#include<stdio.h>
void_square(int*n);
voidsquare(inta);
intmain()
{
intx=4;
// int y = 3;
square(x); // function call
printf("value of x %d\n", x);
_square(&x);
printf("value of &x %d\n", x);
return0;
}
// fuction definition
voidsquare(inta)
{
// a = a*a;
intresult=a*a;
printf(" Result of square %d\n", result);
}
void_square(int*n)
{
*n= (*n) * (*n);
printf("_square is %d\n", *n);
}
// 👉👉 🔹🔹Qexample - 5️⃣ Swap 2 Numbers a & b
#include<stdio.h>
intmain(){
inta=55 ;
intb=33;
intt=a;
a=b ;
b=t;
printf("a = %d & b = %d\n" , a ,b);
return0;
}
// 👉👉 🔹🔹example - 6️⃣ Swap 2 Numbers a & b call by reference
#include<stdio.h>
int_swap(int*a ,int*b);
intmain(){
inta=10;
intb=20;
_swap(&a ,&b);
printf("a = %d b = %d\n" ,a,b );
return0 ;
}
// Fucntion difinition;
int_swap(int*a , int*b){
intt=*a;
*a=*b;
*b=t;
printf("a = %d & b = %d\n", *a,*b);
}