Skip to content

Assign Values to Elements

The assignment statement allows you to store a value in a variable. This can now be extended to allow you to store a value in an element of an array. To achieve this, you indicate the array as well as the index of the element you want to store the value in.


Assigning a value to an element of the array
Assigning a value to an element of the array

Example

The following example creates two arrays, and assigns values to their elements.

#include "splashkit.h"
int main()
{
int data[4];
data[0] = 10;
data[1] = 72;
data[2] = -1;
data[3] = 0;
point_2d points[3];
points[0] = point_at(0, 0);
points[1] = point_at(0.4, -10.1);
points[2] = point_at(-1, 8.7);
}