943,691 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 412
  • C RSS
Dec 6th, 2008
0

؟questions?

Expand Post »
hello again
i have three questions again:
how can i use malloc or calloc for a two demontional arrays?

is it true that A. calloc allocates memory in contiguous bytes, malloc does not ensure contiguous memory allocation?

the third question which is a bit irrelevent to programming
how memorey locations in computers are given address?i mean early intell CPUs could
onley address (64K) but what about the rest of memory locations?

thanks
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
xlx16 is offline Offline
10 posts
since May 2008
Dec 6th, 2008
0

Re: ؟questions?

> is it true that A. calloc allocates memory in contiguous bytes, malloc does not ensure contiguous memory allocation?
No, it's false.
calloc is nothing more than malloc + memset to wipe the memory to all-bits-zero.

> i mean early intell CPUs could onley address (64K)
Only 64K in a single block.
If you wanted more, then you had to start messing about with segment registers
http://en.wikipedia.org/wiki/X86


> how can i use malloc or calloc for a two demontional arrays?
One (of several) ways
  1. char **arr = malloc( rows * sizeof *arr );
  2. for ( r = 0 ; r < rows ; r++ ) {
  3. arr[r] = malloc( cols * sizeof *arr[r] );
  4. }
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: octal to hexa with out format strings
Next Thread in C Forum Timeline: Complexity of sorting techniques





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC