Hi All,
I'm learning Pointers to functions in C.But I have some doubts regardign the same.I would be v.happy and thankful if somebody can help me out on my pbm
The problem is mentioned below:
------------------------------------------
Consider I have 5 different functions which returns different type and takes different arguements also.
Eg :
int aaa(int x);
void bbb(int x,int y, int z);
void ccc(void);
void ddd(char *x,char *y,char *z);
void eee(UINT8 x);
And these are all some operations when the user presses some commands,
Eg:
Commands = "command1","command2","command3","command4","comma nd5"
How will i use the fucntion pointers to execute the corresponding function with their arguements?
If possible, if somebody can reply to me ASAP.
Thanks in advance,
Sowmi
2 1238
i didnt get "pressing commands "
can u explain it little more clearly
int aaa(int x);
void bbb(int x,int y, int z);
void ccc(void);
void ddd(char *x,char *y,char *z);
void eee(UINT8 x);
These functions will need different function pointers.
will need a function pointer:
You assign the address of the functtion to the pointer:
and then you can call the function using the pointer:
But you need a diffrerent function pointer for: -
void bbb(int x,int y, int z);
-
-
void (*fp1)(int, int, int);
-
-
fp1 = bbb;
-
-
fp1(10,20,30);
-
Your example is not a case where you use function pointers. Function pointers are used where you have many functions with the same arguments and the same return type. Then you can choose which function to call by putting its address in a function pointer. The pointer can be passed to another function so that the other function can call different functions. This is commonly done with sorts where you pass the address of the compare function to the sort so you can sort in different sequences.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Susan Baker |
last post by:
Hi,
I'm just reading about smart pointers..
I have some existing C code that I would like to provide wrapper classes
for. Specifically, I would like to provide wrappers for two stucts
defined...
|
by: ozbear |
last post by:
This is probably an obvious question.
I know that pointer comparisons are only defined if the two pointers
point somewhere "into" the storage allocated to the same object, or if
they are NULL,...
|
by: Mikhail Teterin |
last post by:
Hello!
I'd like to have a variable of a pointer-to-function type. The two possible
values are of type (*)(FILE *) and (*)(void *). For example:
getter = straight ? fgetc : gzgetc;
nextchar...
|
by: ra294 |
last post by:
When I use the Now() Fucntion i my ASP.net application I get a date format
of mm/dd/yy.
I want it to be dd/mm/yy. I set in the web config "culture="en-GB"
uiCulture="en" and also set the regional...
|
by: Lance |
last post by:
VB.NET (v2003) does not support pointers, right? Assuming that this is true, are there any plans to support pointers in the future? Forgive my ignorance, but if C# supports pointers and C# and...
|
by: Alf P. Steinbach |
last post by:
Not yet perfect, but:
http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01.pdf
http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01_examples.zip
To access the table of...
|
by: Haggr via AccessMonster.com |
last post by:
"My Fucntion()" will return a string value of lxb114 for a query field with
a string of xlb114r. So my question is how to text that Function in the
immediate window of the module? Tried...
|
by: J Caesar |
last post by:
In C you can compare two pointers, p<q, as long as they come from the
same array or the same malloc()ated block. Otherwise you can't.
What I'd like to do is write a function
int comparable(void...
|
by: Boris |
last post by:
I had a 3 hours meeting today with some fellow programmers that are partly
not convinced about using smart pointers in C++. Their main concern is a
possible performance impact. I've been explaining...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |