Basic CS-Data Structures [3i Infotech Placement]: Sample Questions 29 - 30 of 52

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 29

Data Structures
Edit

Describe in Detail

Essay▾

Define pointer to function that take argument as character pointer and return void pointer.

Explanation

  • (void ⚹) (⚹ foo) (⚹ char) .

Declare a pointer to function:

  • int ⚹ ptrInteger;
    • here, ptrInteger is a pointer to integer.
  • int foo (int) ;
    • foo is a function that returns int and take one argument of int type.
    • A ⚹ operator between int and foo (int) should create a pointer to a function.
    • We have to bind operator ⚹ with foo.
  • int (⚹ foo) (int) ;
    • ⚹ operator is with foo which is a function name.
  • Like normal data pointer, a function pointer can be passed as an argument and also returned from a function.

Ex. .

void fun1 ()

{

print ( “Fun1” ) ;

}

void fun2 ()

{

printf ( “fFun2” )

}

void wrapped (void (⚹ fun) () )

{

fun () ;

}

int main ()

{

wrapper (fun1) ;

wrapper (fun2) ;

return 0;

}

  • We can use function pointer to avoid code redundancy.
  • Function pointers and void pointers, it is possible to use qsort for any data type.

Question 30

Data Structures
Edit

Write in Short

Short Answer▾

Name 1 limitation of using an array to hold data.

Explanation

  • It can only hold data of the same type.
  • It is not easy to resize dynamically with memory allocated in blocks.

Developed by: