Skip to main content

Pointers, Arrays, and References

In C++, arrays are used to store a fixed-size sequence of elements of the same data type. To create an array in C++, you need to follow certain requirements:

 

Alternatives to Pointer:

Looking at Pointer heavy code is difficult to determine intent of the programmer. Consider using the Standard Library before using pointers for general Software EngineeringEngineering. In modern C++ (11 and later) 

  • To hold a collection of values, consider a container, such as vector, set, map, unordered_map, or array
  • To hold a string of characters, consider String
  • To point to an object you own (i.e., must delete) use unique_ptr, or shared_ptr
  • To point to a continguous sequence of elements that you dont own, use span 
  • To systematically avoid dereferencing a null pointer, use not_null


Pointers are not use in C-style Shader languages like GLSL/HLSL, but is critical to understand in Vulkan, and to lesser degree OpenGL.