initialize 2D array!

This is a discussion on initialize 2D array! within the C Programming forums, part of the General Programming Boards category; how to initialize 2D array. following is not a code but just for my concept, plz tell if it is ...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    32

    initialize 2D array!

    how to initialize 2D array.

    following is not a code but just for my concept, plz tell if it is correct
    n how
    array having x rows n y columns

    array=(int **)malloc(x*sizeof(int *)
    for(i=0;i<;i++)
    array[i]=(int *)malloc(y*sizeof(int))

    thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    Yes, just like that, without the casts.
    Numerous posts (some of them very recent) show you how.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Treating a 2D array as a 1D array....
    By John_L in forum C Programming
    Replies: 6
    Last Post: 10-18-2007, 03:38 PM
  2. cannot print out my 2d array correctly! please help
    By dalearyous in forum C++ Programming
    Replies: 5
    Last Post: 04-10-2006, 03:07 AM
  3. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 09:51 AM
  4. Copying from one 2d array to another....with a twist
    By Zildjian in forum C++ Programming
    Replies: 2
    Last Post: 10-24-2004, 08:39 PM
  5. Text file to 2D Array PLEASE HELP!
    By lostboy101 in forum C Programming
    Replies: 0
    Last Post: 03-26-2002, 10:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21