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
Explain the Pointers and Function Return Values with example.
4. Explain dangling and void pointer with example.
3. How we can pass pointer to a function? Make use of suitable programming elaborate your answer and what is the advantage of example to passing pointer to a function.
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education