58
P O I N T E R S: The Basics

P O I N T E R S: The Basics

5 years ago
Anonymous $Dftgs0JzgE

https://medium.com/@goutiemma/p-o-i-n-t-e-r-s-the-basics-afeb2b173d21

Pointers are one of the most powerful fundamentals of the C/C++ language, because developers are given direct access to the memory from one’s code in an easy and fast way. Pointers are variables whose value is the address of another variable, i.e., direct address of the memory location. So, in a sense pointers are a symbolic representation of addresses. They enable programs to simulate pass by reference, or pass by address, and can create and manipulate dynamic data structures. In other words, pointers allocate memory dynamically, which means memory allocated “on the fly” during run time that is usually placed in a program segment known as the heap or the free store. And when variables are passed by reference, the actual address is passed. If you’re still confused with the difference between pass by value and pass by reference, think of it like this: in the case of call by value we pass copies of values of passing arguments, in case of pass by reference, the address of the values is passed and no copies of the actual values are made. The important thing to take away is that, if you pass by reference, any manipulation of the data is reflected throughout. This means that if the value of a parameter changes in a function, that change will be reflected in the actual variable that you passed during the function call. However, the same is not true for pass by value. The changes are not reflected in the actual parameters.

To declare a pointer variable, you need to specify the data type of the value in the memory location that pointer variable points to. The syntax will look something like datatype identifier;, with the asterisk symbol being placed anywhere between the two. For convention, the asterisk is typically attached to the variable name, like this: int ptr or char *ch. All of the examples below, however, are equivalent.

Last Seen
39 minutes ago
Reputation
0
Spam
0.000
Last Seen
41 minutes ago
Reputation
0
Spam
0.000
Last Seen
a year ago
Reputation
0
Spam
0.000
Last Seen
46 minutes ago
Reputation
0
Spam
0.000
Last Seen
a couple of minutes ago
Reputation
0
Spam
0.000
Last Seen
43 minutes ago
Reputation
0
Spam
0.000
Last Seen
2 hours ago
Reputation
0
Spam
0.000
Last Seen
24 minutes ago
Reputation
0
Spam
0.000
Last Seen
6 hours ago
Reputation
0
Spam
0.000
Last Seen
15 minutes ago
Reputation
0
Spam
0.000
Last Seen
2 hours ago
Reputation
0
Spam
0.000
Last Seen
about an hour ago
Reputation
0
Spam
0.000
Last Seen
3 hours ago
Reputation
0
Spam
0.000
Last Seen
about an hour ago
Reputation
0
Spam
0.000
Last Seen
about an hour ago
Reputation
0
Spam
0.000
Last Seen
27 minutes ago
Reputation
0
Spam
0.000
Last Seen
8 minutes ago
Reputation
0
Spam
0.000
Last Seen
56 minutes ago
Reputation
0
Spam
0.000
Last Seen
a couple of minutes ago
Reputation
0
Spam
0.000
Last Seen
24 minutes ago
Reputation
0
Spam
0.000
Last Seen
2 hours ago
Reputation
0
Spam
0.000
Last Seen
13 minutes ago
Reputation
0
Spam
0.000
Last Seen
32 minutes ago
Reputation
0
Spam
0.000
Last Seen
23 seconds ago
Reputation
0
Spam
0.000
Last Seen
29 minutes ago
Reputation
0
Spam
0.000
Last Seen
about an hour ago
Reputation
0
Spam
0.000
Last Seen
18 minutes ago
Reputation
0
Spam
0.000
Last Seen
about an hour ago
Reputation
0
Spam
0.000
Last Seen
3 hours ago
Reputation
0
Spam
0.000
Last Seen
about an hour ago
Reputation
0
Spam
0.000
Last Seen
10 minutes ago
Reputation
0
Spam
0.000
Last Seen
a minute ago
Reputation
0
Spam
0.000
Last Seen
29 minutes ago
Reputation
0
Spam
0.000
Last Seen
about an hour ago
Reputation
0
Spam
0.000
Last Seen
32 minutes ago
Reputation
0
Spam
0.000
Last Seen
5 minutes ago
Reputation
0
Spam
0.000
Last Seen
about an hour ago
Reputation
0
Spam
0.000
Last Seen
39 minutes ago
Reputation
0
Spam
0.000
Last Seen
20 minutes ago
Reputation
0
Spam
0.000
Last Seen
27 minutes ago
Reputation
0
Spam
0.000
Last Seen
2 hours ago
Reputation
0
Spam
0.000
Last Seen
5 minutes ago
Reputation
0
Spam
0.000
Last Seen
about an hour ago
Reputation
0
Spam
0.000
Last Seen
10 minutes ago
Reputation
0
Spam
0.000
Last Seen
2 hours ago
Reputation
0
Spam
0.000
Last Seen
59 minutes ago
Reputation
0
Spam
0.000
Last Seen
about an hour ago
Reputation
0
Spam
0.000
Last Seen
49 minutes ago
Reputation
0
Spam
0.000
Last Seen
about an hour ago
Reputation
0
Spam
0.000
Last Seen
31 minutes ago
Reputation
0
Spam
0.000