[IOS] entry block (1)

Before learning block to first review the C language function pointer.

definition:

The type of function return value (* pointer variable name) (function parameter list);

E.g:

int(*p)(int, int);

Explanation:

This statement will define a pointer to a function variable p. First, it is a pointer variable, so there must be a "*", i.e., (P *); secondly preceding int represents the pointer may point to the variable return type is a function of type int; int two rear brackets represents the pointer there are two variable parameters and may point are a function of type int. Therefore, together the meaning of this statement: defines a pointer variable p, the pointer may point to the variable return type is an int, and has the function of two integer parameters. P type is int (*) (int, int).

 

Part II is a particularly good tutorial

http://c.biancheng.net/view/228.html

 

 

Test code

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface TestBlock : NSObject

-(void)test;
@end

NS_ASSUME_NONNULL_END

 

#import  " TestBlock.h " 

@implementation TestBlock 
// declare a method oc c language c language syntax compatible.
int max ( int A, int B);
// implemented test methods
- ( void ) test {
  // declare a function pointer variable. Called * bigger; point has two parameters (int a, int b) method. Method returns a value of type int.
int (* Bigger) ( int A, int B);
  // pointer assignment Bigger
= max;
  // pointer Bigger
int C (* Bigger) (= . 1 , 2 ); NSLog ( @ " pointer to the function call results:% d " , C); }
// Implementation declared.
int max ( int A, int B) { return A> B? A: B; } @end

Guess you like

Origin www.cnblogs.com/mamamia/p/12200754.html