Advertisement
Don_Mag

Macro / Block / Function / etc

Oct 28th, 2021
2,971
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  main.m
  3. //  ScratchObjC
  4. //
  5. //  Created by Don Mag on 3/17/20.
  6. //  Copyright © 2020 Don Mag. All rights reserved.
  7. //
  8.  
  9. #import <UIKit/UIKit.h>
  10. #import "AppDelegate.h"
  11.  
  12. // MACRO definition
  13. #define MACROSUM(a, b) a + b;
  14.  
  15. // BLOCK declaration
  16. int (^BLOCKSUM)(int, int) = ^(int a, int b) {
  17.     return a + b;
  18. };
  19.  
  20. // Function
  21. int functionSum(int a, int b) {
  22.     return a + b;
  23. }
  24.  
  25. int main(int argc, char * argv[]) {
  26.    
  27.     int x = 0;
  28.    
  29.     x = 1 + 2;
  30.    
  31.     NSLog(@"Assignment result: %d", x);
  32.    
  33.     x = functionSum(3, 4);
  34.    
  35.     NSLog(@"Function result: %d", x);
  36.    
  37.     x = MACROSUM(5, 6);
  38.    
  39.     NSLog(@"Defined Macro result: %d", x);
  40.    
  41.     x = BLOCKSUM(7, 8);
  42.    
  43.     NSLog(@"Declared Block result: %d", x);
  44.    
  45.     x = ^(int a, int b) {
  46.         return a + b;
  47.     }(9, 10);
  48.    
  49.     NSLog(@"Inline Block result: %d", x);
  50.    
  51.     NSString * appDelegateClassName;
  52.     @autoreleasepool {
  53.         // Setup code that might create autoreleased objects goes here.
  54.         appDelegateClassName = NSStringFromClass([AppDelegate class]);
  55.     }
  56.     return UIApplicationMain(argc, argv, nil, appDelegateClassName);
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement