set-sequence.cpp

Up: Array Notation
/*
 * set-sequence.cpp
 *
 * Demonstrate setting a sequence of elements of an array to a value using
 * both loops and Array Notation
 */

#include <stdio.h>
#include <string.h>

const int array_size=10;

int main(int argc, char **argv)
{
    int a[array_size];
    int b[array_size];

    // Setting a sequence of elements of an array to a value array using C/C++
    for (int i = 0; i < 7; i++)
        a[i] = 5;
    for (int i = 7; i < (7 + 3); i++)
        a[i] = 4;

    // Setting a sequence of elements of an array to a value array using Array
    // Notation
    b[0:7] = 5;
    b[7:3] = 4;

    // Verify the results - Arrays should be identical
    if (0 == memcmp(a, b, sizeof(a)))
        printf("Success\n");
    else
        printf("Failed\n");

    return 0;
}
Up: Array Notation