allocating a single array

This is a discussion on allocating a single array within the C Programming forums, part of the General Programming Boards category; would these two lines of code end up with the same results? int * ptr ptr = (int*)malloc(20 * sizeof(int)); ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    380

    allocating a single array

    would these two lines of code end up with the same results?

    int * ptr
    ptr = (int*)malloc(20 * sizeof(int));

    ptr = (int*)malloc(sizeof(int[20]));

  2. #2
    B26354 Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633
    Yes sir, they would.
    Jason Deckard

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to insert a single value into every array alement?
    By philvaira in forum C++ Programming
    Replies: 11
    Last Post: 08-10-2008, 03:05 PM
  2. Modify an single passed array element
    By swgh in forum C Programming
    Replies: 3
    Last Post: 08-04-2007, 09:58 AM
  3. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 05:15 AM
  4. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 01:01 AM
  5. Useing a single dimension array as a multi simension one
    By Eber Kain in forum C++ Programming
    Replies: 1
    Last Post: 02-16-2002, 06:25 PM

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