3i Infotech Placement: Sample Questions 594 - 595 of 1245
Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.
Question 594
Describe in Detail Essay▾
Define pointer to function that take argument as character pointer and return void pointer.
EditExplanation
- (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 595
Explanation
- It can only hold data of the same type.
- It is not easy to resize dynamically with memory allocated in blocks.