GeeksforGeeks » Interview Questions

Microsoft Interview Question for Software Engineer/Developer about CPuzzles

(9 posts)

Tags:

  1. praveen
    guest
    Posted 10 months ago #

    allocate 2D array dynamically with min no. of malloc calls.

  2. rajcools
    Member
    Posted 10 months ago #

    now answer to this question depends whether u want to excess array using [i][j] notation or not

  3. Jack
    guest
    Posted 10 months ago #

    This can be done using consecutive memory allocation and then playing with pinter arithmetic.
    Problem with this approach is that it is not possible to realloc it row/column wise going ahead.

  4. sahil316
    Member
    Posted 10 months ago #

    int a[10][20];
    a=(char **)malloc(sizeof(char[10][20];

  5. sahil316
    Member
    Posted 10 months ago #


  6. vpshastry
    guest
    Posted 7 months ago #

    int (*p)[MAXCOL];
    p=(int (*)[MAXCOL]) malloc (MAXROW * sizeof(*p));

  7. sangee
    guest
    Posted 7 months ago #

    int *ptr;
    ptr=(int*)malloc(rows*clumns*sizeof(int));

  8. Rahul Yadav
    guest
    Posted 7 months ago #

    first allocate memory for **p, and then for each *p assign memory in a loop.

  9. ankiee
    guest
    Posted 5 months ago #

    @sahil316:
    when we have written int a[10][20] memory is already allocated to array a, why do we need malloc, infact i dont think it is dynamic memory allocation at all.


Reply

You must log in to post.

RSS feed for this topic