Thursday 19 November 2015

Pointers

A pointer (with information for this starting paragraph sourced from (TutorialsPoint, 2015), is basically a variable that can refer to another separate variable using the value of its address in code. It means you don't have to use the same variable a multitude of times throughout the code for different functions. Here is an example: "i.e., a direct address of the memory location. Like any variable or constant, you must declare a pointer before using it to store any variable address." 


#include <stdio.h>

int main () {

   int  var1;
   char var2[10];

   printf("Address of var1 variable: %x\n", &var1  );
   printf("Address of var2 variable: %x\n", &var2  );

   return 0;
}

The above code exists in order to print the address values of the variables in your code. And afterwards when you compile said code it will produce this in the console:

Address of var1 variable: bff5a400
Address of var2 variable: bff5a3f6


As extra information gathered by the C programming book by (Richard.R, 2013.), meaning it's a very reliable source since it was written by an official published author, Pointers can help make your code much shorter and more compact, meaning that the compiler has less code to process and thus the program will run more efficiently. When using C# any programmer should consider using these, as down the line with hundreds of thousands of lines of code n your game they can work very well for optimization of your creation, and will allow to run on lower-end hardware, and thus you'll be following a more professional working standard. 


No comments:

Post a Comment