fork(2) download
  1. /* Tutorial 2 on variables (c) 2012 David Bolton http://cplus.about.com */
  2.  
  3. #include <stdio.h>
  4.  
  5. /* declared globally */
  6. float leftpocket = 10.50;
  7. float rightpocket = 3.75;
  8. float totalwealth;
  9.  
  10. int main(int argc, char* argv[])
  11. {
  12. /* day is declared local to main */
  13. int day = 4;
  14. day++;
  15. day += 1;
  16. day = day + 1;
  17.  
  18. totalwealth = leftpocket + rightpocket;
  19.  
  20. printf("%d\n\r",day); /* should be 7 */
  21. printf("%f\n\r",totalwealth);
  22. printf("On day %d I had %f in my left pocket and %f in my right pocket\n\r",day,leftpocket,rightpocket);
  23. printf("On day %d I had $%5.2f in my left pocket and $%5.2f in my right pocket\n\r",day,leftpocket,rightpocket);
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0.01s 1676KB
stdin
Standard input is empty
stdout
7

14.250000

On day 7 I had 10.500000 in my left pocket and 3.750000 in my right pocket

On day 7 I had $10.50 in my left pocket and $ 3.75 in my right pocket