Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Open arrays
// t11e06.OpenArray.cpp
// juanfc 2022-01-16
//
#include <array>
#include <iostream>
using namespace std;
const int N = 100;
typedef array<int, N> TVector;
struct TOpenArr {
int noelems;
TVector ar;
};
void printOArr(TOpenArr a);
TOpenArr sumOArr(TOpenArr a, TOpenArr b);
int main()
{
TOpenArr a = {3, {{1, 2, 3}}};
TOpenArr b = {3, {{3, 2, 1}}};
printOArr(sumOArr(a, b));
}
TOpenArr sumOArr(TOpenArr a, TOpenArr b)
{
TOpenArr r = {a.noelems};
for (int i = 0; i < a.noelems; ++i)
r.ar[i] = a.ar[i] + b.ar[i];
return r;
}
void printOArr(TOpenArr a)
{
for (int i = 0; i < a.noelems; ++i)
cout << a.ar[i] << " ";
cout << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment