Calculator: Callback Typealias count = (int , int ), intfunc Add (A:int, B:int)->int { return a+b}func
delete (A:int, B:int)->int { return a-B }func Cheng (a:int, B:int)->int { return a*b }func Dev ( A:int, B:int)->int { return a/b }func ABC (fun:count, X:int, Y:int), Int {return fun (x, y)}//var< C11/>f:count =addprint (ABC (Add, X:2, y:3) print (ABC (delete, X:2, y:3)) print (ABC (Cheng, X:2, Y:3)) print (ABC (DEV, x: 2, Y:3))
//MARK://MARK:////////8. Functions/////////C language Function type: 1, no return value, no parameter 2, there is a return value, no parameter 3, no return value, has parameters, 4, has a return value, has parameters;//a function is a block of code that is used to accomplish a particular task, and you name the code block, which is used as an indicator, and is called when the code block is executed .//1. No return value, no parametersFunc fun1 ()void{Print ("no return value, no parameter")}//2. There is a return value, no parameters;Func fun2 ()string{return "Lzy"}//3, no return value, parameterFunc fun3 (A:int, B:int)Void{print (A+b)}//4, with a return value, with parameters; A: Call a function of type floatFunc fun4 (A:int, B:float)float{returnFloat (a) +B}//calling Functionsfun1 () print (Fun2 ()) Fun3 (3B:5)//no return value;Print (Fun4 (3B:5) )//has a return value;//5. Functions with multiple return valuesFunc fun5 (A:int, B:int)(Int, Float) {return(A, Float (b))}print (Fun5 (3B:5) Let (first, second)= Fun5 (3B:5) print (first ) print (second) print (Fun5 (3B:5).0) Print (Fun5 (3B:5).1)//func fun6 (name name:string, age:int) {print ("name is \ (name), age = \ (age)")}fun6 (name:"Lzy", Age: +)//Exchange A value of two numbersFunc fun7 (inout a:int, InOut b:int)void{a= a ^b; b= a ^b; A= a ^b;}varX:int =5 ;varY:int =Ten; Fun7 (&x, B: &y) Print ("x = \ (x), y = \ (y)")//function PointersTypealias Swapfunc = (inout int, inout int)VoidvarP_fun:swapfunc =Fun7p_fun (&x, &y) Print ("x = \ (x), y = \ (y)")//function pointers as parameters;func fun8 (Pfun:swapfunc, InOut a:int, InOut b:int) {Pfun (&a, &b)} Fun8 (P_fun, A:&x, B: &y) Print ("x = \ (x), y = \ (y)")//function pointer as return valueFunc Fun9 ()swapfunc{//defined within the body of a function;Let P_func:swapfunc =fun7returnp_func}fun9 () (&x,&y) Print ("x = \ (x), y =\ (y)")
I think the future of Apple's mainstream language is swift, which is estimated to be 2020. I also have 5 years of study experience.
Beginner Swift (Implementation of subtraction functions and basic types of functions)