Skip to content

Instantly share code, notes, and snippets.

@sukeesh
Last active August 4, 2017 08:20
Show Gist options
  • Save sukeesh/94659d82b5224f5cebe790bc7a12a07a to your computer and use it in GitHub Desktop.
Save sukeesh/94659d82b5224f5cebe790bc7a12a07a to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int *go(int x){
int y = 0;
if (x == 1){
return &y; // Address of stack memory associated with local variable 'y' is returned
}
int *val = go(x - 1);
if ( val > &y ){
cout << "Stack is growing towards higher address" << endl;
}
else{
cout << "Stack is growing towards lower address" << endl;
}
return &y;
}
int main(){
go(4);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment