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
Explain the Pointers and Function Return Values with example.
Indicate whether the following is true or false:Only pointers and references are permissible for use with dynamically bound virtual functions.
4. Explain dangling and void pointer with example.
Chapter 13 Solutions
Programming in C
Knowledge Booster
Similar questions
- How we can pass the function pointer as a parameter give example.arrow_forward3. 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.arrow_forwardDefine Arrays as Parameters to Functions.arrow_forward
- How to call function using pointer. Please Explain with Code Example?arrow_forwardIs that right?For functions that are flexibly bound, you need pointers or references.arrow_forwardUse Clojure: a. See attached picture. b. In Clojure (like other functional programming languages) functions and variables are treated identically. This means a function may easily take another function as an argument, and/or return a function. Write a function swap-arg-order which takes a function (of two arguments) as an argument returns another function that does the same thing, but expects its two arguments in the opposite order.That is, for example• given the division function / which divides the first argument by the second (so (/ 3 6) returns the number 1/2), the following expression should evaluate to 2((swap-arg-order /) 3 6)• given the function list-longer-than? from above, the following expression should evaluate to true((swap-arg-order list-longer-than?) '(1 2 3) 2) c. Define a higher order function g so the following expression evaluates to true:(= 100 (g (fn [n] (* n n))))arrow_forward
- The distinction between void and NULL pointers is as follows: Make use of appropriate examples to support your response.arrow_forwardWith an example discuss the operators used with pointers.arrow_forward7. using c++, Write a void function that accepts an integer array a and a integer SizeA, and an integer n, and adds n to every element in that array. Be sure to develop an appropriate name for your function.arrow_forward
- Write 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_forwardIn java there must be at least two calls to the function with different arguments and the output must clearly show the task being performed. (ONLY ARRAYS or ARRAYLIST) Develop a function that accepts an array and returns true if the array contains any duplicate values or false if none of the values are repeated. Develop a function that returns true if the elements are in decreasing order and false otherwise. A “peak” is a value in an array that is preceded and followed by a strictly lower value. For example, in the array {2, 12, 9, 8, 5, 7, 3, 9} the values 12 and 7 are peaks. Develop a function that returns the number of peaks in an array of integers. Note that the first element does not have a preceding element and the last element is not followed by anything, so neither the first nor last elements can be peaks. Develop a function that finds the starting index of the longest subsequence of values that is strictly increasing. For example, given the array {12, 3, 7, 5, 9, 8,…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_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education