what is the advantage of function pointer
Answers were Sorted based on User's Feedback
Answer / dwight schrute
suppose u have 2 files:
file1 has following functions:
A1
B1
C1
file12 has following functions:
A2
B2
C2
scenario:
A1 needs to use A2 in turn A2 needs to use B1.
A1 invokes A2;
A2 invokes B1;
for B1 to be available in file2 either shld be extern or in
header file which in turn exposes it to entire file2.
In order to minimize this exposure "pass B1 as a functional
pointer to A2".
Is This Answer Correct ? | 4 Yes | 1 No |
Answer / chikani sagar
TO implement call back functions......It is more efficient.
code complexity will be redused.....
Is This Answer Correct ? | 3 Yes | 1 No |
Answer / sanjeeva rao
It is useful when you want to send function as argument to
another function. And to implement the call back functions in multi-threading programming.
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / tahir ali
As you probably learned in your first programming courses,
pointers to variables allows you to modify variable contents
from a non-local environment. This gives the flexibility of
writing generic functions which do not alter "known" global
variables, but references to "unknown" variables. Such
functions can be reused. Function pointers gives you the
same flexibility, but at a higher level. Instead of calling
a "known" function, one can call any arbitrary "unknown"
function. This is the main advantage of function pointers:
greater flexibility and better code reuse.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / sudeep reddy
function pointers can be used to replace switch/if
statements,to realize late binding(virtual function tables)
or to implement callback function primitives.
Is This Answer Correct ? | 0 Yes | 0 No |
How many ways are there to swap two numbers without using temporary variable? Give the each logic.
How can I find the day of the week given the date?
print the table 5 in loops
main() { printf(5+"Vidyarthi Computers"); }
CAN ANYONE PLEASE HELP ON THIS PROGRAM FOR MY EXAM..TQ Write a C program to help a H’s Restaurant automate its breakfast billing system. Your assignment should implement the following items: a. Show the customer the different breakfast items offered by the H’s Restaurant. b. Allow the customer to select more than one item from the menu. c. Calculate and print the bill to the customer. d. Produce a report to present your complete program and show more sample output. Assume that the H’s Restaurant offers the following breakfast menu: Plain Egg $2.50 Bacon and Egg $3.45 Muffin $2.20 French Toast $2.95 Fruit Basket $3.45 Cereal $0.70 Coffee $1.50 Tea $1.80 Your program must do the following task below: a. Define the data structs, menu item types with two components: menu item of type string and menu price of type double. Use an array to declare the data structs. b. Function get data to loads the data into the array menu list. c. Function show menu to show the different breakfast items offered by the restaurant and tell the user how to select the items. d. Function print receipt to calculates and prints the customer receipt. The billing amount should include a 5% tax. e. Format your output with two decimal places. The name of each item in the output must be left-justify. You may assume that the user selects only one item of a particular type. f. The two sample output as shown: Welcome to HiFi’s Restaurant 1 Bacon and Egg $3.45 1 Muffin $2.20 1 Coffee $1.50 Tax 5% $0.35 Amount Due $7.50
What are the advantages and disadvantages of a heap?
study the code: #include<stdio.h> void main() { const int a=100; int *p; p=&a; (*p)++; printf("a=%dn(*p)=%dn",a,*p); } What is printed? A)100,101 B)100,100 C)101,101 D)None of the above
Can I pass constant values to functions which accept structure arguments?
What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?
How can I invoke another program (a standalone executable, or an operating system command) from within a c program?
How many main () function we can have in a project?
Multiply an Integer Number by 2 Without Using Multiplication Operator