VMWare Inc Interview Question
Software Engineer / DevelopersRefer the manual? No C required, plain or with fruit. Silly question.
Anyway, typical answer is to declare local variables and compare the address values.
Has anyone really run these testing programs and found that the stack from higher memory to lower? Then please let us know the platform that was used to test.
#include <iostream>
using namespace std;
int main (int argc, char * const argv[])
{
int a = 1;
int b = 2;
cout << (&a - &b) << endl;
getchar();
return 0;
}
Declaring two variables and finding the difference does not tell whether stack grows up or down.
Bcoz, both variable will be stored in the same stack frame.
So, Declare 1 variable in one funtion and another variable in another fucntion and find the difference of those address.
This will work, bcoz for each function there will be a separate stack created.
int main()
{
char a[] = {'a','b'};
if((&a[0] -&a[1])>0)
printf("\nDown");
else
printf("\nUp");
return 0;
}
Actual code is this--->
- Punch July 20, 2010int main()
{
int i;
void checkStack(int*);
checkStack(&i);
return 0;
}
void checkStack(int *j)
{
int k;
if(&k>j) printf("Stack is growing UP");
else printf("Stack is growing DOWN");
}
So we are actually checking the local variable address which should be in Stack;