//* Use of variables - global scope *

#include <stdio.h> int sum = 0; // this variable is accessible from everywhere below in this file int sum_so_far(int x) { sum = sum+x; return(sum); } // this function hides potentially complicated data processing // it accepts new data item and returns updated result/outgoing item // its internal state is kept in the global variable(s) int main() { for (;;) { int data, processed; scanf("%d", &data); if (data<0) break; processed=sum_so_far(data); printf("TL: %5d\n", processed); // printf("TL: %5d\n", sum); // this will work too } return(0); }