×

Hook() function in C

Use of hook () function in C

Introduction: 

The hook () is a function used in the C programming language. The basic concept of the hook() function is that it can remove the function code by its own code. When you call the function, then your code will run. So, hook () is a function which removes the function code.

The hook() function is a function which provides extended behaviour in the run time. A hook is a package code that gives the user an interface to write a customised program. It is a function which is also known as the call back function.

Syntax of the hook () function in C language:

Syntax means the order or arrangement in the program. The syntax is also known as the function prototype. Every function has a syntax value. The syntax of the hook() function is: 

 Int hookFunction(); 

The hook() function uses to remove the function code by its own code.

Header file of the hook () function in C language :

Every program contains some header files. For the run of any program, you must need a header file. Without a header file, you can't run any programs. So, we must produce the header file in every program. It is a file with an extension. 

The primary use of the header file is to propagate the declaration of code files. The hook () function uses as a library function. The header file of the hook () function in the C language is <stdio.h>. 

It writes in the program as #include <stdio.h>. 

Example 1 –

Here we given a example of the hook () function using C language:

 #include <stdio.h>
int hookTargetFunction ()
{
printf ("Calling the original function!\ n");
return 10,
}
int main ()
{
printf (“The number is: %d\n”, hookTargetFunction());
return 0;
}

Output: We compile and run the above program.The result of this above program is:

Calling the original function!
The number is: 10

To better understand, we give another example of the hook () function.

Example 2 –

Here we given a example of the hook() function using C language:

#include <stdio.h>
void PayEmployee (Employee anEmployee, int amout)
{
company. getBankAccount () . withdraw (amount);
anEmployee . getBankAccount () . deposit (amount);
anEmployee . setPaidThisWeek (TRUE);
void *(*hookList) (Employee,int) = getPaymentHookList();
while (*hookList != NULL)
{
(*hookList) (anEmployee, amount);
++hookList;
}
}
void addPaymentHook (void (*paymentFunc) (Employee, int))
{
getPaymentHookList() . addHook (paymentFunc);
}

Output: We compile and run the above program.

In the above two programs, we have used the hook () function; by the programs, we briefly discussed how to write any C language program using the hook () function. The basic concept of the hook () function is that it can remove the function code by its own code. The hook () function is a library function.

So we <stdio.h> header file in this program. It writes in the program as #include <stdio.h>.  In the above programs, we are using stdio.h header file.

The primary use of the header file is to propagate the declaration of code files. We also share the output of the above two programs. 


Related Topics

Prototype in C

A prototype is nothing but a model, a model of initial creation of an intended product. Similarly, in the C programming language, all functions have a prototype. In general, all...

4 minutes read.

Remove an element from an array in C

A collection of objects or pieces of the same data type stored in a single memory block is known as an array. A data structure called an array is used...

3 minutes read.

Type qualifiers in C

Type qualifiers in C: In the C programming language, type qualifiers are the keywords that prepend to the variables to change their accessibility, i.e., we can tell that the type...

4 minutes read.

Program to Find Mode of an Array in C

Mode is the highest occurring value or number in a given set of data elements. In a group of data values, a value that occurs most frequently is considered to...

3 minutes read.

Continue in C

C language: C language is a procedure oriented programming language. We can say that it is a platform dependent language. C language is introduced by Dennis Ritchie in the year 1970. We...

2 minutes read.

Positioning of file in C

Positioning() function in c The fseek() function is utilized to change the document position of the stream . The fully extent of value from the source should be one of the...

3 minutes read.

Addition of Matrix in C

The mathematical operation of includingor greater matrices is called the addition of matrices. A matrix is a square series of numbers, symbols, words, letters, and different things. In this article,...

3 minutes read.

How to convert a string to hexadecimal in C

Converting a character array or any string to its respective hexadecimal form is simple. The only thing we have to do is to follow the below steps. Take each character from...

3 minutes read.

GCD of Two Numbers in C

The GCD means the greatest common divisor of two or more integers, it is also called as hcf. The gcd returns the greatest integer of the given two integers that...

3 minutes read.

memmove() in C

Introduction: In this article we are discuss about the memmove() function in C. This function transfers memory blocks from one location to another. The memmove() function is declared in the...

3 minutes read.

Run Time Polymorphism in C

What is polymorphism? Polymorphism refers to the existence of various forms. Polymorphism can be simply defined as a message's capacity to be presented in multiple forms. An individual who can have...

4 minutes read.

Booleans in C

Introduction to Boolean With all the complexities of programming, it can take time to understand the basics. One concept, in particular, that confuses many beginners is the use of Booleans in...

6 minutes read.

Distance Vector Routing Protocol Program in c

A distance-vector routing protocol is one of the foremost instructions of routing protocols in pc conversation principle for packet-switched networks. The hyperlink-nation protocol is the alternative foremost class.The Bellman-Ford set...

4 minutes read.

Bar3d() function in C Graphics

The bar3d function is used to create a 2-dimensional filled-in rectangular bar. We can also create three-dimensional shapes in C using helpful function. The first step in creating this 3D...

3 minutes read.

C Decision control statement

Decision Making C conditional statements are used to specify one or more conditions. The statements will be executed if the condition becomes true otherwise alternative statement will be executed if the...

3 minutes read.

OpenGL in C

OpenGL stands for Open Graphics Library. It is a low-level, widely supported modeling and rendering software package that is widely available across all the platforms. It is an API used...

4 minutes read.

Random function in C

Random function in C In the C programming language, the rand() is a function used for Pseudo Random Number Generator (PRNG). The random number generated by the rand() function is not...

4 minutes read.

SJF Scheduling Program in C

The SJF (shortest job first) or the shortest job next is the programming scheduling in the C. It is one of the CPU scheduling programming. The SJF is defined as...

4 minutes read.

Self-referential structure in C

Self-referential structure in C A self-referential structure is a structure that can have members which point to a structure variable of the same type. They can have one or more pointers...

3 minutes read.

C Programming Tutorial

What is C Programming C is most popular and widely used computer programming language. It was developed by Dennis Ritchie in 1972 at the Bell Lab. It is used to develop system application software. There...

8 minutes read.