Programming in C
4th Edition
ISBN: 9780321776419
Author: Stephen G. Kochan
Publisher: Addison-Wesley
expand_more
expand_more
format_list_bulleted
Question
Chapter 13, Problem 1E
Program Plan Intro
- 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
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.
Chapter 13 Solutions
Programming in C
Knowledge Booster
Similar questions
- Write a function f which takes three pointers to int variables (a, b, c). Then it should:-Set the first variable to the sum of values of the variables (a + b + c).-Set the second variable to difference between maximum and minimum of values ( max(a,b,c) - min(a,b,c) )-Set the third variable to median of a, b, c.For example:if a = 5, b = 10, c = 2Then f(&a, &b, &c) should:Set a to 17 (that is the sum)Set b to 8 (that is max - min = 10 - 2)Set c to 5 (that is the median of 5, 10 and 2) NOTE: You are already provided a test main which checks your code for evaluation. DO NOT MODIFY IT or your answer will NOT be accepted. #include<stdio.h> // Write your code here... //////////////////////////////////////////// THIS IS THE TEST MAIN FOR YOUR PROGRAM// DO NOT MODIFY IT!!int main() {int a = 1;int b = 2;int c = 3;for (int i = 0; i < 2; i++) {f(&a, &b, &c);printf("%d\n", a);printf("%d\n", b);printf("%d\n", c);}return 0;}//////////////////////////////////////////…arrow_forwardGive your own definition of "virtual functions."arrow_forwardLanguage: C Write the function convolve that will calculate the confolution of two functions f, g on [0, t] interval. The convolution is defined as (f ∗ g)(t) = Z t 0 f(τ )g(t − τ ) dτ for f, g : [0, ∞) → R. The argument function f and g should be passed by pointers. The integral should be approximated by the Riemman sum, i.e., Z b a f(x) dx = Xn i=1 f(xi) ∆x, where ∆x = b−a n and xi = a + i ∆x. Define the functions func1, func2 and func3, that return sin(x), cos(x) and x 3 respectively. Use these functions to calculate the convolution of f = sin(x), g = sin(x) f = sin(x), g = cos(x) f = sin(x), g = x 3 for t = 2π and n = 1000.arrow_forward
- Tell whether or not the following statement is accurate:Only pointers and references are permissible for dynamically bound virtual functions.arrow_forwardConsider the following function definition.void mystery(int* x){// function body } Inside the definition of mystery, the C++ language provides a way to distinguish if x points to a lone int value or to an int allocated as part of a larger array.A. True B. Falsearrow_forwardGive an example of how the background process of invoking inline functions is different from that of calling a standard function, and explain how the difference came to exist. In addition, give an example of how the difference was brought about.arrow_forward
- 12. Consider the recursive function int gcd( int a, int b) int gcd( int a, int b){ if (b > a) return gcd(b,a); if ( b == 0 ) return a; return gcd( b, a% b); } How many invocation (calls) of the gcd() function will be made by the call gcd(72, 30)?arrow_forwardThe distinction between void and NULL pointers is as follows: Make use of appropriate examples to support your response.arrow_forwardWrite a C++ function to find the norm of a matrix. The norm is defined as the square root of the sum of squares of all elements in the matrix Note: the use of pointers is not allowed and code should be simple.The user should input the matrix he wants.We cannot initialize the matrix on our own.arrow_forward
- Indicate whether or not the following is true:When it comes to dynamically bound virtual functions, only pointers and references are acceptable.arrow_forwardWrite a swap function, that swaps the values of two variables in main, but use pointers instead of reference parameters. WRITE IN C++arrow_forwardGiven a list of parent-child relationships represented as a list of structs, where each struct contains a string field for the name of the parent and a string field for the name of the child, write a function in C that takes in a child's name as a parameter and returns an array of strings containing the names of all the ancestors of that child. The function should also return the number of ancestors found through an integer pointer.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr