function pointers---the difference between an int *f (4) and an int (*f) (4) in C + +

Source: Internet
Author: User

int *f (), which represents the function f, the type of the return value of the function is int *

Int (*f) (), which means that this is a function pointer, it can be useful to point to a function, point to a function can use it instead of the function, and then use this pointer is equivalent to using the function.

Routines

#include <stdio.h>int fun (int); int main (void) {    int (*F1) (int);    Int (*F2) (int);    F1 = fun;    F2 = &fun;//Note that the two methods of initializing function pointers above are correct, so you can choose to use & or not    F1 (2) When initializing a function pointer;    F2 (2);    return 0;} int fun (int i) {    printf ("%d", I);    return 1;}

function pointers---the difference between an int *f (4) and an int (*f) (4) in C + +

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.