fork download
  1. #include <stdio.h>
  2.  
  3. int foo( int n, void (*notify)(int) )
  4. {
  5. int sum = 0 ;
  6. for( int i = 1 ; i < n ; ++i )
  7. {
  8. sum += i*i ;
  9. notify(sum) ;
  10. }
  11. return sum ;
  12. }
  13.  
  14. void report_progress( int s )
  15. { printf( "intermediate value returned: %d\n", s ) ; }
  16.  
  17. int main()
  18. {
  19. foo( 10, report_progress ) ;
  20. }
  21.  
Success #stdin #stdout 0s 1832KB
stdin
Standard input is empty
stdout
intermediate value returned: 1
intermediate value returned: 5
intermediate value returned: 14
intermediate value returned: 30
intermediate value returned: 55
intermediate value returned: 91
intermediate value returned: 140
intermediate value returned: 204
intermediate value returned: 285