Block syntax---blocks

Source: Internet
Author: User

block blocks syntax. --- anonymous functions

Blocks can define anonymous functions inside a function.

BlocK- implements the maximum value of two numbers.

Function:

#import<Foundation/Foundation.h>#import "Person.h"//1. Output I love iOSvoidoutput () {printf ("I Love ios\n");}//2. Find the maximum of two numbers intMaxValue (intXinty) {returnx > y?x:y;}intMainintargcConst Char*argv[]) {@autoreleasepool {//method One: Direct printingoutput (); intmax = MaxValue (2,5); printf ("max =%d", Max); //method Two: Define pointer variables        void(*p) () =NULL; P= output;//the pointer points to the corresponding function;p (); int(*p) (int,int) =NULL; P=MaxValue; intmax = P (2,5); printf ("max =%d", Max); //method Three: function renaming (printing more than one type, it is more convenient)typedefint(*pfun) (int,int);//Rename the function type to PfunPfun P1 =NULL; P1=MaxValue; intmax = P1 (2,5); printf ("max =%d", Max);

   Fourth Method- --Block  int  (^max) (int , int ) = ^int  (int  A, int   b) { return  a > B? 
    
      A:B;        }; 
     //  How to call block block  int  value = max (4 , 6  ); printf (  value =%d  , value);  

Block syntax----blocks

Block syntax---blocks

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.