Thread: whats the meaning of this allocate ?

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    24

    whats the meaning of this allocate ?

    arr =(char **)malloc((SOME INTEGER VALUE)*sizeof(char *)))

    supose there`s char **arr; declaration & the allocation succeed .

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    It allocates a dynamic array with "SOME INTEGER VALUE" number of elements of char pointer type (char*).

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Memloop View Post
    It allocates a dynamic array with "SOME INTEGER VALUE" number of elements of char pointer type (char*).
    Which means, most likely, a series of strings similar to this (altho the char pointers in the array have not been allocated their own memory yet):
    Code:
    char stringray[4][20] ={ "the first string",  "this one's stringray[1]", "now stringray[2]", "our last string..." }
    except dynamic in two dimensions (so it could be any number of strings of any length, as determined by the malloc calls).
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Promblem with code
    By watchdogger in forum C Programming
    Replies: 18
    Last Post: 01-31-2009, 06:36 PM
  2. Why can't you allocate a 2D array like this?
    By rudyman in forum C++ Programming
    Replies: 7
    Last Post: 07-22-2008, 01:47 PM
  3. When to Allocate or Not to Allocate
    By Eber Kain in forum C++ Programming
    Replies: 5
    Last Post: 11-13-2005, 11:32 PM
  4. The Meaning of Life: A Trick Question?
    By chix/w/guns in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 07-12-2004, 07:53 PM
  5. when to allocate memory
    By SAMSAM in forum Windows Programming
    Replies: 3
    Last Post: 01-22-2003, 11:40 PM