game - design - multimedia - web - programming - tutorials - There are currently viewers visiting Apron Tutorials.

TECHNICAL
GRAPHICAL
SOUND
GAME
WEB
ARTICLE
TOOL
PROJECT

 NEWS
 TECHNICAL TUTORIALS
 WEB TUTORIALS
 IMAGE EDITING
 3D MODELING
 PROJECTS
 DEMOS
 ARTICLES
 COMMUNITY

 ```#include #include using namespace std; // declare our swap number function void swap_numbers(int *num1, int *num2); int main() { // PART I //////////////////// // declare a new variable num as integer int num; // declare a pointer pNum (the p shows that the variable is a pointer) int *pNum; // let pNum point to the address of num pNum = # // set a value to the location that pNum points to. *pNum = 8; // display num cout << "num = " << num << endl << endl; // PART II /////////////////// int num1 = 1; // num1 = 1 int num2 = 2; // num2 = 3 swap_numbers(&num1, &num2); // swap the numbers // display numbers cout << "num1 = " << num1 << endl << "num2 = " << num2; getchar(); // wait for a key to be pressed return 0; // return zero } // define our swap number function void swap_numbers(int *num1, int *num2) { int temp = *num1; *num1 = *num2; *num2 = temp; } /* This tutorial demonsterates the use of pointers. Pointers are one of the most hated and loved subjects in c++. It's one of the things that separates c++ from the other programming languages. If you handle pointers right, you will be able to increase the speed of your applications, and decrease the amount of used memory. When you see this symbol * in c++ it means that a pointer is used. When we declare a variable it's really just a series of memory cells, that we can acess by an identifier. example: a short int uses 16 bit (2 byte), a long int uses 32 bit (4 byte) Let say that when you declare int myVariable; it uses 32 bit, and the variable gets an unique address in memory. A good simile for the computer memory can be a street in a city. On a street all houses are consecutively numbered with an unique identifier so if we talk about 27th of Sesame Street we will be able to find that place without loss, since there must be only one house with that number and, in addition, we know that that house will be between houses 26 and 28. In the same way in which houses in a street are numbered, the operating system organizes the memory with unique and consecutive numbers, so if we talk about location 1776 in the memory, we know that there is only one location with that address and also that is between addresses 1775 and 1777. Using a pointer we can access directly to the value stored in the variable pointed by it just by preceding the pointer identifier with the reference operator asterisk (*), that can be literally translated to "value pointed by". declare a pointer: int *pNum; define the pointer(let the pointer point to): pNum = # */ ```

 I hope you found this c++ tutorial useful! Don't forget to mention Apron Tutorials in your References! Best Regards Ronny André Reierstad