Sujet : "undefined behavior"?
De : nospam (at) *nospam* dfs.com (DFS)
Groupes : comp.lang.cDate : 12. Jun 2024, 21:47:23
Autres entêtes
Message-ID : <666a095a$0$952$882e4bbb@reader.netnews.com>
User-Agent : Betterbird (Windows)
Wrote a C program to mimic the stats shown on:
https://www.calculatorsoup.com/calculators/statistics/descriptivestatistics.phpMy code compiles and works fine - every stat matches - except for one anomaly: when using a dataset of consecutive numbers 1 to N, all values > 40 are flagged as outliers. Up to 40, no problem. Random numbers dataset of any size: no problem.
And values 41+ definitely don't meet the conditions for outliers (using the IQR * 1.5 rule).
Very strange.
Edit: I just noticed I didn't initialize a char:
before: char outliers[100];
after : char outliers[100] = "";
And the problem went away. Reset it to before and problem came back.
Makes no sense. What could cause the program to go FUBAR at data point 41+ only when the dataset is consecutive numbers?
Also, why doesn't gcc just do you a solid and initialize to "" for you?