Monday, July 9, 2007

Write a program to check if the stack grows up or down.

Try noting down the address of a local variable. Call another function with a local variable declared in it and check the address of that local variable and compare!.


#include < stdio.h >
#include < stdlib.h >

void stack(int *local1);

int main()
{
int local1;
stack(&local1);
exit(0);
}

void stack(int *local1)
{
int local2;
printf("\nAddress of first local : [%u]", local1);
printf("\nAddress of second local : [%u]", &local2);
if(local1 < &local2)
{
printf("\nStack is growing downwards.\n");
}
else
{
printf("\nStack is growing upwards.\n");
}
printf("\n\n");
}

26 comments:

sujit.das said...

This is the wrong one. just reverse one is OK
if(local1 > &local2)
{
printf("\nStack is growing downwards.\n");
}
else
{
printf("\nStack is growing upwards.\n");
}
printf("\n\n");
}

sekhar said...

if(local1 < &local2)
{
printf " Stocking Growing to Higher address"
}
else{
printf " Stocking Growing to Lower address"
}

Anonymous said...

Someone pl clarify the doubt in this question

Anonymous said...

Shouldn't the program be as below? The earlier authors are comparing address of local2 with the address inside local1 passed from main.

if(&local1 > &local2)
{
printf("\nStack is growing downwards.\n");
}
else
{
printf("\nStack is growing upwards.\n");
}
printf("\n\n");
}

Anonymous said...

Is should not be: if(&local1 > &local2)

local1 is a pointer, so it's value is already the address of the local.

&local would give you the address of the pointer itself.

Anonymous said...

Cleonjoys:-

I don't understand the reason to fight on this. I would suggest to get into the memory layout of a process before discussing on whether stack grows up(any new stack frame residents getting incremental memory address) or down(decremental address). In UNIX, esp Solaris, Stacks begin @ Higher address and start downwards as new things getting inside.

Ex:

#include

int main(int argc, char **argv){
int a, b;

printf("Address of a is %d, and b is %d\n", &a, &b);

return 0;
}

O/P:

Address of a is 134511156, and b is 134511152

So the two automatic stack variable allocated on stack with incremental
address, so in respect to discussion its growing downwards.

Anonymous said...

Should declare the variables volatile. Otherwise the variables can be put in registers (and yes addresses thereof can be legitimately taken)

Uttam Agrawal said...

Sample C Program To Accept A String & Display Number Of Vowels.

Sample C Program To Accept A String & Display Number Of Each Vowels.

Sample C Program To Accept A String & Find Out Whether This Character Is Present In The String.

Sample C Program To Find Out The No. Of Times A Character Is Present In The String.

Sample C Program To Understand Working Of Address Concept.

Sample C Program On Use Of Array & Pointer Concept Together.

Sample C Program On Pointers & 2 - Dimensional Array.

Sample C Program On Strings Into Array Of Pointers.

Sample C Program To Accept & Add Ten Numbers Using Pointers.

Sample C Program To Implement Recursive Algorithm Using Pointers.

Sample C Program With Algorithm To Implement Bubble Sort Using Pointers.

Sample C Program To Implement Selection Sort Using Pointers, Arrays & Functions.

sandeep kumar said...

Thanks for the info. It is very helpful.
RegardsEducational site
Get jobs info at Educational site

Anonymous said...

You can see precisely why As i urge in opposition to co-signing for the purpose of financial loans. It's really a problems holding out to occur. And the ones [url=http://pozyczkibezbik24.net.pl]pożyczki pozabankowe zawiercie[/url] online payday loan advice corporations might not send out just what that they predict.
A payday cash loan is usually a short-term mortgage loan having big service fees a large number of consumers secure simply because they still find it the answer [url=http://pozyczkibezbik24.org.pl]o wiele więcej znajdziesz tutaj[/url] to have an prompt concern. Any mortgage loan might possibly cover or perhaps put off the afternoon of reckoning, still it's often the particular most extreme conceivable answer. Almost all borrowing products usually are explained more than sometimes since the customer lacks good enough dollars to pay for your regular bills. Sanctioned aggresive, pricey cycle that could be quite challenging to fix and also factors massive debt problems for numerous groups.

Your current lender is definitely correct, however. This loan product services enterprise will endeavour to be in a person's payday cash advances for less than your expenses. Still until eventually it will be profitable (as well as mind-boggling absolute majority typically are not) you'll continue on to get over the impressive arranged attempts from the loan service. In addition to sending an important cease-and-desist mail isn't going to discontinue selection efforts. Any Good Commercial collection agency Strategies Conduct yourself discourages [url=http://pozyczkibezbik24.net.pl]pożyczki pozabankowe radom[/url] credit card companies with contacting people for those who ship a letter prompting it again. They even so might possibly file a claim everyone in in the court.
Here i will discuss the advice: As i won't frequently suggest asking for in order to get out of credit debt, but your loan combination home loan might be a good indication on your behalf. The item will help you pay out your financial situation [url=http://pozyczkabezbik24.org.pl]pozyczkabezbik24.org.pl[/url] in full. Often, less complicated was required to distribute monthly payments towards a brand-new loan service. People expenditures could i hope become in the reduced rate of with lesser number of extra fees.

Previous to taking on some combination lending product, be sure you understand the interest speed, fines pertaining to overlooked funds. In addition, you needs to turn out to be you've enough cash flow to make your funds. Still, instead of giving that will substantiation your own self, It is advisable to talk to your associate to help intensify along with get liability just for this consumer debt. This individual need worked on [url=http://pozyczkibezbik24.org.pl]rekomendowana strona[/url] that from the beginning. In conclusion, It's safe to experience much better in case you went on some sort of consolidation mortgage at a well-liked mortgage lender such as a traditional bank or simply credit rating un.
When my personal subscribers happen to be critically thinking about payday loans, I suggest many at the least acquire pożyczki bez bik that precaution in getting a loan provider this can be a person in the, as their members join some community guidelines.

Anonymous said...

If we glance at the specification of the expression like, with terms of a captivating connection using an additional, but for a experiencing that is definitely engendered for those who have miltchmonkey an improved marriage on your own as well : and even to be a feeling of increased oneness family members or even mankind - that develops into much more extra ordinary that each one everyone is seeking in your daily course is actually really enjoy.

Anonymous said...

You actuallу make it ѕeem so еasy together ωith yοur ρrеsentation but I find this matter to be really оne thing whiсh I believe I'd never understand. It sort of feels too complicated and extremely large for me. I'm looking forωaгd for your
neхt submit, I will try to get the hang of it!


Alѕo visit my wеb ρage
Payday Loans
Also see my page > Payday Loans

Anonymous said...

Experiencing not any credit scores are sometimes tremendous obstacle if looking for a payday loan. Creditors should have enough advice to manufacture a decision. Scarcity of credit ranking can be described as losing piece while in the problem. It means the particular customer has not beforehand took out profit, had very little bank cards, basically no recommendations that could confirm his/her debt capabilities. Developing zero credit scores [url=http://pozyczkibezbiktop.net.pl]pożyczki bez bik[/url] is not only problematical on the subject of acquiring a personal loan, but it also can be a difficulties with areas of everyday living, as an example if looking to get a high-rise apartment (landlords test consumer credit plus references via many other landlords). Then again, all of us acquired not any credit standing in the beginning. You will want to beginning to formulate ones own credit scores sooner or later around your life. There would be wise to become at the first try pertaining to all. The good thing is, you will find loan providers so, who be aware that basically no credit scores may be a recent get started in as well as a prospective brand new shopper [url=http://szybkapozyczka247.net.pl]pożyczki prywatne tychy[/url] meant for a considerably long time. Whilst mortgage lenders together with debit card enterprises experience rigorous loans necessities, increasing credit rating isn’t hopeless, however it would be complicated. There are plenty of strategies for getting rid of basically no consumer credit rating, as an illustration eliminating a good fitting up loans using a secured personal or perhaps co-signer, trying to find a fabulous secured visa or mastercard, always keeping active data balanced, etc.

Cash loans may not be the biggest instrument for gathering credit history. Like a situation with point, they can put together credit scores just involving fast cash providers, although implement very little regarding normal loan companies similar to banking companies.

A number of concerning cash advance loans, nevertheless, will be [url=http://pozyczkiprywatnebezbik.org.pl]http://pozyczkiprywatnebezbik.org.pl[/url] the advantage that very little loan companies perfectly examine an individual's credit report, so it doesn’t quite topic for those who have basically no credit scores and also undesirable credit history when you however take a great potential for receiving sanctioned for just a loan product you will want. Virtually no consumer credit test is usually a problem solver in case that a desperate state of affairs develops any time cash is necessary speedy and the other doesn't have consumer credit and poor credit ratings and simply doesn't have time for it to use developing greetings credit rating. Fast cash banks you should not request difficult requests along with they do not necessitate guarantee [url=http://kredytbezbikuoferty.org.pl]kredyt bez bik[/url] or even a co-signer nevertheless give on the spot fast payday loans on a single moment of application form most often. They've also been fairly extremely fast and additionally practical. What is more, these are to choose from 24/7 for example weekends and annual vacations. Yet, payday advances are short-term and also small-dollar lending products along with high interest levels as well as investment expenses. Hence, cash loans will be for individuals that are usually absolutely certain they're going to easily afford to repay that loan product to come back only when it's expected.

Anonymous said...

What a stuff of un-ambiguity and preserveness of valuable know-how on
the topic of unexpected feelings.

Here is my homepage: research a review on web site cedar finance
My web page :: Learning Forex Trading

Anonymous said...

http://www.cafb29b24.org/docs/buyativan/#91634 buy ativan online pharmacy - ativan liver

Anonymous said...

I like to all a touch of shade when dealing with Christmas card
"envelopes". Is it hard to add an easy "clip craft" sweet walking cane or Christmas Bells
or Minature Christmas tree when making use of tags?
Believe I will certainly begin making use of tags this
year.
Many thanks!
Ellen.

Feel free to surf to my web site xerox phaser 8560dn

Anonymous said...

Great goods from you, man. I have understand your
stuff previous to and you are just extremely excellent.
I actually like what you've acquired here, really like what you are stating and the way in which you say it. You make it entertaining and you still care for to keep it wise. I can't wait to read much more from you.
This is really a great site.

my weblog :: ABC Personal Financing

Anonymous said...

Hey I am so glad I found your blog, I really found you by mistake, while I
was searching on Yahoo for something else, Nonetheless I am here now and would just like to say thanks a lot for a remarkable
post and a all round exciting blog (I also love the theme/design), I don't have time to browse it all at the moment but I have bookmarked it and also included your RSS feeds, so when I have time I will be back to read a great deal more, Please do keep up the superb work.

my web site ... xerox 8560mfp driver

Anonymous said...

Hello this is kinda of off topic but I was wondering if
blogs use WYSIWYG editors or if you have to manually code with HTML.
I'm starting a blog soon but have no coding expertise so I wanted to get advice from someone with experience. Any help would be enormously appreciated!

Look into my website - payday loan lenders

Anonymous said...

Hurrah! At last I got a web site from where
I know how to genuinely get helpful information concerning
my study and knowledge.

My page ... xerox 8560 ram error

Anonymous said...

I am really inspired with your writing skills and
also with the structure for your weblog. Is this a paid
theme or did you customize it yourself? Anyway keep up the excellent high quality writing, it's uncommon to peer a great blog like this one these days..

my blog post ... cedar finance 60 seconds

Anonymous said...

Many thanks match, worked like a beauty.

This has actually been doing my head in for days !
!

Here is my homepage: xerox phaser 8560 toner :: ::

Anonymous said...

Sаved as а favoгite, Ι like
your web site!

mу wеb blog Facebook marketing Strategies

Anonymous said...

Amazing blog! Do you have any tips for aspiring writers?
I'm hoping to start my own website soon but I'm a little lost on everything.
Would you recommend starting with a free platform like Wordpress or go for a paid option?

There are so many choices out there that I'm totally confused .. Any recommendations? Thanks a lot!

Also visit my blog ... acne

Anonymous said...

Many thanks for the answer. This functioned wonderful !
!!

My page ... xerox phaser 8560 ink []

Anonymous said...

Stack grows downwards means the stack pointer grows towards 0x00000000 if its a 32-bit.When a local variable is declared and called another function,then this local varaible will be pushed on to stack,means this will get higher adrress
so if local1>local2=>down
else =>upwards.
pls change the program as so..