जॉइन Examsbook
943 0

प्र: Can I increase the size of a dynamically allocated array? < Yes / No> if yes, how?

  • उत्तर देखेंउत्तर छिपाएं
  • Workspace

उत्तर :
व्याख्या :

Yes, using the realloc() function as shown below: main() {         int *p;         p = ( int *) malloc (20) ;         t = p;         t = (int *) realloc ( p, 40);         if ( t == NULL )         Printf (" Cannot reallocate, leaves previous allocated region unchanged ");        else        {               if ( p ==t )               ;  / * the array expanded at the same region */              else             {                   free ( p ); / * deallocate the original array */                  p = t;  /* set p to newly allocated region */              }       } }

क्या आपको यकीन है

  त्रुटि की रिपोर्ट करें

कृपया संदेश दर्ज करें
त्रुटि रिपोर्ट सफलतापूर्वक जमा हुई