I was researching how to declare functions, but got stuck trying to declare one that would print a series of lines inside a structure. I was wondering how it was possible to do it.
I've simplified my whole program here, but basically that's what I need it to do.
#include <iostream>
struct Dato {
int a;
int b;
}Prueba[2];
Void MuestraLista() {
std::cout << "1) Numero de empleado: " << Prueba[1].a << "\tSueldo: " <<
Prueba[1].b;
std::cout << "\n2) Numero de empleado: " << Prueba[2].a << "\tSueldo: "
<< Prueba[2].b;
}
int main(){
Prueba[1].a=500;
Prueba[1].b=300;
Prueba[2].a=600;
Prueba[2].b=100;
MuestraLista();
system ("pause");
}
It's basically mishandling your array.
When a new ARRAY of size N is CREATED , it must be traversed from , this for all languages, or at least for c, c++, java, javascript, c#, python, VB, php, among many others.
0 hasta N-1
So, when you do
Prueba[2]
, you are pointing to a non-existent index, causing an out of memory error.I hope I have helped.