fork download
  1. struct date
  2. {
  3. int month;
  4. int day;
  5. int year;
  6. };
  7.  
  8. /* function prototype */
  9. struct date nextDay (struct date dateval);
  10.  
  11. #include <stdio.h>
  12. int main ()
  13. {
  14.  
  15. /* two structure variables */
  16. struct date today, tomorrow;
  17.  
  18. /* set today to the proper date */
  19. today.day = 2;
  20. today.year = 2026;
  21. today.month = 3;
  22.  
  23. /* This statement illustrates the ability to pass a */
  24. /* structure to a function and to return one as well */
  25.  
  26. tomorrow = nextDay (today); /* tomorrow, not today, will be updated */
  27.  
  28. printf ("%d/%d/%d\n", tomorrow.month, tomorrow.day, tomorrow.year-2000); /* Y2K Problem? */
  29.  
  30. return (0);
  31. }
  32.  
  33. struct date nextDay (struct date dateval) /* notice the return type - struct date */
  34. {
  35.  
  36. ++dateval.day; /* add a day, does not check for max days in the month */
  37.  
  38. return (dateval); /* returned updated structure (all members) back to the calling function */
  39.  
  40. } /* nextDay */
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
3/3/26