Scrigroup - Documente si articole

Username / Parola inexistente      

Home Documente Upload Resurse Alte limbi doc  


AccessAdobe photoshopAlgoritmiAutocadBaze de dateCC sharp
CalculatoareCorel drawDot netExcelFox proFrontpageHardware
HtmlInternetJavaLinuxMatlabMs dosPascal
PhpPower pointRetele calculatoareSqlTutorialsWebdesignWindows
WordXml

AspAutocadCDot netExcelFox proHtmlJava
LinuxMathcadPhotoshopPhpSqlVisual studioWindowsXml

Pointers to functions

c

+ Font mai mare | - Font mai mic



DOCUMENTE SIMILARE

Trimite pe Messenger
Keywords and identifiers
Simple arrays
Directives - The null directive
Functions and Program Structure: Basics of Functions
Pointers to functions
Structures - Linked lists and other structures
Expressions and arithmetic - Conversions, Operators
Bitfields
Const and volatile
Declarations, Definitions and Accessibility - Storage class specifiers


Pointers to functions

A useful technique is the ability to have pointers to functions. Their declaration is easy: write the declaration as it would be for the function, say

int func(int a, float b);

and simply put brackets around the name and a in front of it: that declares the pointer. Because of precedence, if you don't parenthesize the name, you declare a function returning a pointer:

/* function returning pointer to int */
int *func(int a, float b);

/* pointer to function returning int */
int (*func)(int a, float b);

Once you've got the pointer, you can assign the address of the right sort of function just by using its name: like an array, a function name is turned into an address when it's used in an expression. You can call the function using one of two forms:




(*func)(1 );
/* or */
func(1,2);

The second form has been newly blessed by the Standard. Here's a simple example.

#include <stdio.h>
#include <stdlib.h>

void func(int);

main()

void
func(int arg)

Example 5.16

If you like writing finite state machines, you might like to know that you can have an array of pointers to functions, with declaration and use like this:

void (*fparr[])(int, float) = ;
/* then call one */

fparr[5](1, 3.4);

Example 5.17

But we'll draw a veil over it at this point!






Politica de confidentialitate



DISTRIBUIE DOCUMENTUL

Comentarii


Vizualizari: 429
Importanta: rank

Comenteaza documentul:

Te rugam sa te autentifici sau sa iti faci cont pentru a putea comenta

Creaza cont nou

Termeni si conditii de utilizare | Contact
© SCRIGROUP 2022 . All rights reserved

Distribuie URL

Adauga cod HTML in site