Sunday, 21 January 2024

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 articles


  1. Pentest Tools Alternative
  2. Hacker Tools 2020
  3. Hacking Tools Kit
  4. Hack Tools Pc
  5. Best Pentesting Tools 2018
  6. Pentest Tools List
  7. Hacker Tools Mac
  8. Hack Tools Mac
  9. Hack And Tools
  10. Hacks And Tools
  11. Hacking Apps
  12. Hacker Tools Apk
  13. Pentest Tools Download
  14. How To Make Hacking Tools
  15. Pentest Automation Tools
  16. Pentest Tools Framework
  17. Hacking Apps
  18. Hacker Tools For Mac
  19. Wifi Hacker Tools For Windows
  20. Hacker Tools Apk
  21. Hack Tools Download
  22. Hacking Tools Name
  23. Pentest Tools Windows
  24. Pentest Tools
  25. Hack Tools 2019
  26. Pentest Recon Tools
  27. Hacker Tools Linux
  28. Hacker Tools Online
  29. Hack Tools For Ubuntu
  30. Hacker Tools Windows
  31. Ethical Hacker Tools
  32. Tools Used For Hacking
  33. Pentest Box Tools Download
  34. Hacking Tools For Windows
  35. Hacking Tools For Beginners
  36. Black Hat Hacker Tools
  37. Hacking Tools Download
  38. Growth Hacker Tools
  39. Physical Pentest Tools
  40. Pentest Tools Free
  41. Hack Tools For Ubuntu
  42. How To Make Hacking Tools
  43. Hacker Tools For Windows
  44. Pentest Tools For Windows
  45. Pentest Tools Find Subdomains
  46. Hacking Tools For Windows Free Download
  47. Hack Apps
  48. Hacking Tools Github
  49. Usb Pentest Tools
  50. Hacker Tools For Pc
  51. Hacker
  52. Hacker Security Tools
  53. Hacker Tools Free
  54. Hacking Tools And Software
  55. Install Pentest Tools Ubuntu
  56. Hacking Tools For Games
  57. Hack App
  58. Pentest Tools Free
  59. Android Hack Tools Github
  60. Pentest Tools Android
  61. Pentest Tools Open Source
  62. Hack Tools For Games
  63. Install Pentest Tools Ubuntu
  64. Install Pentest Tools Ubuntu
  65. Nsa Hack Tools
  66. Hack Tool Apk
  67. Easy Hack Tools
  68. Hacking Tools And Software
  69. Top Pentest Tools
  70. Tools For Hacker
  71. Pentest Tools Tcp Port Scanner
  72. Easy Hack Tools
  73. Hacking Tools For Windows
  74. Tools For Hacker
  75. Pentest Tools Website
  76. Hacking Tools And Software
  77. Hacking Tools 2020
  78. Hacker Hardware Tools
  79. Hacking Tools 2019
  80. Wifi Hacker Tools For Windows
  81. Top Pentest Tools
  82. Hacking Tools And Software
  83. How To Install Pentest Tools In Ubuntu
  84. Hacking Tools Online
  85. Beginner Hacker Tools
  86. Pentest Tools For Windows
  87. Pentest Tools For Windows
  88. Hacker Tools Github
  89. Pentest Tools For Android
  90. Hack Tools Download
  91. Pentest Tools Review
  92. Pentest Automation Tools
  93. Hack Tools 2019
  94. Nsa Hacker Tools
  95. Kik Hack Tools
  96. Hack Tools 2019
  97. Hack Tools For Games
  98. Pentest Recon Tools
  99. Hack Tool Apk No Root
  100. Hacker Tools Windows
  101. Tools Used For Hacking
  102. What Are Hacking Tools
  103. Game Hacking
  104. New Hacker Tools
  105. Hacker Tools For Pc
  106. Hack Tools Online
  107. Hacking Apps
  108. Physical Pentest Tools
  109. Hackers Toolbox
  110. New Hack Tools
  111. Computer Hacker
  112. Hack Tools 2019
  113. Pentest Reporting Tools
  114. New Hacker Tools
  115. Hacker Tools 2020
  116. Hacker Tools 2019
  117. Hacker Tools Linux
  118. Growth Hacker Tools
  119. Hacking Tools And Software
  120. Hacker Tools
  121. Blackhat Hacker Tools
  122. Pentest Tools Apk
  123. Hacker Search Tools
  124. Pentest Tools Framework
  125. Growth Hacker Tools
  126. Android Hack Tools Github
  127. Hacking Tools
  128. Hacking Tools Free Download
  129. Hacking Tools Name
  130. Hacker Security Tools
  131. Black Hat Hacker Tools
  132. Pentest Tools For Android
  133. Hacking Tools And Software
  134. Hacker
  135. Pentest Tools For Mac
  136. Hacking Tools Github
  137. Hacking App
  138. Nsa Hacker Tools
  139. Pentest Tools For Mac
  140. Usb Pentest Tools
  141. Hacking Tools 2020
  142. Easy Hack Tools
  143. Hacker Tools Mac
  144. Github Hacking Tools
  145. Pentest Tools Website Vulnerability
  146. Best Hacking Tools 2019
  147. Kik Hack Tools
  148. Hacker Search Tools
  149. What Is Hacking Tools
  150. Hack Tools Online
  151. Hacking Tools Pc
  152. Physical Pentest Tools
  153. Hack Tools Online
  154. Hack Tools Mac
  155. Easy Hack Tools
  156. Hacking Tools 2020
  157. Hacking Tools Pc
  158. Hacker Tools Free Download
  159. Hacking Tools 2019
  160. Hacker Tool Kit
  161. Pentest Tools Website
  162. Hacking Tools Github
  163. Pentest Box Tools Download
  164. What Is Hacking Tools
  165. Underground Hacker Sites
  166. Hack Tools For Ubuntu
  167. Hacks And Tools
  168. Computer Hacker
  169. Pentest Tools Apk
  170. Hacking Tools Kit

No comments:

Post a Comment