malloc vs link-list

S

siliconwafer

Hi All,
Q.1:Is a link list of characters terminated with '\0' equivalent to a
string?
Q.2:If so,can we do string operations in string.h on it?How?
Q.3:What is better when it comes to creating arrays on heap - malloc or
link list of individual elements?
 
S

santosh

siliconwafer said:
Hi All,
Q.1:Is a link list of characters terminated with '\0' equivalent to a
string?
Q.2:If so,can we do string operations in string.h on it?How?
Q.3:What is better when it comes to creating arrays on heap - malloc or
link list of individual elements?

1. Well, although you design your own semantics for linked lists, they
are usually terminated by a NULL pointer in the last element of the
list.

2. No, the string functions of the Standard C library will only work
for null terminated array of characters. For other data structures you
will need to write your own manipulation routines.

3. The elements of the linked lists themselves are allocated via
malloc() or equivalent. Any runtime storage on the heap has to be
allocated through malloc().
 
M

Marc Boyer

Le 06-12-2005 said:
Hi All,
Q.1:Is a link list of characters terminated with '\0' equivalent to a
string?
Q.2:If so,can we do string operations in string.h on it?How?
Q.3:What is better when it comes to creating arrays on heap - malloc or
link list of individual elements?

When you want your homework to be done by newsgroup, please,
gives also the email address of your teacher: we can send him
the answers directly.

Marc Boyer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,172
Messages
2,570,933
Members
47,472
Latest member
blackwatermelon

Latest Threads

Top