Close
Close

I am tryng to run for loop in codeblocks with the shown code.Though I haven't initialized the variable a, helloworld is getting printed 8 times.why so

   mahi6683

#include<stdio.h>

     int main ()

{

int a;
      while(a<10)

     {

       printf("helloworld ");
       a++;
     }
     return 0;

}


Answers

  •   

    If the memory values are not defined by the user at the start of the code’s execution in C, the CPU will set the variable value to anything that is acceptable in computer programming language, this is usually termed as garbage value.


    • Also if I m initiating with a negative value say -1 it is printing only 10 times instead of 11.Why?
      - mahi6683
    • And thankks for ur help.
      - mahi6683
    • if u initiatize a=-1 then value of a in every loop get incremented every time by 1 n whileloop will run till a=9 i.e 11 times.
      - pongo

Ask Yours
Post Yours
Write your answer