Skip to content

Commit 0e30eaa

Browse files
committed
done with programs feeding for now
1 parent 317d603 commit 0e30eaa

File tree

3 files changed

+105
-24
lines changed

3 files changed

+105
-24
lines changed

Pointer.c

Lines changed: 103 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
#include <stdio.h>
22
#include <conio.h>
3-
int valuebyusingpointer(int x, int y, int z);
4-
int pointerdiscussion(int x, int y, int z);
5-
int fun(int x);
6-
int basicdeclaration();
7-
int ProblemOnPointer();
3+
// int valuebyusingpointer(int x, int y, int z);
4+
// int pointerdiscussion(int x, int y, int z);
5+
// int fun(int x);
6+
// int basicdeclaration();
7+
// int ProblemOnPointer();
8+
// int twolevelpointer();
9+
// int HardpointerValuChange();
10+
// int easyPointerChange();
11+
int pointerToArray();
812
int main()
913
{
1014
int x, y, z;
@@ -20,7 +24,11 @@ int main()
2024
// pointerdiscussion(x,y,z);
2125
// valuebyusingpointer(x, y, z);
2226
// printf("%x",d);
23-
ProblemOnPointer();
27+
// ProblemOnPointer();
28+
// twolevelpointer();
29+
// HardpointerValuChange();
30+
// easyPointerChange();
31+
pointerToArray();
2432
printf("\nhurray i learnt pointer");
2533
}
2634

@@ -59,39 +67,111 @@ int fun(int x)
5967
{
6068
// x = 30;
6169
int *ptr = &x;
62-
6370
}
6471
// 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
6572

66-
int basicdeclaration(){
73+
int basicdeclaration()
74+
{
6775
int m = 1000;
68-
int n,o;
69-
int* z;
76+
int n, o;
77+
int *z;
7078
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);
7681

82+
printf("\nThe adress of n is %x", &n);
83+
printf("\nThe adress of o is %x", &o);
7784
}
7885

79-
80-
int valuechangethroughfunction(int x){
86+
int valuechangethroughfunction(int x)
87+
{
8188
x = 400;
8289
return 0;
8390
}
8491

85-
8692
// some basic problems on pointer
8793

88-
int ProblemOnPointer(){
89-
int x=10,y=18;
90-
int *ptr1,*ptr2;
94+
int ProblemOnPointer()
95+
{
96+
int x = 10, y = 18;
97+
int *ptr1, *ptr2;
9198
ptr1 = &x;
9299
// ptr2 = &y;
93100
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+
int twolevelpointer()
108+
{
109+
int s = 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);
96125
}
97126

127+
int HardpointerValuChange()
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+
return 0;
143+
}
144+
145+
int easyPointerChange()
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
158+
int pointerToArray(){
159+
int arr[5];
160+
int len = sizeof(arr)/sizeof(arr[0]);
161+
// printf("lenggth is %d",len);
162+
for(int i=0;i<len;i++){
163+
printf("%x\n",&arr[i]);
164+
}
165+
printf("%x",&arr);
166+
printf("\n");
167+
printf("%x",&arr[1]);
168+
printf("\n");
169+
printf("%x",&arr[2]);
170+
printf("\n");
171+
printf("%x",&arr[3]);
172+
printf("\n");
173+
printf("%x",&arr[4]);
174+
}
175+
176+
//By taking value and printing the answer
177+

Pointer.exe

655 Bytes
Binary file not shown.

Structure.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,5 @@ struct date baisicstructure(){
165165
printf("Enter the date : ");
166166
scanf("%d/%d/%d",&Somedate.dates,&Somedate.months,&Somedate.year);
167167
return Somedate;
168-
};
168+
};
169+

0 commit comments

Comments
 (0)