Advertisement
RicardasSim

return value

Dec 30th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int f1(int x, int y){
  6.     return x+y;
  7. }
  8.  
  9. int f2(int x){
  10.     return ++x;
  11. }
  12.  
  13. int f3(int x){
  14.     return x++; /*  postfix version, return value will not be incremented,
  15.                     use the prefix version to increment before returning, ++x
  16.                     example f2()
  17.                 */
  18. }
  19.  
  20. int f4(int x){
  21.     x++;
  22.     int y = x;
  23.     return y;
  24. }
  25.  
  26. int main (int argc, char **argv){
  27.  
  28.     int a,b;
  29.    
  30.     a = 1;
  31.    
  32.     b = 2;
  33.    
  34.     printf("f1: %d\n",f1(a,b));
  35.     printf("f2: %d\n",f2(a));
  36.     printf("f3: %d\n",f3(a));
  37.     printf("f4: %d\n",f4(a));
  38.    
  39.     return 0;
  40. }
  41.  
  42. /*
  43.  output:
  44.  
  45. f1: 3
  46. f2: 2
  47. f3: 1
  48. f4: 2
  49.  
  50.  
  51.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement