Monday, January 22, 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 Recon Tools
  2. Hacker Tool Kit
  3. Physical Pentest Tools
  4. Hacking Tools Usb
  5. World No 1 Hacker Software
  6. Hacker Tools List
  7. Pentest Tools Nmap
  8. Hacker Tools Windows
  9. Hacker Tools For Mac
  10. Termux Hacking Tools 2019
  11. Hacker Tools For Pc
  12. Pentest Tools For Windows
  13. How To Hack
  14. Nsa Hacker Tools
  15. Hack Tools For Games
  16. Pentest Tools Url Fuzzer
  17. Hack App
  18. Wifi Hacker Tools For Windows
  19. Pentest Tools Bluekeep
  20. Best Hacking Tools 2019
  21. Hacking Tools For Windows Free Download
  22. Easy Hack Tools
  23. How To Make Hacking Tools
  24. Tools Used For Hacking
  25. Hacking Tools For Windows Free Download
  26. Pentest Tools Download
  27. What Is Hacking Tools
  28. Hack Website Online Tool
  29. Hacker
  30. Free Pentest Tools For Windows
  31. Pentest Tools Github
  32. Hack Tools For Windows
  33. Hacker
  34. Hack Tool Apk No Root
  35. Pentest Tools Github
  36. Hacking Tools And Software
  37. Hack Tools Pc
  38. Hacking Tools Free Download
  39. Hacking Tools For Beginners
  40. Pentest Tools Online
  41. Hack Apps
  42. Hack Tools For Mac
  43. Hacker Tools 2020
  44. Pentest Tools Download
  45. Hacking Tools For Pc
  46. Blackhat Hacker Tools
  47. How To Make Hacking Tools
  48. Pentest Tools Bluekeep
  49. Hacking Tools For Windows 7
  50. Pentest Reporting Tools
  51. Hacker Tools Free Download
  52. Pentest Tools Download
  53. Pentest Tools Download
  54. Hacker Tools For Pc
  55. Hacking Tools Pc
  56. Hacking Tools Github
  57. Hacking Tools Usb
  58. Hacking Tools For Windows 7
  59. Hacking Tools For Pc
  60. Pentest Tools Nmap
  61. Hacker Tools Mac
  62. Hacking Tools For Windows
  63. Top Pentest Tools
  64. Tools 4 Hack
  65. Github Hacking Tools
  66. Hacker Tools Hardware
  67. Pentest Reporting Tools
  68. Hacking Tools 2019
  69. World No 1 Hacker Software
  70. Nsa Hack Tools
  71. Physical Pentest Tools
  72. Hacking Tools For Windows
  73. Hacking Tools For Windows 7
  74. Hacker Tools List
  75. Hacker
  76. Pentest Tools List
  77. Hack Tools Github
  78. Pentest Tools Website
  79. Nsa Hack Tools
  80. Hacker Tools
  81. Pentest Tools Url Fuzzer
  82. Best Pentesting Tools 2018
  83. Hacker Hardware Tools
  84. Hacking Tools Github
  85. Hacking Tools Download
  86. Hacker Tools List
  87. Hacker Tools Linux
  88. Physical Pentest Tools
  89. Pentest Tools Online
  90. Hacker Tools 2019
  91. Pentest Tools Review
  92. Best Hacking Tools 2019
  93. Hacker Tools For Ios
  94. Pentest Tools Windows
  95. Hacker Hardware Tools
  96. Hacking Tools For Windows Free Download
  97. Hacker Tools For Pc
  98. Pentest Tools Kali Linux
  99. Pentest Tools For Ubuntu
  100. Pentest Tools For Android
  101. Hackers Toolbox
  102. Tools Used For Hacking
  103. Hack Tools Mac
  104. Nsa Hack Tools
  105. Hacker Tools For Pc
  106. Hacking Tools Mac
  107. Hacker Hardware Tools
  108. How To Install Pentest Tools In Ubuntu
  109. Game Hacking
  110. Hacker Tools Free Download
  111. Hacking Tools Github
  112. Hacking Tools Usb
  113. Hacking Tools Download
  114. Hacking App
  115. Pentest Tools Windows
  116. Hacker Tools 2020
  117. Hacking Tools For Games
  118. Top Pentest Tools

No comments: