Horje
pointers to a function in c Code Example
pointers to a function in c
#include <stdio.h>
#include <string.h>

void (*StartSd)(); // function pointer
void (*StopSd)();  // function pointer

void space()
{
    printf("\n");
}

void StopSound() // funtion
{
    printf("\nSound has Stopped");
}

void StartSound() // function
{
    printf("\nSound has Started");
}

void main()
{

    StartSd = StartSound; // Assign pointer to function
    StopSd = StopSound;   // Assign pointer to function

    (*StartSd)(); // Call the function with the pointer
    (*StopSd)();  // Call the Function with the pointer

    space();

    StartSd(); // Call the function with the pointer
    StopSd();  // Call the function with the pointer

    space();

    StartSound(); // Calling the function by name.
    StopSound();  // Calling the function by name.
}
function pointer in c
// Basic syntax
ret_type (*fun_ptr)(arg_type1, arg_type2,..., arg_typen);

// Example
void fun(int a)
{
    printf("Value of a is %d\n", a);
}

// fun_ptr is a pointer to function fun() 
void (*fun_ptr)(int) = &fun;




C

Related
declare variables arduino Code Example declare variables arduino Code Example
ruby inject Code Example ruby inject Code Example
libdvd-pkg: `apt-get check` failed Code Example libdvd-pkg: `apt-get check` failed Code Example
write a binary file c Code Example write a binary file c Code Example
wireshark tls client hello filter Code Example wireshark tls client hello filter Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
10