Advertisement
Guest User

Untitled

a guest
May 14th, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // this function gets called from main and with value 2 being passes to this paramether named countVar
  2. // now we can use it inside this function and do whatever we want with it.
  3. void methodToCall (int countVar)
  4. {
  5.     // The "true" part of the if statement only runs once when the program comes to an end
  6.     // this is where it should end
  7.     // but not until all frames removed from the stack
  8.     // the top frame would be with the countVar value of 0;
  9.     // it gets removed, but now it must continue where it stopped
  10.     // printf("Now lets continue where we left before and the value of countVar is %d\n",countVar);
  11.     //
  12.     if (countVar == 0){ // "true part of the if statement"
  13.         printf("\nThat is it, it is the end of the program countVar value is %d\n", countVar);
  14.         printf("Lets clear the stack and remove frame by frame starting with the top frame\n");
  15.     } else {
  16.         printf("The value of countVar is %d lets deduct 1 from countVar and call this method again \n", countVar);
  17.         int oneLessVar = countVar -1;
  18.         methodToCall(oneLessVar);
  19.         // this is where it stopped so now it needs to finish this function before we can remove the frame from the stack.
  20.         printf("\nNow lets continue where we left before and the value of countVar is %d\n",countVar);
  21.        
  22.     }
  23.         // this runs when if loop has finished its job
  24.         printf("Frame with countVar with the value of %d is removed\n", countVar);
  25. }
  26.  
  27. int main(int argc, const char * argv[])
  28. {
  29.     // this is where it all starts
  30.     methodToCall(2);
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement