PLease, help with this problem!

These are the first sentences of my code (I can ensure there is nothing before).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <fstream>
#include <iostream>
using namespace std;
#define n 4
#define m 4

float Lx= 0.9;
float Ly= 0.9;
int i;
int j;
float x[n];
float y[m];
 
main()
{
for (i=0;i<=n;i++){
    x[i] = Lx/((n-1)*2)+Lx/(n-1)*(i-1);}
x[0]=0;
x[n]=Lx;

for(i=0;i<=n;i++){
     cout << x[i] << " " ;}


for (j=1;j<=m;j++){
      y[j] = Ly/((m-1)*2)+Ly/(m-1)*(j-1);}

for(i=0;i<=n;i++){
     cout << x[i] << " " ;}
     
y[0]=0;
y[m]=Ly;
....

}


If this code form part of a complete code (which not modify the arrays y[j] or x[i]) I have problems with x(0) value, which is not 0 with the complete code and obviously 0 when I try in another file without the other part... WHY!?¿
You are in undefined behavior, all of your loops write to an out of bounds memory location.

//i = 0; until i <= n; This allows i to be 0, 1 ,2,3 (should break here but doesn't), 4. Your array is float x[n]; //size 4, so [0, 1, 2, 3]
thanks veeeeeery much. Now i understand... I saw the light! (now i have to modify 400 lines of code... fuck me)!
Topic archived. No new replies allowed.