[Solved] same program gives different outputs everytime I run [closed]


In these lines

int minX,minY=INT_MAX;
int maxX,maxY=INT_MIN;
       ^

minX and maxX is never initialized. This is an UB as defined by the standard. Whatever you read is not predictable – it’s usually what’l left on that block of memory by another process.

Do note that = has a higher priority than comma, so the expression is evaluated as

int (minX),(minY=INT_MAX);

Actually the comma has the lowest priority among all operators in C++. Change them to these should fix

int minX=INT_MAX,minY=INT_MAX;
int maxX=INT_MIN,maxY=INT_MIN;
         ^~~~~~~

1

solved same program gives different outputs everytime I run [closed]