function pointer c
C
#include <stdio.h>
// A normal function with an int parameter
// and void return type
void foo(int a) {
printf("foo: Value of a is %d\n", a);
}
int add(int a, int b) {
return a+b;
}
// Take function as argument
void baz(void (*fun)(int), int arg) {
// call fun
printf("baz: Calling func pointer with arg %d\n", arg);
fun(arg);
}
int main() {
// Create pointers
void (*fun_a)(int) = &foo;
void (*fun_b)(int) = foo; // & removed
int (*fun_c)(int, int) = add;
(*fun_a)(10); // If you have the address, use *
fun_b(10); // * removed
printf("fun_c(10, 20) = %d\n", fun_c(10,20));
baz(foo, 10);
// output:
// foo: Value of a is 10
// foo: Value of a is 10
// fun_c(10, 20) = 30
// baz: Calling func pointer with arg 10
// foo: Value of a is 10
return 0;
}
Also in C:
- Title
- strtoul C
- Category
- C
- Title
- c program to perform transpose of a matrix
- Category
- C
- Title
- entete c/c++
- Category
- C
- Title
- Declaring Variables in C
- Category
- C
- Title
- assert() in c
- Category
- C
- Title
- es palindromo
- Category
- C
- Title
- what is conio.h
- Category
- C
- Title
- c program to find the sum of given number using recursion
- Category
- C
- Title
- Fibonacci program c pthread
- Category
- C
- Title
- c check if file was created
- Category
- C
- Title
- c value set to zero __memmove_avx_unaligned_erms
- Category
- C
- Title
- c fill 2d array
- Category
- C
- Title
- how to login to another user in powershell
- Category
- C
- Title
- restapi
- Category
- C
- Title
- set timezone in debian terminal
- Category
- C
- Title
- full screen on c
- Category
- C
- Title
- how to pass an array to a thread in c?
- Category
- C
- Title
- sum of arrays
- Category
- C
- Title
- lazer codechef
- Category
- C
- Title
- random en c
- Category
- C
- Title
- c producer consumer pthread semaphore
- Category
- C
- Title
- vbnet create and write on file
- Category
- C
- Title
- diferencia entre * y & en c
- Category
- C
- Title
- left me on read
- Category
- C
- Title
- sbatch array set max jobs at once
- Category
- C
- Title
- how to pass an array value to a pthread in c
- Category
- C
- Title
- c substring
- Category
- C
- Title
- update ubuntu in terminal
- Category
- C
- Title
- write a binary file c
- Category
- C
- Title
- Declare macro
- Category
- C
- Title
- how to feed a char array to function in C
- Category
- C
- Title
- read from stdin c
- Category
- C
- Title
- \0 in c
- Category
- C
- Title
- c how to define a variable
- Category
- C
- Title
- how to convert int in to const char in c
- Category
- C
- Title
- c allocate array
- Category
- C
- Title
- boolean function c
- Category
- C
- Title
- how to free a 2d array correctly
- Category
- C
- Title
- change plot line color in matplotlib
- Category
- C
- Title
- string to int c
- Category
- C
- Title
- how to put quotes inside string c
- Category
- C
- Title
- java.lang.SecurityException: Permission denied (missing INTERNET permission?)
- Category
- C
- Title
- sustituir un dígito por otro
- Category
- C
- Title
- disable gnu++11 option
- Category
- C
- Title
- factors using recursion
- Category
- C
- Title
- hostbuilder add environment variables
- Category
- C
- Title
- python web crawler
- Category
- C
- Title
- chat c socket tcp geeksforgeeks
- Category
- C
- Title
- wait function in c
- Category
- C
- Title
- version of libgcc
- Category
- C
- Title
- docker run port mapping
- Category
- C
- Title
- c concatenate strings
- Category
- C
- Title
- how to create an array of char in c++
- Category
- C
- Title
- matplotlib plot circle marker
- Category
- C
- Title
- pointer parameter where to put the asterix in C?
- Category
- C
- Title
- vbl share price
- Category
- C
- Title
- accessing elements 2D array using pointers
- Category
- C
- Title
- how to do Employing defensive code in the UI to ensure that the current frame is the most top level window
- Category
- C
- Title
- mostrar lista recursiva
- Category
- C
- Title
- add border to image android
- Category
- C
- Title
- long commands makes terminal lag after modifying PS1
- Category
- C
- Title
- csrf_exempt
- Category
- C
- Title
- tmux how to kill all sessions
- Category
- C
- Title
- code in c skipping over scanf
- Category
- C
- Title
- maximo comun divisor
- Category
- C
- Title
- passing 'const char *' to parameter of type 'char *' discards qualifiers
- Category
- C
- Title
- c radians
- Category
- C
- Title
- div
- Category
- C
- Title
- printf n characters c
- Category
- C
- Title
- how to declare 2 d array using malloc
- Category
- C
- Title
- c check if array is empty
- Category
- C
- Title
- C why is is & nit used in scan f fr string
- Category
- C
- Title
- prime number
- Category
- C
- Title
- allocate memory c
- Category
- C
- Title
- potencia recursiva
- Category
- C
- Title
- how to write function in c
- Category
- C
- Title
- a enum data type in c
- Category
- C
- Title
- california
- Category
- C
- Title
- write in file in c
- Category
- C
- Title
- router solicitation and advertisement magic is used by
- Category
- C
- Title
- primo
- Category
- C
- Title
- does strcat null terminate
- Category
- C
- Title
- how to print a file c
- Category
- C
- Title
- c check if char is an operator
- Category
- C
- Title
- XAudio2 C
- Category
- C
- Title
- ImportError: No module named 'skimage'
- Category
- C
- Title
- how to check where the last char is in a string c
- Category
- C
- Title
- how to free memory in c
- Category
- C
- Title
- sdl bouton
- Category
- C
- Title
- insertion sort
- Category
- C
- Title
- dani
- Category
- C
- Title
- keras conv2d batchnorm
- Category
- C
- Title
- c float to int
- Category
- C
- Title
- File "h5py\h5g.pyx", line 161, in h5py.h5g.create ValueError: Unable to create group (name already exists)
- Category
- C
- Title
- arduino digital read
- Category
- C
- Title
- 233 pounds to inr
- Category
- C
- Title
- diagonales
- Category
- C
- Title
- change no_turbo
- Category
- C
- Title
- resto de division recursiva
- Category
- C
- Title
- code: 'EADDRINUSE', [0] errno: 'EADDRINUSE', [0] syscall: 'listen', [0] address: '::', [0] port: 5000
- Category
- C