Cursor in C / C ++
Pointer - Pointer in C / C ++ language is easy to learn and interesting. Some tasks in the C / C ++ language are made easier by pointers, and other tasks become more flexible, such as in memory allocation, which cannot be performed without using a pointer. Therefore it is necessary to master the cursor when becoming a complete C / C ++ programmer. Now start with the simplest steps.
As you know, each variable in a given memory area and each memory location has its address defined so that it is easy to access using the operator (&) corresponding to its address in memory. Looking at the example below, it will print the address of the variable defined:
#include using namespace std ; int main () { int bien1 ; char bien2 [ 10 ]; cout << "Dia chi cua bien1 la: " ; cout << & bien1 << endl ; cout << "Dia chi cua bien2 la: " ; cout << & bien2 << endl ; return 0 ; }
Running the above C / C ++ program will produce the following results:
What is a pointer?
A pointer is a variable in which its value is the address of another variable. For example, the address of the device. Like variables and constants, you must declare the pointer before you can use it to store any address of the variable. The general form of cursor declaration is as follows:
kieu_du_lieu * ten_bien ;
Here, kieu_du_lieu is the basic pointer data type, it is valid type in C language and ten_bien is the value name of the cursor. The * character part used in declaring pointers is the same as what you use for multiplication. However, in this declaration, the * character is designed to use pointer variables. Here are some valid declarations of pointers:
int * sv ; // tro toi mot gia tri nguyen double * nv ; // tro toi mot gia tri double float * luong ; // tro toi mot gia tri float char * ten // tro toi mot ky tu
The actual data type of the value of all pointers, be it integer, float, character, or other type, is like, some hexadecimal represent a memory address. The only difference of pointers of different data types is the data type of the variable or constant that the pointer points to.
How to use pointers in C / C ++
There are several important operations, which will help us work with pointers on a regular basis: a) we define pointer variables, b) assign the address of the variable to a subset and c) finally access Address variable values in pointer variables. This is done by the operator * returning the value of the variables contained in the address specified by this operator. Here are the uses of the above operations:
#include using namespace std ; int main () { int bien1 = 15000 ; // khai bao bien. int * sv ; // bien con tro sv sv = & bien1 ; // luu tru dia chi cua bien1 vao bien con tro sv cout << "Gia tri cua bien1 la: " ; cout << bien1 << endl ; // In dia chi duoc luu tru trong bien con tro sv cout << "Dia chi duoc luu tru trong bien con tro sv la: " ; cout << sv << endl ; // Truy cap gia tri co san tai dia chi cua bien con tro cout << "Gia tri cua *sv la: " ; cout << * sv << endl ; return 0 ; }
Running the above C / C ++ program will produce the following results:
Details about pointers in C / C ++
Pointers have many concepts but are quite easy to learn and very important in C / C ++ language programming. Here are the important concepts about pointers in C / C ++, which are clearly presented to you, when you click on the corresponding link.
Concept DescriptionNull pointer in C / C ++
C / C ++ supports null pointers, which are a constant with a value of 0 defined in some standard librariesArithmetic pointer in C / C ++
There are 4 algebra operators that can be used on pointers: ++, -, +, -Pointers and arrays in C / C ++
What is the relationship between pointer and array? You check now.Cursor array in C / C ++
You can define arrays to hold pointers.Pointers to pointers in C / C ++
C / C ++ allows you to point to a pointer .Pass cursor to function in C / C ++
Pass a parameter by reference or address: both for passed parameters can be changed in the function called by the called function.Returns the pointer from the function in C / C ++
C / C ++ allows a function to return a pointer to a local variable, static variable, and also dynamically allocated memory.According to Tutorialspoint
Previous lesson: String (String) in C / C ++
Next article: Cursor NULL in C / C ++
You should read it
May be interested
- How to change the mouse cursor in Windowshow to change the mouse cursor in windows - in this article, i will show you how to change the mouse cursor in the following two main ways.
- Replace the mouse cursor with funny picturesinstead of the default windows mouse cursor, you can create more funny and lovely mouse pointers that suit your taste and help create more interest in working with computers.
- How to change the cursor size on the Debian 10 desktopdebian allows you to change the cursor size via the settings utility. you can access the settings utility through the application launcher search.
- Macromedia Flash - Dynamic cursor objectread this exercise and see how to create a dynamic cursor with just a few basic steps and of course use action script in flash 8.
- Macromedia Flash - Move objectswith this exercise, you will learn how to move any object with the cursor in flash 8 using the action script.
- The basic steps of fixing cursor cursors flutter in Windowsthe status of the mouse pointer jumps, the mouse is disordered or the mouse moves automatically while typing the keyboard occurs quite popular, it causes inhibition for the user to keep the mouse to hold the cursor back. this may be because the touchpad on your laptop is too sensitive or maybe because you accidentally touched the touchpad when typing. please try to apply the following corrections below.
- Macromedia Flash - Push objects away from the cursorthis tutorial will show you how to make a flash file with the effect of pushing the object away from the cursor by using some action script fragments in flash 8. let's look at the following example file.
- Create snow effect when moving mouse on Windowsin many parts of the world, snow began to fall and turn everything into a white color from the roof, the street, the park, the playground, everything looked like a long white sheet of paper. you can create snowfall in your computer using the cursor snowflakes software, making it snow every time you move the mouse on the screen.
- How to Restart Windows 8to restart windows 8, move the cursor to the upper/lower right corner → click → click the button → click . you can also use an alternate method that uses only the keyboard in situations where you cannot use the mouse. move your cursor to th...
- Mouse cursor spins error in Windows 10+11 and how to fix it quicklyare you feeling annoyed because the mouse pointer keeps spinning in windows 10+11? it's okay, tipsmake has measures in place