Pointers in C
Next
Functions in C/C++ >| |
Each data used in an application must be defined, i.e. memory must be reserved for him. Assigning values to a data means that this value is stored in a binary form to a specific memory location. In this case, the data memory is occupied by the number of memory bits that it occupies for a particular type of data. For example. for the int-type data in C / C ++, this would be 16 or 32 bits.
Each memory location has its own address. This number is associated with a location. The smallest memory location that can be addressed independently is usually one byte.
The pointer is a free data into which the address of a location in the memory can be placed.
Data shown by pointers can be of different types.
Each memory location has its own address. This number is associated with a location. The smallest memory location that can be addressed independently is usually one byte.
The pointer is a free data into which the address of a location in the memory can be placed.
Data shown by pointers can be of different types.
When some data takes up more than one byte, the data address is the byte with the least serial number.
The address of a data in the memory can be obtained using the prefixed uninterrupted operator &. See more about operators on the pages operators in languages C/C++.
The address of a data in the memory can be obtained using the prefixed uninterrupted operator &. See more about operators on the pages operators in languages C/C++.
Defining the pointer
* pointer_identifier
Let's look at the following code:
Let's look at the following code:
int a=1;
int *pint;
pint= &a;
cout << a << endl;
cout << pint << endl;
On standard output:
An integer data was introduced and initialized to a value of 1. Also, a pint to the integer data was introduced and it was initialized with the memory address of the data a. Note that a large number in a hexadecimal record is obtained when printing a pointer value. Memory addresses are usually such values.
A description of the data type at the beginning of a declarative command indicates the type of displayed data. Previously, it was int int. the cursor points to the whole number. If the data were double, then the double data pointer would be defined and initialized in the following way:
double x =2;
double *pdb;
pdb= &x;
Assign data values via the pointer to another data
If we would like to introduce in the previous example another data of type double, for example. y and to initialize this value using a pointer to x, we would add the following code:
double x=2;
double *pdb;
pdb= &x;
double y;
y= *pdb; //y is now 2
Address arithmetic
In C / C ++, the following operations are allowed over the cursors:
- assigning a value to one pointer to another
- Adding integer data to the value of the pointer and deleting the integer data from the value of the pointer
- seizing and comparing two pointers
- comparison of the pointer by zero
Previous
|< Two-dimensional array-matrices |
Next
Functions in C/C++ >| |