You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Write a program in C to show the basic declaration of a pointer Expected Output :Pointer : Show the basic declaration of pointer:Here is m=10, n and o are two integer variable and *z is an nteger z stores the address of m = 0x7ffd40630d44 *z stores the value of m = 10 &m is the address of m =x7ffd40630d44 &n stores the address of n = 0x7ffd40630d48 &o stores the address of o =0x7ffd40630d4c &z stores the address of z= 0x7ffd40630d50
65
72
66
-
intbasicdeclaration(){
73
+
intbasicdeclaration()
74
+
{
67
75
intm=1000;
68
-
intn,o;
69
-
int*z;
76
+
intn,o;
77
+
int*z;
70
78
z=&m;
71
-
printf("\nthe value of m is %d",m);
72
-
printf("\nThe value of m through address is %x",*z);
73
-
74
-
printf("\nThe adress of n is %x",&n);
75
-
printf("\nThe adress of o is %x",&o);
79
+
printf("\nthe value of m is %d", m);
80
+
printf("\nThe value of m through address is %x", *z);
76
81
82
+
printf("\nThe adress of n is %x", &n);
83
+
printf("\nThe adress of o is %x", &o);
77
84
}
78
85
79
-
80
-
intvaluechangethroughfunction(intx){
86
+
intvaluechangethroughfunction(intx)
87
+
{
81
88
x=400;
82
89
return0;
83
90
}
84
91
85
-
86
92
// some basic problems on pointer
87
93
88
-
intProblemOnPointer(){
89
-
intx=10,y=18;
90
-
int*ptr1,*ptr2;
94
+
intProblemOnPointer()
95
+
{
96
+
intx=10, y=18;
97
+
int*ptr1, *ptr2;
91
98
ptr1=&x;
92
99
// ptr2 = &y;
93
100
ptr2=&y;
94
-
*ptr2=*ptr1;
95
-
printf("a = %d %d %d",x,*ptr1,*ptr2);
101
+
*ptr2=*ptr1;
102
+
printf("a = %d %d %d", x, *ptr1, *ptr2);
103
+
}
104
+
105
+
// Two levelpointer
106
+
107
+
inttwolevelpointer()
108
+
{
109
+
ints=12111230;
110
+
int*ptr1, **ptr2;
111
+
ptr1=&s;
112
+
ptr2=&ptr1;
113
+
114
+
printf("The address of s is %x", &s);
115
+
printf("\n");
116
+
printf("The value of s is %d", s);
117
+
printf("\n");
118
+
printf("The address of ptr1 is %x", ptr1);
119
+
printf("\n");
120
+
printf("The value of ptr1 is %d", *ptr1);
121
+
printf("\n");
122
+
printf("The address of ptr2 is %x", ptr2);
123
+
printf("\n");
124
+
printf("The value of ptr2 is %p", **ptr2);
96
125
}
97
126
127
+
intHardpointerValuChange()
128
+
{
129
+
int*pc, c;
130
+
c=22;
131
+
printf("Address of c: %p\n", &c);
132
+
printf("Value of c: %d\n\n", c);
133
+
pc=&c;
134
+
printf("Address of pointer pc: %p\n", pc);
135
+
printf("Content of pointer pc: %d\n\n", *pc);
136
+
c=11;
137
+
printf("Address of pointer pc: %p\n", pc);
138
+
printf("Content of pointer pc: %d\n\n", *pc);
139
+
*pc=2;
140
+
printf("Address of c: %p\n", &c);
141
+
printf("Value of c: %d\n\n", c); // 2
142
+
return0;
143
+
}
144
+
145
+
inteasyPointerChange()
146
+
{
147
+
int*pc, c;
148
+
c=5;
149
+
pc=&c;
150
+
*pc=1;
151
+
printf("%d\n", *pc);
152
+
printf("%d", c);
153
+
}
154
+
155
+
156
+
// Pointer To Array
157
+
// a program where we got to know the base adress of the array is the array first element address aactually
0 commit comments