views:

213

answers:

2
struct letter
{
char ch;
struct letter *ptr_next;
}
*ptr_first,*ptr_this;
//ptr this contains the address of the first node and ptr this contains the address of last node added.

alt textA word chair has to be inserted in the linked list such that C goes into the first node,h in the second and so on.. The attached picture is the memory diagram to fill. I also added what i tried.Please guide me if i am wrong.alt text Thanks in advance..

+1  A: 

the answer to your question: no. no, because you left one question mark unresolved at ff15.

Peter Miehle
should it be a NULL there?
fahad
what else? i do not see any other option
Peter Miehle
+1  A: 

The problem is the padding bytes your compiler will insert in your struct letter. The addresses of contiguous struct letter objects will never end up like in your drawing.

pmg
this a copy from an academicallay (101) homework, "fill in the blanks"
Peter Miehle
Unable to get what your saying my friend.
fahad
The Point is: we are not doing/checking your homework for you, but we like to answer questions about your problems.
Peter Miehle
@pmg:In this example there will be no padding as the char is of one byte
fahad
@fahad: **precisely** because it is one byte, I'm convinced there will be padding (of course, padding is not mandatory; the compiler is free to do what it pleases)
pmg
ideone ( http://ideone.com/VldYR ) has pointers 4 bytes long and the compiler inserts 3 padding bytes in the structure :)
pmg