Programming in C
Programming in C
4th Edition
ISBN: 9780321776419
Author: Stephen G. Kochan
Publisher: Addison-Wesley
Question
Book Icon
Chapter 13, Problem 1E
Program Plan Intro

Program Plan:

  • Include the necessary header files into program.
  • Declare the “typedef” variable in return type of “integer”.
  • Define the function named “testFunction()” which returns “1” in return type of integer.
  • Define the main method.
    • Define the function.
    • Declare the object for “FunctionPtr”.
    • Call the “testFunction” function and store the result in “objPtr”.
    • Print the result on screen.

Expert Solution & Answer
Check Mark
Program Description Answer

The following program is demonstrates the definition of “typedef” variable which represents a pointer to a function.

Explanation of Solution

Program:

//Include required header files

#include <stdio.h>

/*Definition of typedef function*/

typedef int(*FunctionPtr)(void);

/*Function definition*/

int testFunction(void)

{

//Return statement

return 1;

}

//Main funciton

int main(void)

{

//Function definition

int testFunction(void);

//Object declaration

FunctionPtr objPtr;

//Function is called by pointer

objPtr = testFunction;

//Print statement

printf("%i\n", objPtr());

//Return statement

return 0;

}

Sample Output

1

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Indicate whether the following is true or false:Only pointers and references are permissible for use with dynamically bound virtual functions.
Is that correct?Pointers or references are required for dynamically bound virtual functions.
Explain, with the use of an illustration, how the background process of invoking inline functions varies from that of calling a normal function.
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr