8000 Sample Pointer Demo Created · sbccas/c-programming-tutorials@3d8d64f · GitHub
[go: up one dir, main page]

Skip to content

Commit 3d8d64f

Browse files
Sample Pointer Demo Created
1 parent 60dce3c commit 3d8d64f

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"CP5CharArrayDemo.C": "cpp",
3434
"CP5CharacterArrayDemo.C": "cpp",
3535
"CPsizeofDatatypes.C": "cpp",
36-
"CP5PointersDemo.C": "cpp"
36+
"CP5PointersDemo.C": "cpp",
37+
"deletepointer.C": "cpp"
3738
}
3839
}

3_Programs/CP5PointersDemo.C

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ long long d=9879879870;
1616
printf("Address of int i=%d, data=%d\n",&i,i);
1717
printf("Address of float f=%d, data=%f\n",&f,f);
1818
printf("Address of char c=%d, data=%c\n",&c,c);
19-
printf("Address of double d=%d, data=%lld\n",&d,d);
19+
printf("Address of long long d=%d, data=%lld\n",&d,d);
2020

2121
//Print same output using Pointers
2222
//Here comes pointers in Action:
@@ -28,27 +28,31 @@ printf("Address of double d=%d, data=%lld\n",&d,d);
2828
you use the asterisk (*) symbol before the variable name.
2929
For example:
3030
int *ptr; declares a pointer named ptr that can point to an integer.*/
31-
int *ptri; //Pointer to integer
32-
float *ptrf; //Pointer to float
33-
char *ptrc; //Pointer to char
34-
long long *ptrl; //Pointer to long long
31+
int *ptrii; //Pointer to integer
32+
float *ptrff; //Pointer to float
33+
char *ptrcc; //Pointer to char
34+
long long *ptrll; //Pointer to long long
3535
/*Initialization of pointers
3636
Address-of Operator (&): To get the memory address of a variable,
3737
you use the & operator.
3838
For example: int x = 10; int *ptr = &x;
3939
sets the pointer ptr to hold the memory address of the variable x.*/
40-
ptri = &i;
41-
ptrf = &f;
42-
ptrc = &c;
43-
ptrl = &d;
44-
printf("Address Data stored in ptri=%d\n",ptri);
45-
printf("Address Data stored in ptrf=%f\n",ptrf);
46-
printf("Address Data stored in ptrc=%c\n",ptrc);
47-
printf("Address Data stored in ptrl=%lld\n",ptrl);
40+
ptrii = &i;
41+
ptrff = &f;
42+
ptrcc = &c;
43+
ptrll = &d;
44+
printf("Address Data stored in ptri=%d\n",ptrii);
45+
printf("Address Data stored in ptrf=%d\n",ptrff);
46+
printf("Address Data stored in ptrc=%d\n",ptrcc);
47+
printf("Address Data stored in ptrl=%d\n",ptrll);
4848
/*Dereferencing (*): To access the value a pointer is pointing to,
4949
you use the * operator.
5050
For instance: int y = *ptr; would assign the value of x
5151
(since ptr is pointing to x) to the variable y.
5252
*/
53+
printf("Data pointed by ptrii = %d\n",*ptrii);
54+
printf("Data pointed by ptrff = %f\n",*ptrff);
55+
printf("Data pointed by ptrii = %c\n",*ptrcc);
56+
printf("Data pointed by ptrii = %lld\n",*ptrll);
5357

5458
}

3_Programs/CP5PointersDemo.exe

512 Bytes
Binary file not shown.

3_Programs/tempCodeRunnerFile.C

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
printf("Enter data in Character Array1: using scanf\n");
2-
scanf("%s",carray);
1+
p

0 commit comments

Comments
 (0)
0