Multiple choice technology programming languages

struct customer *p= malloc( sizeof( struct customer ) ); Given the sample allocation for the pointer "p" found above, which one of the following statements is used to reallocate ptr to be an array of 10 elements?

  1. p = realloc( ptr, 10 * sizeof( struct ritesh));

  2. realloc( ptr, 9 * sizeof( struct ritesh) );

  3. p+= malloc( 9 * sizeof( struct ritesh) );

  4. p = realloc( ptr, 9 * sizeof( struct ritesh) );

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

realloc expands existing allocation. Option A correctly uses realloc to resize ptr for 10 elements. Option B is missing assignment (memory leak), Option C uses malloc and adds to pointer (wrong), Option D only allocates 9 elements. Note: question uses 'ptr' in text but 'p' as variable name - minor inconsistency.