AceTheInterview
Jobs in Pune | Work better in teams | Socialize with friends | Submit Q&A | Tell a friend
Search site for 

Top 100 Interview Questions & Answers in a convenient and easy to read book!

“I bought this guide a few days ago to prepare for my interview with Oracle. Many of the questions they asked me were from this guide. I found this book absolutely great!”

– Ravi, California

Read more comments...

Interview Questions And Answers RSS Feed

Answers »

  1. Submitted By: raja — October 6, 2006
    +0 votes
      + -

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

  2. Submitted By: DougNoTronik — October 6, 2006
    +6 votes
      + -

    I prefer this method because it uses less memory allocation calls and the memory is in a contiguous line.
    I used calloc.. which can easily be swaped out with calloc.
    Also.. this makes a 2d array of integers but that is easily changed as well.

    int x = 0, y = 0;

    Array = (int **) calloc( Height, sizeof(int *));
    *(Array) = (int *) calloc( Width * Height, sizeof(int));

    for(y = 0; y < Height; y++)
    {
    Array[y] = &(Array[0][x]);
    x += Width;
    }

  3. Submitted By: DougNoTronik — October 6, 2006
    -2 votes
      + -

    I used calloc.. which can easily be swaped out with calloc.

    OOPS.. that is a typo

    should say:
    I used calloc.. which can easily be swaped out with malloc.

  4. Submitted By: guest — October 6, 2006
    -4 votes
      + -

    The first sizeof() should be sizeof(int *), not sizeof(int).

  5. Submitted By: ch — November 17, 2006
    -4 votes
      + -

    int a[][]=new int[x][y];

  6. Submitted By: Swati Sarda — December 18, 2006
    +1 votes
      + -

    int * Allocate(int x, int y)
    {
    int size = x * y;
    int * arr = =(int*)malloc(size*sizeof(int));
    return arr;
    }

    As memory of arrays are allocated continuously, even for multi dimentional arrays.

  7. Submitted By: Marcus Wan — February 3, 2007
    -1 votes
      + -

    In C++ to allocate and free memory respectively:

    template
    T** Allocate(T** arry, int x, int y)
    {
    arry = new T*[x];

    for(int i=0; i
    void Allocate(T** arry, int x, int y)
    {
    for(int i=0; i

  8. Submitted By: Marcus Wan — February 3, 2007
    +0 votes
      + -

    In C++ to allocate and free memory respectively:

    template<typename T>
    T** Allocate(T** arry, int x, int y)
    {
    arry = new T*[x];

    for(int i=0; i<=x; i++)
    arry[i] = new T[y];

    return arry;
    }

    template<typename T>
    void Allocate(T** arry, int x, int y)
    {
    for(int i=0; i<=x; i++)
    delete [] arry[i];

    delete [] arry;
    }

  9. Submitted By: Marcus Wan — February 3, 2007
    +0 votes
      + -

    sorry the second function is meant to be called “Delete” and not “Allocate”.

  10. Leave an Answer/Comment

    To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
    Click to hear an audio file of the anti-spam word

Our Sponsors
Our Sponsors
Contact Us | FAQ | Sitemap | Terms of Use | Privacy Policy | Tell a Friend

Copyright © 1999-2006 Jeeve Technologies LLC. All rights reserved.