viernes, 19 de enero de 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'.

More articles


  1. Hackrf Tools
  2. Tools 4 Hack
  3. Tools For Hacker
  4. How To Make Hacking Tools
  5. Pentest Tools Apk
  6. Hacker Tools List
  7. Pentest Tools Url Fuzzer
  8. Hacker Tools Free
  9. Hacker Tools For Ios
  10. Usb Pentest Tools
  11. Nsa Hack Tools
  12. Hacker Tools Apk Download
  13. Hacking Tools Usb
  14. Wifi Hacker Tools For Windows
  15. Hack Apps
  16. Hack Tools
  17. Hacking Tools And Software
  18. Hacking Tools Hardware
  19. Nsa Hack Tools
  20. Hak5 Tools
  21. Hacker Tools For Ios
  22. Hacker Tool Kit
  23. Hacking Apps
  24. Hacking Tools 2019
  25. Hacking Tools For Windows
  26. Pentest Tools For Mac
  27. Hack Tools Github
  28. Hacking Tools Mac
  29. Pentest Tools Port Scanner
  30. Pentest Tools
  31. Pentest Reporting Tools
  32. Hacking Tools Windows 10
  33. Beginner Hacker Tools
  34. Physical Pentest Tools
  35. Pentest Tools Nmap
  36. Best Hacking Tools 2020
  37. Underground Hacker Sites
  38. Hack Tools For Pc
  39. Beginner Hacker Tools
  40. New Hacker Tools
  41. Hack Website Online Tool
  42. Hacks And Tools
  43. Pentest Tools Linux
  44. Hacker Tools Apk
  45. Pentest Box Tools Download
  46. Pentest Tools For Mac
  47. Pentest Tools For Ubuntu
  48. How To Make Hacking Tools
  49. Best Hacking Tools 2019
  50. Pentest Recon Tools
  51. Pentest Tools Review
  52. World No 1 Hacker Software
  53. Pentest Tools Review
  54. Hack Tools Mac
  55. Pentest Tools For Android
  56. Black Hat Hacker Tools
  57. Hack Rom Tools
  58. Hack Tool Apk
  59. Hacker Tools For Ios
  60. Hacking Tools Name
  61. Pentest Tools Url Fuzzer
  62. Pentest Tools Review
  63. Hacker Tools For Mac
  64. Hacking Tools Download
  65. Pentest Tools Kali Linux
  66. Pentest Tools For Android
  67. Hacker Tools Free
  68. Hacker Tools Apk
  69. Pentest Tools List
  70. Hacking Tools And Software
  71. Hacker Hardware Tools
  72. Pentest Tools Alternative
  73. Hack App
  74. Hacker Tools For Pc
  75. Blackhat Hacker Tools
  76. Hacker Tools
  77. Tools Used For Hacking
  78. Hack App
  79. Install Pentest Tools Ubuntu
  80. Hacker Tools Free
  81. Hack Tool Apk No Root
  82. Pentest Tools Apk
  83. Hacker Tools 2020
  84. Hacking Tools Software
  85. Github Hacking Tools
  86. Hacker Tools Hardware
  87. Pentest Tools For Mac
  88. Hackers Toolbox
  89. Pentest Box Tools Download
  90. Tools For Hacker
  91. Hack Tool Apk
  92. Hacker Tools Online
  93. Hack And Tools
  94. Pentest Tools Windows
  95. Hacking Tools Github
  96. Hack Tools Github
  97. Hacking Tools Software
  98. Github Hacking Tools
  99. Pentest Tools Android
  100. Hacking Tools Online
  101. Pentest Tools Android
  102. Pentest Tools Framework
  103. Hacker Techniques Tools And Incident Handling
  104. Pentest Tools Kali Linux
  105. Install Pentest Tools Ubuntu
  106. Hacking Tools And Software
  107. Blackhat Hacker Tools
  108. Hacking Tools For Pc
  109. Beginner Hacker Tools
  110. Pentest Box Tools Download
  111. Hack App
  112. World No 1 Hacker Software
  113. Wifi Hacker Tools For Windows
  114. Hacker Tools Free Download
  115. Hack Tools Pc
  116. Hacker Security Tools
  117. Pentest Tools Website
  118. Hacking Tools For Windows 7
  119. Hacking Tools Free Download
  120. Pentest Automation Tools
  121. Hacker Tools 2019
  122. Ethical Hacker Tools
  123. Tools 4 Hack
  124. Hacking Tools 2020

No hay comentarios:

Publicar un comentario