@@ -16,7 +16,7 @@ long long d=9879879870;
16
16
printf ("Address of int i=%d, data=%d\n" ,& i ,i );
17
17
printf ("Address of float f=%d, data=%f\n" ,& f ,f );
18
18
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 );
20
20
21
21
//Print same output using Pointers
22
22
//Here comes pointers in Action:
@@ -28,27 +28,31 @@ printf("Address of double d=%d, data=%lld\n",&d,d);
28
28
you use the asterisk (*) symbol before the variable name.
29
29
For example:
30
30
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
35
35
/*Initialization of pointers
36
36
Address-of Operator (&): To get the memory address of a variable,
37
37
you use the & operator.
38
38
For example: int x = 10; int *ptr = &x;
39
39
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 );
48
48
/*Dereferencing (*): To access the value a pointer is pointing to,
49
49
you use the * operator.
50
50
For instance: int y = *ptr; would assign the value of x
51
51
(since ptr is pointing to x) to the variable y.
52
52
*/
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 );
53
57
54
58
}
0 commit comments