-2

I am running my code with gcc. I have a function in which I declare a variable X1 which is initialized to 'inf'.

function(double nu, void *params) {
struct func_params *part= (struct func_params *)params;
double result;
*commands*
if (condition){
        double wb,X1;
        printf("inside if X1 %e \n",X1);
    }
return result;

this code is returning "inside if X1 inf". I never had that issue and I didn't change anything to the code...Any idea what it could be?

pulsar_hh
  • 125
  • 2
  • 9
  • Using uninitialized variables means that their value is what is in the memory at the time of allocation (which is unpredictable and can vary from one execution to another). – Sianur Aug 02 '18 at 12:39

1 Answers1

1

It is Undefined bahavior and your unitialized variable can have any value including inf & NaN.

When you use it you invoke the Undefined Behavior

0___________
  • 60,014
  • 4
  • 34
  • 74