Monday, June 5, 2023

Pointers Part 1: The Basics



So you're eager to learn about pointers but unfortunately you got stuck because they seemed to you terrible in nature? That's not true I know, but many of the people get confused when they arrive at the topic of pointers. Well pointers are the most important tools in C programming and are the one that can make you fly (unless you don't know how to ride over them). In this article we're going to learn basics of pointers.
Pointers are the varaibles that store addresses of other variables. Easy ain't it?
So lets start with the decleration of a pointer, pointer is decreleared as:
data_type *var_name;
e,g
int *pt;
well the astrisk(*) before the variable name is the thing that makes variable a pointer. So far so good now what?
Now lets say we want to store address of a variable in our pointer variable that seems pretty complex..!
Let's do it:
int number = 100;
int *pt = #
Is it really complex..?
what we are doing here is that we are first declaring and initializing a integer variable (number) with value of 100 and then we declare and initialize a pointer variable (pt) with the address of number variable. Now pt (pointer variable) contains the address of number (integer varaible). So what? Now we can use this pointer variable to change the value of number variable. Is this some kind of Magic? Maybe. Lets' do it:
*pt = 200;
what we have done here is that we De-referencing the pt variable with the asterisk (*) and then assigned it the value of 200 now the number variable contains 200. Isn't it a magic? De-referencing is used for accessing the value of the variable towards which our pointer is pointing simple. So lets write a full program of what we have learned so far.
/*Pointer Basics: Creating and Using Pointers*/
#include<stdio.h>
int main(void){
  int number = 100;
  int *pt = &number;
  printf("Value of 'number' is: %d", number);
  printf("Address of 'number' is: %p", pt);
  *pt = 200;
  printf("New value of 'number' is: %d", number);
  return 0;
}
What this whole program did was it created a integer variable and a pointer to integer variable and then printed out the value and address of the 'number' variable and after that we De-referenced the pointer variable so that we can access the value to which our pointer variable is pointing and changed the old 100 value with new 200 value and at last we printed that out. Easy isn't it?
But do you know that you can get the address of a variable even by using ampersand (&) operator? Lemme show you how. I'll declare and initialize a variable 'var' and then print it to screen using ampersand (&) operator:
int var = 10;
printf("Address of 'var' is %p\n", &var);
the last statement here will print out the address of 'var' not value so that means it is equal to this statement:
int *pt = &var;
printf("Address of 'var' is %p\n", pt);
here we first assigned the address of 'var' to pointer variable 'pt' and then printed out the address of 'var' using the pointer variable (pt).
So lets write another program that will wrap up this part of 'Pointer Basics':
/*Pointer Basics Part 1: Program 2*/
#include<stdio.h>
int main(void){
   int var = 10;
   int *pt = &var;
   printf("The Value of 'var' is: %d\n", var);
   printf("De-referencing: *pt = %d\n", *pt);
   printf("Ampersand: The Address of 'var' is %p\n",  &var);
   printf("pt = %p\n", pt);
   return 0;
}
So that's the end of first part watch out for the next part in which we'll tighten our grip on pointers and get ready for some Advanced '*po(inter)-fo'.
Related links
  1. Pentest Recon Tools
  2. Pentest Tools Open Source
  3. Pentest Tools Find Subdomains
  4. Hacking Tools For Windows Free Download
  5. Computer Hacker
  6. Pentest Tools Url Fuzzer
  7. Hacker Techniques Tools And Incident Handling
  8. Hacking Tools Windows
  9. Hack Tools Download
  10. Tools Used For Hacking
  11. Hacker Tools Free
  12. Hacker Tools For Pc
  13. Hacking Tools Windows 10
  14. Pentest Tools Open Source
  15. Blackhat Hacker Tools
  16. Hacker Tool Kit
  17. Pentest Tools Website Vulnerability
  18. Hacker Tools Apk
  19. Termux Hacking Tools 2019
  20. Hacker Tools Windows
  21. Termux Hacking Tools 2019
  22. How To Make Hacking Tools
  23. Hacking Tools 2019
  24. Hacker Tools For Mac
  25. Nsa Hacker Tools
  26. Android Hack Tools Github
  27. Pentest Tools Github
  28. Hacker Tools 2020
  29. Hacker Tools Mac
  30. Wifi Hacker Tools For Windows
  31. Hack Tools Github
  32. Hacking Tools Windows 10
  33. Pentest Tools Website
  34. Hacker Security Tools
  35. Hacking Tools Pc
  36. Beginner Hacker Tools
  37. Hacker Tools For Pc
  38. Hacking Apps
  39. Best Hacking Tools 2019
  40. Hacking Tools Github
  41. Game Hacking
  42. Hacker Tools Apk
  43. Hacking Tools 2019
  44. Hacker Tools List
  45. Easy Hack Tools
  46. Hacker
  47. Pentest Tools Download
  48. Hacking Tools For Kali Linux
  49. Hacking Tools Mac
  50. Hack Tools 2019
  51. Pentest Tools Android
  52. Install Pentest Tools Ubuntu
  53. Hacker Tools Hardware
  54. Pentest Tools Alternative
  55. Pentest Tools Kali Linux
  56. Hack Tools Online
  57. Pentest Tools Apk
  58. Hacking Tools 2020
  59. Hack Tools For Pc
  60. Hacker Tools For Windows
  61. Hacker Tools Hardware
  62. Nsa Hacker Tools
  63. Hacking Tools Kit
  64. Physical Pentest Tools
  65. Usb Pentest Tools
  66. Hacking Tools For Pc
  67. Best Hacking Tools 2020
  68. Termux Hacking Tools 2019
  69. Hacker Tools Free
  70. Hacking Tools Free Download
  71. What Are Hacking Tools
  72. Hack Tools Pc
  73. Physical Pentest Tools
  74. Pentest Automation Tools
  75. Pentest Tools Port Scanner
  76. Hacking Tools Hardware
  77. Nsa Hack Tools
  78. Hacker Tools Software
  79. Nsa Hack Tools Download
  80. Black Hat Hacker Tools
  81. Hacking Tools Pc
  82. Hacking Tools For Windows 7
  83. Blackhat Hacker Tools
  84. Hacking Tools Usb
  85. What Are Hacking Tools
  86. Hacking Tools For Kali Linux
  87. Hacker Tools 2019
  88. How To Hack
  89. Hacking Tools And Software
  90. Tools Used For Hacking
  91. How To Hack
  92. Hackers Toolbox
  93. Hacking Tools Software
  94. Pentest Tools Apk
  95. Hacker Tools For Mac
  96. Hack Tools Online
  97. Hacking Tools For Mac
  98. Hacking Tools Usb
  99. Easy Hack Tools
  100. Tools 4 Hack
  101. New Hack Tools
  102. Beginner Hacker Tools
  103. Best Pentesting Tools 2018
  104. Hacking Tools 2020
  105. Hacker Tools Windows
  106. Pentest Tools Android
  107. Hacking Tools Github
  108. Hack Tools
  109. Hack Tools For Windows
  110. Hacking Tools Free Download
  111. Easy Hack Tools
  112. Hack Tools Mac
  113. Hack Tools Github
  114. Hackrf Tools
  115. Pentest Automation Tools
  116. Hacking Tools Download
  117. Android Hack Tools Github
  118. Wifi Hacker Tools For Windows
  119. Pentest Tools
  120. Hack Tools
  121. What Is Hacking Tools
  122. Hacker Tools Github
  123. Hack Apps
  124. Hacking Tools For Beginners
  125. Hacker Tools 2020
  126. Hacker Search Tools
  127. Pentest Tools For Ubuntu
  128. Pentest Tools For Android
  129. Hacking Tools Github
  130. Hacking Tools Free Download
  131. Hack And Tools
  132. Pentest Tools List
  133. Pentest Tools Website
  134. What Are Hacking Tools
  135. Hacking Tools Windows 10
  136. Pentest Tools Download
  137. Top Pentest Tools
  138. Pentest Tools For Windows
  139. Hack App
  140. Hacks And Tools
  141. Pentest Tools Open Source
  142. Hacking Tools Pc
  143. Pentest Automation Tools
  144. Growth Hacker Tools
  145. Hacker Tools Apk
  146. Pentest Recon Tools
  147. Hacker Tools Apk
  148. Hack App
  149. Pentest Tools For Ubuntu
  150. Hacks And Tools
  151. Pentest Tools
  152. Physical Pentest Tools
  153. Pentest Tools Github
  154. Pentest Tools Open Source
  155. Hacking App
  156. Beginner Hacker Tools
  157. Best Hacking Tools 2020
  158. Hacking Tools Free Download
  159. Best Hacking Tools 2020
  160. Hacker Tools Windows
  161. Hack Tools
  162. Pentest Box Tools Download
  163. Pentest Tools Download
  164. New Hack Tools
  165. Hacking Tools 2020
  166. Blackhat Hacker Tools
  167. Beginner Hacker Tools
  168. Ethical Hacker Tools
  169. Hacker Hardware Tools
  170. Hacking Tools Hardware
  171. Pentest Tools Github
  172. Hacking Tools For Windows
  173. Hack Tools For Games
  174. Pentest Tools Linux
  175. Hack Tools Mac
  176. Hack Tools Mac

No comments:

Post a Comment

My Blog List

Blog Archive

Kiwi Arts Now Sold at Image Spa!

Kiwi Arts Now Sold at Image Spa!
Buy Natural Wood Bangles at Image Spa!

Kiwi Arts on Artfire

Store not available