473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Confussed: pointers from Kernigan & Richie

On page 106 of the second edition of "The C Programming Language" by K
& G, two stack operations PUSH n POP are given.
PUSH *p++ = val;
POP

val = *--p;

What I know about stacks is that the top of stack (tos) pointer pts to
the topmost element of the stack.
But going by the PUSH operation, the 'va' gets stored in *p first and
then the address of p is incremented by ++ which I think will
OVERWRITE the previous tos. Similarly with pop.

I thought about it and came to the following conclusion:

( either I am missing out on operator PRECENDENCE and its
associativity)

||

( the tos points always to an empty element just above the actual
element on top of the stack)

&&

( I am totally CONFUSSED :p)
please clear my doubts. Thanks in advance :-)
Nov 14 '05 #1
3 1388
so*****@somedomain.net scribbled the following:
On page 106 of the second edition of "The C Programming Language" by K
& G, two stack operations PUSH n POP are given.
PUSH *p++ = val;

POP

val = *--p;

What I know about stacks is that the top of stack (tos) pointer pts to
the topmost element of the stack.
But going by the PUSH operation, the 'va' gets stored in *p first and
then the address of p is incremented by ++ which I think will
OVERWRITE the previous tos. Similarly with pop. I thought about it and came to the following conclusion: ( either I am missing out on operator PRECENDENCE and its
associativity) || ( the tos points always to an empty element just above the actual
element on top of the stack)
This is correct. The pointer will always point at an empty element,
which can be thought of the place where the *NEXT* element will be
pushed.
&& ( I am totally CONFUSSED :p)
please clear my doubts. Thanks in advance :-)


--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Insanity is to be shared."
- Tailgunner
Nov 14 '05 #2

On Thu, 15 Jul 2004 so*****@somedomain.net wrote:

On page 106 of the second edition of "The C Programming Language" by K
& G, two stack operations PUSH n POP are given.


Do not multi-post. Your question has already been answered in
the newsgroup alt.comp.lang.learn.c-c++. Read it there.

-Arthur

Nov 14 '05 #3
Do not multi-post. Your question has already been answered in
the newsgroup alt.comp.lang.learn.c-c++. Read it there.


i m learning :-) . won't happen next time. thanks for ur reply though.

cheers.
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Thomas Matthews | last post by:
Hi, Given a structure of pointers: struct Example_Struct { unsigned char * ptr_buffer; unsigned int * ptr_numbers; }; And a function that will accept the structure:
5
by: someone | last post by:
On page 106 of the second edition of "The C Programming Language" by K & G, two stack operations PUSH n POP are given. >> PUSH *p++ = val; >>POP val = *--p; What I know about stacks is...
73
by: David Scarlett | last post by:
Is the following code safe? SomeType *a, *b; /* Some code.... */ free(a);
39
by: anonymous | last post by:
Dear All, >From my understanding of pointers, a pointer should not be able to access a memory location until that memory has been allocated either by assiging the address of a variable or...
1
by: ballpointpenthief | last post by:
I am trying to build a generic type for data structures in order to be able to build complex data structures based on other, simpler data structures. So, say we have linked lists, doubly linked...
2
by: surjamankhatiwora | last post by:
Can you please give me a brief difference between the vb commends like End,Unload me and Me.hide with its example each...coz while coding, i m totally confussed about these commends....
0
by: David Thompson | last post by:
On Wed, 09 Apr 2008 12:34:43 +0500, arnuld <arnVuld@ippiVmail.com> wrote: I think you've got the idea, but: - I would be careful about using 'equal'. Pointers and arrays are different things,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.