Search code examples
cfor-loopgarbage

Why is the value of this variable changing to garbage once inside for-loop? C


Why is the value of n changing to garbage inside the for-loop? (I'm new to C language, I come from a C++ background)

float n = 3.0;
printf ("%f\n", n);
for (; n <= 99.0; n += 2)
    printf ("%f\n", &n);

enter image description here


Solution

  • You are printing the address of n (&n) inside the for-loop. Get rid of the &