To add one to a variable's value, use ++, as in:
var++;
After this statement is executed, the value of variable var is incremented by 1. It's the same as writing this code:
var=var+1;
You'll find ++ used in for loops; for example:
for(x=0;x<100;x++)
This looping statement repeats 100 times. It's much cleaner than writing the alternative:
for(x=0;x<100;x=x+1)
#include <stdio.h> int main()/* www . j a v a 2 s .c om*/ { int x; for(x=0;x<10;x++) puts("hi!"); return(0); }
Use incrementing Operator inside while loop
#include <stdio.h> int main()/*from ww w . ja v a 2s. c o m*/ { int x; x=0; while(x<10) { puts("hi!"); x++; } return(0); }