Programming – Week 2

This week we worked with pointers in C++. You create a pointer by adding a
” * ” at the end of the data type. Pointers works just like the name describes, it points towards a memory address instead of a value. To access a variables memory address you add ” & ” in front of the variable name. To access the value of a pointer you can use ” * ” in front of the pointer variable.

This is an example of how pointer can be used:


#include 

void main()
{
  int variable = 5;
  int* pointer = &variable;

  std::cout << "Address: " << pointer << "nValue: " << *pointer;
  std::cin.get();
}


We also started a new project to create the classic Pong game. In order to create a window and draw graphics we use a library called SDL (Simple DirectMedia Layer). By using functions and data types from SDL library we could create our own window and graphics-renderer.
The game works by having a game loop, in this case a while loop. We handle all logic in a function called ”Update” and after all logic is done we call a function called ”Draw” which renders everything to the screen. By creating Pong we learned about creating structs, using functions and more.

About Semih Parlayan

2014  Programming