473,472 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

pointers to functions.

1 New Member
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. int foo(int n)
  4. {printf("Foo got %d\n", n); return(0);
  5. }
  6.  
  7. int bar(int n)
  8. {
  9. printf("Bar got %d\n", n); return(0);
  10. }
  11.  
  12. int main(int argc, char *argv[])
  13. {  
  14. int m = 0;
  15. int (*(fun_array[3]))();
  16. int i = 1;
  17. int ii = i/++i;
  18. printf("\ni/++i = %d, ",ii);
  19. fun_array[1] = foo; 
  20. fun_array[2] = bar; 
  21. (fun_array[++m])(++m);    
  22. }
  23.  
In the above program what does this statement implies
(*(fun_array[3]))(); ?

Is it an array of 3 elements that can store addresss of 3 functions ?
]
And i'm getting 3 errors in it, how to slove them ?
i'm using turboC++ compiler.
Nov 13 '07 #1
1 1223
sicarie
4,677 Recognized Expert Moderator Specialist
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. int foo(int n)
  4.    printf("Foo got %d\n", n); 
  5.    return(0);
  6. }
  7.  
  8. int bar(int n)
  9. {
  10.    printf("Bar got %d\n", n); 
  11.    return(0);
  12. }
  13.  
  14. int main(int argc, char *argv[])
  15. {  
  16.    int m = 0;
  17.    int (*(fun_array[3]))();
  18.    int i = 1;
  19.    int ii = i/++i;
  20.    printf("\ni/++i = %d, ",ii);
  21.    fun_array[1] = foo; 
  22.    fun_array[2] = bar; 
  23.    (fun_array[++m])(++m);    
  24. }
  25.  
In the above program what does this statement implies
(*(fun_array[3]))(); ?

Is it an array of 3 elements that can store addresss of 3 functions ?
]
And i'm getting 3 errors in it, how to slove them ?
i'm using turboC++ compiler.
That depends on what the errors are, let's see them. I'm guessing at least one of them deals with the line you are talking about.

PS - you do know that you have no implementation of fun_array - whatever it is. I wouldn't be surprised if that was an obscure way to declare an array, but I do not believe it is a function.
Nov 13 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Alex | last post by:
Is there any problem with sending function pointers through in a variable argument list? I have a function like the following: typedef (*ptr2FuncType1)( int ); typedef (*ptr2FuncType2)( double...
2
by: Thomas Matthews | last post by:
Hi, I would like to create a table (or vector) of pointers to templated functions. 1. How do I declare a typedef of a pointer to a templated function? For example, I have some functions...
9
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...
13
by: munni | last post by:
hi i want to write a program on function pointers where i have not written any programs using function pointers till now. i want to take an array of 26 functions which r to be pointed by this...
11
by: cps | last post by:
Hi, I'm a C programmer taking my first steps into the world of C++. I'm currently developing a C++ 3D graphics application using GLUT (OpenGL Utility Toolkit written in C) for the GUI...
15
by: Christian Christmann | last post by:
Hi, in which situations pointers to functions might be more efficient/convenient than a direct function call? In the example I've found so far, I see no advantage of using pointers to...
1
by: Bushido Hacks | last post by:
A private utility function using a function pointer sounds ideal to me. I want to simpify writing the same set of loops. While there are a few functions that can't use it, setting and modifying...
12
by: claudiu | last post by:
Hi, I'll go straight to the first question. Why does the code below compile? void f(int i = 0); int main() { (&f)();
12
by: bgold | last post by:
Hey. I have a base class (SPRITE), and using this base class I have derived a large number of derived classes (PERSON, BULLET, MISSILE, etc.). Now, at a certain point in my program, I have a pair...
8
by: a | last post by:
Hello. Suppose I have a family of functions f_0(x) = 0*x f_1(x) = 1*x .... f_n(x) = n*x taking float and returning float (naturally, the actual functions would
0
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...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.