logo

CuriousTab

CuriousTab

Discussion


Home Technical Questions Programming Comments

  • Question
  • How would you free the memory allocated by the following program? #include "alloc.h" #define MAXROW 3 #define MAXCOL 4 main() { int **p, i; p = (int **) malloc (MAXROW * sizeof (int *)); for ( i = 0; i < MAXROW ; i++) p[i] = (int *) malloc (MAXCOL * sizeof (int )); }


  • Correct Answer
  • for ( i=0; i < MAXROW ; i++) free (p[i]); free (p); 


  • Programming problems


    Search Results


    • 1. How would you dynamically allocate a 2-D array of integers?
    • Discuss
    • 2. Improve the following code using typedef. struct node { int data1; float data2; struct node *left; struct node *right; }; struct node *ptr; ptr = (struct node *) malloc (sizeof (struct node) );
    • Discuss
    • 3. In the following code can we declare a new typedef name emp even though struct employee has not been completely defined while using typedef? < Yes / No> typedef struct employee *ptr; struct employee { char name[20]; int age; ptr next; };
    • Discuss
    • 4. Answer the following Program #define CHARSIZE 8 #define MASK(y) (1 << y % CHARSIZE) #define BITSLOT (y) (y / CHARSIZE) #define SET(x,y) ( x[BITSLOT(y)] = MASK(y) ) #define TEST(x,y) ( x[BITSLOT(y)] & MASK(y) ) #define NUMSLOTS(n) ((n + CHARSIZE - 1) / CHARSIZE) Give the above macros how would you 1. declare an array arr of 50 bits 2. put the 20th bit on 3. test whether the 40th bit is on or off
    • Discuss
    • 5. What would be the output of the following program ? main() { unsigned int a = oxffff; ~a; printf ("%x", a); }

    • Options
    • A. ffff
    • B. 0000
    • C. 00ff
    • D. None of the above
    • Discuss
    • 6. Can I increase the size of a dynamically allocated array? < Yes / No> if yes, how?
    • Discuss
    • 7. What is the difference between malloc() and calloc() functions?
    • Discuss
    • 8. If I use the following printf() to print a long int why I am not warned about the type mismatch? printf ("%d",num );
    • Discuss
    • 9. How would you use qsort() function to sort an array of structures?
    • Discuss
    • 10. What will be output of following c code? #include int main() { int i; for(i=10;i<=15;i++){ while(i){ do{ printf("%d ",1); if(i>1) continue; }while(0); break; } } return 0; }
    • Discuss


    Comments

    There are no comments.

Enter a new Comment