SlideShare a Scribd company logo
1 of 50
Preprocessor and Underlying C laungage 
Chorn Charly 
Leang Bunrong 
Cheng Udam 
Kan Vichhai 
Srou Chanthorn 
Em Vy 
Seth Sambo 
Chea Socheat
Content 
 #define 
 #import 
 #include 
 #undef 
 Conditional compilications 
 Array 
 Function 
 Block 
structure 
Pointers 
Miscellaneous Language Features 
How Things Work
Preprocessor 
 Preprocessor is the initial program. the first step in compile files it need through initial the 
program.(note preprocessor not finish with “ ; ”). 
 Preprocessor is begin with #. 
 Preprocessor advantages: 
1. Define constants(UpperCase All for name convention). 
2. Import files to files at specifice point 
3. condictionally compile code( use to prevent Program). 
4. Reduce coding 
Oh ! It is in 
.h file. 
Preprocessor 
Compiler(GCC) 
.h file
Preprocessor(cont.) 
Source program 
Compiled code 
Objective – C Compiler(e.g gcc) 
Objective – C Preprocessor GCC(objective-C compiler)
Preprocessor(cont.) 
 Preprocessor are: #define,#include,#import and conditional compilation ..etc. 
1. #define is used to define constants.it also is used to define macro to make easy for develper 
that can use own keyword to develop own project( reduce line of codes). 
 Syntax: #define constantName value 
 Example:
Preprocessor(cont.) 
 #import (#include in C language) is the preprocessor to insert the text of the file Header File.h 
Into file being processed at the point of the #import line. 
 Syntax1: #import “headerName.h” 
 Syntax2:#import <package/headerName.h> 
 Example: 
 Syntax1 is used to import files (class,category...etc) in own project (new class that implement 
by new generation). 
 Syntax2 is used to import files (package,class...etc) in othe package to our project(build in 
classes , libraries ..etc.(Foundation.h,UIKit...etc).
Preprocessor(cont.) 
 #if,#ifdef,#ifndef proprocessor is like if statement. but it execute during compile 
time(condictionally during compile time). 
 Syntax1: 
#if identifier(macro or constant) 
//statements(macro ) 
#else 
// statements(macro) 
#endif 
 Example: 
 Note: #define is no space . In #if preprocessor between # and define keyword is got a space 
character.(#define => # define).
Preprocessor(cont.) 
 #ifdef....#endif,#ifndef .......#endif is executed as #if the same.objective – C new version 
recomment that should not use #if .it can duplicate include file in compile time. 
 Syntax1: 
#ifndef identifier(macro or constant) 
//statements(macro ) 
#else 
// statements(macro) 
#endif 
 Note:identifier(macro or constant) we can configure Xcode to create it. 
 #if , #ifdef is executed when identifier=1(true) but #ifndef is executed when identifier=0(false).
Preprocessor(cont.) 
 To define Constant by configure Xcode.
Preprocessor(cont.) 
 To define Constant by configure Xcode. Double click on debug.and add new Constant 
Identifier or constant
Preprocessor(cont.) 
Example:
Preprocessor(cont.) 
 #undef is used to reset macro. 
 Syntax: 
#undef macroname
Array 
• Objective-c array represent an entire set of values. Then each value store in the 
different element of the set using a number called an index number. Index number start 
from 0 to n-1. you can use array anywhere the variable dose. It similar to variable you 
need to declare before use. Declare an array involves declaring the type of element that 
will be contained in the array. 
Int fibonacci [15]; //declare an array named fibonacci with the 15 size 
Int integers[5] = {0,1,2,3,4}; // declare an array with initialize 
Char letters[5] = {‘a’,’b’,’c’,’d’,’e’}; //declare an array with character 
Int a[10] = { [9] = 1 , [2]=3 , [1]=2 , [0]=1}; //declare an array with initialize base the specific type
Array cont…. 
• The array we used in the last example was a one dimensional array. Arrays can have more than one 
dimension, these arrays-of-arrays are called multidimensional arrays. They are very similar to 
standard arrays with the exception that they have multiple sets of square brackets after the array 
identifier. A two dimensional array can be though of as a grid of rows and columns. 
This section will take a look at the two dimension array. 
Example in this case it like matrix 4 * 5 show as below 
10 5 -3 17 82 
9 0 0 8 -7 
32 20 1 0 14 
0 0 8 7 6 
Int M[4][5] = { 
{10 , 5 , -3 , 17 ,82 }, 
{9 , 0 , 0 , 8 , -7} , 
{32 , 20 , 1 , 0 , 14 }, 
{0 , 0 , 8 , 7 , 6} 
};
Block(cont.) 
• it can have parameter also 
• it can be the parameter of function 
• we use it as a parameter, it mean that we want to get the value of the processing of 
block in the parameter 
• it can not use global variable 
• it can only use its own variable in block
Block(cont.) 
• Syntax 
return-type(^block-name)(parameter-type) = ^(parameter-type and name){ 
//block-body 
}
Block 
• default of block or this way 
 
• Accessing 
• it is similar to function when we call block to use
Block with parameter 
• we can use block with parameter and return type 
• accessing
Block with parameter(cont.) 
• it can take multiple parameter and more 
• accessing
Access outside variable in block 
• you can not access outside variable in the block if you try, you will get error like this
Access outside variable in block(cont.) 
• solution 
• it mean that you declare variable for block can use it
Block as function parameter 
• we can use block as a parameter of a function 
• file.h
Block as function parameter(cont.) 
• file.m 
implement body 
accessing method
Block as function parameter(cont.) 
• block as parameter can take two or more parameter in it and return value also 
• note parameter-name for block is not importance we do not need to declare the name 
but when we call it we need to assign name to it 
file.h 
we do not need to define a name (optional)
Block as function parameter(cont.) 
• file.m 
we do not need to define a name (optional)
Block as function parameter(cont.) 
• main method 
we need to assign name to it
Structures 
• Structure is an entity that contains various types of variable in it
Structures(Cont.) 
• Initialize a structure
Structures(cont.) 
• Accessing variables in structures
Pointer 
• What is pointer? 
 A variable that is able to store the address of another variable is called a "pointer”. 
 Allows us to indirectly access variables 
o In other words, we can talk about its address rather than its value 
• Syntax to create pointer: 
Datatype *pointer_name. 
example: int *a; 
 Simple int or float or double variables, they are like a box which can store a single int or float 
or double value. Example: int a=10;  a 
10 
 Let create other variable that using pointer. Example: int *b;  b
Pointer(cont.) 
 Can we write int *d = 10 ? NO WE CANNOT. As I told you above pointer variable can only store address 
not value. If we write it in Xcode it will show the warning for us. 
 And if we still want to print out the *d value we will get this result. 
Result:
Pointer(cont.) 
 If we write int *d=10, it will look like: 
 For now let assign our pointer variable to other value. 
Result 
D
Pointer(cont.) 
• Let’s see how our pointer get value from variable a: 
10 
a 
d 0x103FF 
 Variable d is only store address that reference to the variable a. 
• Array and pointer; 
 I will create an array with 5 elements within it. 
 And I will create a pointer that point to it.
Pointer(cont.) 
• Let see how it work in memory 
• Let print out the value of b: 
• So, how can we print out the value of 20? 
 It will print out 20. 
• What does *(d+1) mean? 
 It means that now we are moving the address of d to one block forward. 
a[5] 
10 
20 
30 
40 
50 
value 
address 
x3100 
x3101 
x3102 
x3103 
x3104 
*b 
x3100
Pointer and structure 
• We have learned about the structure already. So ,now let make it work with our pointer.
Pointer and structure(cont.) 
• So how can we access structure members in our structure? 
• Let try to print out all the value: 
Or 
Or
Pointer and Function 
• Let create function with parameters as pointer :
Pointer and Function(cont.) 
• How to call and use it : 
• Result:
Pointer and Function(cont.) 
• So let call swap for the second time: 
• The result will be like
The goto Statement 
• goto statement cause a direct to specified point in the program. 
• To identify where the program to be made you have to create label. 
• This label can be located anywhere in the function before or after the goto. 
• Syntax: 
goto labelName; 
labelName: statement;
The Null Statement 
• A null statement consist of only a semicolon ( ; ) and perform no operation. When you 
place a semicolon ( ; ) wherever a normal program statement appear, known as the null 
statement. 
• Sometime in the program you place it at the end statement but you can place it after 
while, for, do statements to terminate loop expression. 
• Example: 
null statement
The Comma Operator 
• The comma operator ( , ) allows you to use two or expressions where only one 
expression is expected. Look at the example: 
Output: 
• When you evaluate between two operands while assign value to variable a it’ll take the 
result and discard the result of variable b. 
• One more thing is using in for statement expression.
The sizeof Operator 
• Although you never make clear about size of data type in your program, sometimes you 
need to know this information. 
• Now you can use the sizeof operator to determines sizes. 
• Example:
Command-Line Arguments 
• Similar to Java when you want to pass some value from the command line to your 
Objective-C program when they are executed. These value are called command line 
arguments. 
• The command line are handle using main() function arguments.
Command-Line Argument (cont.) 
• Click  Product  Scheme  Edit Scheme then show this dialog, click add argument.
How Things Works 
Because of Objective-C language has the C language underneath so this section 
will explain how relationship between Objective C and C language and there are four 
factors that we will talk about it. 
Fact 1 : Instance Variables Are Store in Structures 
In C language to manipulate instance variables or to defines a physically grouped 
list of variables to be placed under one name. On the other hand, In Objective C we use 
class to manipulate instances and objects.
How Things Works (cont.) 
• Fact 2 : An Object Variable Is Really a Pointer 
Objective-C has pointers because it is an evolution of C, which used pointers 
extensively. In C you may usually use pointer with array or structure and so on. Objective- 
C provides convenient access to memory addresses through the use of pointers to 
particular types. The main advantage of pointer types is that they allow you to interpret 
any memory address as the potential location of a variable.
How Things Works (cont.) 
• Fact 3 : Methods Are Functions, and Message Expressions Are Function Calls 
Methods are really function. In Objective C, there are sender and receiver that 
sender send the message and receiver will receive the message from sender. The way 
that we send or receive the message is call sending message that mean calling function. 
• Fact 4 : The id Type is Generic Pointer Type 
Objective-C provides support for dynamic typing via the id data type. The id type is 
a unique Objective-C type that can hold a pointer to any type of Objective-C object, 
regardless of its class.
Block 
• Block is use like a function but it have some difference from function 
• Block can declare out of class it is not follow by class, it can declare everywhere 
• Block can not create in file.h, it can create only file.m 
• if we create in file.h it is not error at compile time but it is error at runtime 
• it follow by Caret sign (^) 
• it follow by the semi-colon (;)
Thank You

More Related Content

What's hot

Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Rasan Samarasinghe
 
C programming session 05
C programming session 05C programming session 05
C programming session 05Dushmanta Nath
 
C programming session 01
C programming session 01C programming session 01
C programming session 01Dushmanta Nath
 
Pointers-Computer programming
Pointers-Computer programmingPointers-Computer programming
Pointers-Computer programmingnmahi96
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programmingnmahi96
 
Functions in c language
Functions in c language Functions in c language
Functions in c language tanmaymodi4
 
Programming in C Session 1
Programming in C Session 1Programming in C Session 1
Programming in C Session 1Prerna Sharma
 
Strings-Computer programming
Strings-Computer programmingStrings-Computer programming
Strings-Computer programmingnmahi96
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2Prerna Sharma
 
C programming session 02
C programming session 02C programming session 02
C programming session 02Dushmanta Nath
 
12 computer science_notes_ch01_overview_of_cpp
12 computer science_notes_ch01_overview_of_cpp12 computer science_notes_ch01_overview_of_cpp
12 computer science_notes_ch01_overview_of_cppsharvivek
 
Computer programming(CP)
Computer programming(CP)Computer programming(CP)
Computer programming(CP)nmahi96
 
Resource wrappers in C++
Resource wrappers in C++Resource wrappers in C++
Resource wrappers in C++Ilio Catallo
 

What's hot (20)

Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++
 
C programming session 05
C programming session 05C programming session 05
C programming session 05
 
C Theory
C TheoryC Theory
C Theory
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
Pointers-Computer programming
Pointers-Computer programmingPointers-Computer programming
Pointers-Computer programming
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
Programming in C Session 1
Programming in C Session 1Programming in C Session 1
Programming in C Session 1
 
Strings-Computer programming
Strings-Computer programmingStrings-Computer programming
Strings-Computer programming
 
C tutorial
C tutorialC tutorial
C tutorial
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 
12 computer science_notes_ch01_overview_of_cpp
12 computer science_notes_ch01_overview_of_cpp12 computer science_notes_ch01_overview_of_cpp
12 computer science_notes_ch01_overview_of_cpp
 
C
CC
C
 
Ch4 functions
Ch4 functionsCh4 functions
Ch4 functions
 
Computer programming(CP)
Computer programming(CP)Computer programming(CP)
Computer programming(CP)
 
Resource wrappers in C++
Resource wrappers in C++Resource wrappers in C++
Resource wrappers in C++
 

Viewers also liked

Galdetzea ta kontatzea zer egin duen
Galdetzea ta kontatzea zer egin duenGaldetzea ta kontatzea zer egin duen
Galdetzea ta kontatzea zer egin duenKristina Gago
 
2 оголошення про результати проведення торг в no. 3 2013-ор
2 оголошення про результати проведення торг в no. 3 2013-ор2 оголошення про результати проведення торг в no. 3 2013-ор
2 оголошення про результати проведення торг в no. 3 2013-орLibrary Franko
 
Permendikbud no-54-tahun-2013-ttg-skl
Permendikbud no-54-tahun-2013-ttg-sklPermendikbud no-54-tahun-2013-ttg-skl
Permendikbud no-54-tahun-2013-ttg-sklAlvin Cg
 
Los mejores consejos para cuidar la piel de tu semblante.
Los mejores consejos para cuidar la piel de tu semblante.Los mejores consejos para cuidar la piel de tu semblante.
Los mejores consejos para cuidar la piel de tu semblante.evasivezero5044
 
Liste adhérents 2015
Liste adhérents 2015Liste adhérents 2015
Liste adhérents 2015aprova84
 
SOPRANO Energy division EnerTermoPac for Green House CO2 included 2015 EV V01
SOPRANO Energy division EnerTermoPac for Green House CO2 included 2015 EV V01SOPRANO Energy division EnerTermoPac for Green House CO2 included 2015 EV V01
SOPRANO Energy division EnerTermoPac for Green House CO2 included 2015 EV V01Christian Moreau
 
لماذا جوجل؟؟؟ ولماذا ليس جوجل؟؟؟ Why is Google? and why is not Google?
لماذا جوجل؟؟؟  ولماذا ليس جوجل؟؟؟   Why is Google?  and why is  not Google?لماذا جوجل؟؟؟  ولماذا ليس جوجل؟؟؟   Why is Google?  and why is  not Google?
لماذا جوجل؟؟؟ ولماذا ليس جوجل؟؟؟ Why is Google? and why is not Google?Heyam hayek
 
¿Con respeto! euskaraz
¿Con respeto! euskaraz¿Con respeto! euskaraz
¿Con respeto! euskarazKristina Gago
 
Complete analysis of Mahindra & Mahindra
Complete analysis of Mahindra & MahindraComplete analysis of Mahindra & Mahindra
Complete analysis of Mahindra & MahindraSantosh Tiwari
 

Viewers also liked (11)

Presentazione bSmart
Presentazione bSmartPresentazione bSmart
Presentazione bSmart
 
Resume Sami
Resume SamiResume Sami
Resume Sami
 
Galdetzea ta kontatzea zer egin duen
Galdetzea ta kontatzea zer egin duenGaldetzea ta kontatzea zer egin duen
Galdetzea ta kontatzea zer egin duen
 
2 оголошення про результати проведення торг в no. 3 2013-ор
2 оголошення про результати проведення торг в no. 3 2013-ор2 оголошення про результати проведення торг в no. 3 2013-ор
2 оголошення про результати проведення торг в no. 3 2013-ор
 
Permendikbud no-54-tahun-2013-ttg-skl
Permendikbud no-54-tahun-2013-ttg-sklPermendikbud no-54-tahun-2013-ttg-skl
Permendikbud no-54-tahun-2013-ttg-skl
 
Los mejores consejos para cuidar la piel de tu semblante.
Los mejores consejos para cuidar la piel de tu semblante.Los mejores consejos para cuidar la piel de tu semblante.
Los mejores consejos para cuidar la piel de tu semblante.
 
Liste adhérents 2015
Liste adhérents 2015Liste adhérents 2015
Liste adhérents 2015
 
SOPRANO Energy division EnerTermoPac for Green House CO2 included 2015 EV V01
SOPRANO Energy division EnerTermoPac for Green House CO2 included 2015 EV V01SOPRANO Energy division EnerTermoPac for Green House CO2 included 2015 EV V01
SOPRANO Energy division EnerTermoPac for Green House CO2 included 2015 EV V01
 
لماذا جوجل؟؟؟ ولماذا ليس جوجل؟؟؟ Why is Google? and why is not Google?
لماذا جوجل؟؟؟  ولماذا ليس جوجل؟؟؟   Why is Google?  and why is  not Google?لماذا جوجل؟؟؟  ولماذا ليس جوجل؟؟؟   Why is Google?  and why is  not Google?
لماذا جوجل؟؟؟ ولماذا ليس جوجل؟؟؟ Why is Google? and why is not Google?
 
¿Con respeto! euskaraz
¿Con respeto! euskaraz¿Con respeto! euskaraz
¿Con respeto! euskaraz
 
Complete analysis of Mahindra & Mahindra
Complete analysis of Mahindra & MahindraComplete analysis of Mahindra & Mahindra
Complete analysis of Mahindra & Mahindra
 

Similar to Presentation 5th

Similar to Presentation 5th (20)

Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
 
C Programming - Refresher - Part IV
C Programming - Refresher - Part IVC Programming - Refresher - Part IV
C Programming - Refresher - Part IV
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
 
Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Ppt of c vs c#
Ppt of c vs c#Ppt of c vs c#
Ppt of c vs c#
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2nd
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit DubeyMCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance level
 
#Code2 create c++ for beginners
#Code2 create  c++ for beginners #Code2 create  c++ for beginners
#Code2 create c++ for beginners
 
C#unit4
C#unit4C#unit4
C#unit4
 
C programming language
C programming languageC programming language
C programming language
 
Lập trình C
Lập trình CLập trình C
Lập trình C
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
 
C language updated
C language updatedC language updated
C language updated
 
Pc module1
Pc module1Pc module1
Pc module1
 
C
CC
C
 
C programming tutorial for Beginner
C programming tutorial for BeginnerC programming tutorial for Beginner
C programming tutorial for Beginner
 
Presentation c++
Presentation c++Presentation c++
Presentation c++
 

Presentation 5th

  • 1. Preprocessor and Underlying C laungage Chorn Charly Leang Bunrong Cheng Udam Kan Vichhai Srou Chanthorn Em Vy Seth Sambo Chea Socheat
  • 2. Content  #define  #import  #include  #undef  Conditional compilications  Array  Function  Block structure Pointers Miscellaneous Language Features How Things Work
  • 3. Preprocessor  Preprocessor is the initial program. the first step in compile files it need through initial the program.(note preprocessor not finish with “ ; ”).  Preprocessor is begin with #.  Preprocessor advantages: 1. Define constants(UpperCase All for name convention). 2. Import files to files at specifice point 3. condictionally compile code( use to prevent Program). 4. Reduce coding Oh ! It is in .h file. Preprocessor Compiler(GCC) .h file
  • 4. Preprocessor(cont.) Source program Compiled code Objective – C Compiler(e.g gcc) Objective – C Preprocessor GCC(objective-C compiler)
  • 5. Preprocessor(cont.)  Preprocessor are: #define,#include,#import and conditional compilation ..etc. 1. #define is used to define constants.it also is used to define macro to make easy for develper that can use own keyword to develop own project( reduce line of codes).  Syntax: #define constantName value  Example:
  • 6. Preprocessor(cont.)  #import (#include in C language) is the preprocessor to insert the text of the file Header File.h Into file being processed at the point of the #import line.  Syntax1: #import “headerName.h”  Syntax2:#import <package/headerName.h>  Example:  Syntax1 is used to import files (class,category...etc) in own project (new class that implement by new generation).  Syntax2 is used to import files (package,class...etc) in othe package to our project(build in classes , libraries ..etc.(Foundation.h,UIKit...etc).
  • 7. Preprocessor(cont.)  #if,#ifdef,#ifndef proprocessor is like if statement. but it execute during compile time(condictionally during compile time).  Syntax1: #if identifier(macro or constant) //statements(macro ) #else // statements(macro) #endif  Example:  Note: #define is no space . In #if preprocessor between # and define keyword is got a space character.(#define => # define).
  • 8. Preprocessor(cont.)  #ifdef....#endif,#ifndef .......#endif is executed as #if the same.objective – C new version recomment that should not use #if .it can duplicate include file in compile time.  Syntax1: #ifndef identifier(macro or constant) //statements(macro ) #else // statements(macro) #endif  Note:identifier(macro or constant) we can configure Xcode to create it.  #if , #ifdef is executed when identifier=1(true) but #ifndef is executed when identifier=0(false).
  • 9. Preprocessor(cont.)  To define Constant by configure Xcode.
  • 10. Preprocessor(cont.)  To define Constant by configure Xcode. Double click on debug.and add new Constant Identifier or constant
  • 12. Preprocessor(cont.)  #undef is used to reset macro.  Syntax: #undef macroname
  • 13. Array • Objective-c array represent an entire set of values. Then each value store in the different element of the set using a number called an index number. Index number start from 0 to n-1. you can use array anywhere the variable dose. It similar to variable you need to declare before use. Declare an array involves declaring the type of element that will be contained in the array. Int fibonacci [15]; //declare an array named fibonacci with the 15 size Int integers[5] = {0,1,2,3,4}; // declare an array with initialize Char letters[5] = {‘a’,’b’,’c’,’d’,’e’}; //declare an array with character Int a[10] = { [9] = 1 , [2]=3 , [1]=2 , [0]=1}; //declare an array with initialize base the specific type
  • 14. Array cont…. • The array we used in the last example was a one dimensional array. Arrays can have more than one dimension, these arrays-of-arrays are called multidimensional arrays. They are very similar to standard arrays with the exception that they have multiple sets of square brackets after the array identifier. A two dimensional array can be though of as a grid of rows and columns. This section will take a look at the two dimension array. Example in this case it like matrix 4 * 5 show as below 10 5 -3 17 82 9 0 0 8 -7 32 20 1 0 14 0 0 8 7 6 Int M[4][5] = { {10 , 5 , -3 , 17 ,82 }, {9 , 0 , 0 , 8 , -7} , {32 , 20 , 1 , 0 , 14 }, {0 , 0 , 8 , 7 , 6} };
  • 15. Block(cont.) • it can have parameter also • it can be the parameter of function • we use it as a parameter, it mean that we want to get the value of the processing of block in the parameter • it can not use global variable • it can only use its own variable in block
  • 16. Block(cont.) • Syntax return-type(^block-name)(parameter-type) = ^(parameter-type and name){ //block-body }
  • 17. Block • default of block or this way • Accessing • it is similar to function when we call block to use
  • 18. Block with parameter • we can use block with parameter and return type • accessing
  • 19. Block with parameter(cont.) • it can take multiple parameter and more • accessing
  • 20. Access outside variable in block • you can not access outside variable in the block if you try, you will get error like this
  • 21. Access outside variable in block(cont.) • solution • it mean that you declare variable for block can use it
  • 22. Block as function parameter • we can use block as a parameter of a function • file.h
  • 23. Block as function parameter(cont.) • file.m implement body accessing method
  • 24. Block as function parameter(cont.) • block as parameter can take two or more parameter in it and return value also • note parameter-name for block is not importance we do not need to declare the name but when we call it we need to assign name to it file.h we do not need to define a name (optional)
  • 25. Block as function parameter(cont.) • file.m we do not need to define a name (optional)
  • 26. Block as function parameter(cont.) • main method we need to assign name to it
  • 27. Structures • Structure is an entity that contains various types of variable in it
  • 29. Structures(cont.) • Accessing variables in structures
  • 30. Pointer • What is pointer?  A variable that is able to store the address of another variable is called a "pointer”.  Allows us to indirectly access variables o In other words, we can talk about its address rather than its value • Syntax to create pointer: Datatype *pointer_name. example: int *a;  Simple int or float or double variables, they are like a box which can store a single int or float or double value. Example: int a=10;  a 10  Let create other variable that using pointer. Example: int *b;  b
  • 31. Pointer(cont.)  Can we write int *d = 10 ? NO WE CANNOT. As I told you above pointer variable can only store address not value. If we write it in Xcode it will show the warning for us.  And if we still want to print out the *d value we will get this result. Result:
  • 32. Pointer(cont.)  If we write int *d=10, it will look like:  For now let assign our pointer variable to other value. Result D
  • 33. Pointer(cont.) • Let’s see how our pointer get value from variable a: 10 a d 0x103FF  Variable d is only store address that reference to the variable a. • Array and pointer;  I will create an array with 5 elements within it.  And I will create a pointer that point to it.
  • 34. Pointer(cont.) • Let see how it work in memory • Let print out the value of b: • So, how can we print out the value of 20?  It will print out 20. • What does *(d+1) mean?  It means that now we are moving the address of d to one block forward. a[5] 10 20 30 40 50 value address x3100 x3101 x3102 x3103 x3104 *b x3100
  • 35. Pointer and structure • We have learned about the structure already. So ,now let make it work with our pointer.
  • 36. Pointer and structure(cont.) • So how can we access structure members in our structure? • Let try to print out all the value: Or Or
  • 37. Pointer and Function • Let create function with parameters as pointer :
  • 38. Pointer and Function(cont.) • How to call and use it : • Result:
  • 39. Pointer and Function(cont.) • So let call swap for the second time: • The result will be like
  • 40. The goto Statement • goto statement cause a direct to specified point in the program. • To identify where the program to be made you have to create label. • This label can be located anywhere in the function before or after the goto. • Syntax: goto labelName; labelName: statement;
  • 41. The Null Statement • A null statement consist of only a semicolon ( ; ) and perform no operation. When you place a semicolon ( ; ) wherever a normal program statement appear, known as the null statement. • Sometime in the program you place it at the end statement but you can place it after while, for, do statements to terminate loop expression. • Example: null statement
  • 42. The Comma Operator • The comma operator ( , ) allows you to use two or expressions where only one expression is expected. Look at the example: Output: • When you evaluate between two operands while assign value to variable a it’ll take the result and discard the result of variable b. • One more thing is using in for statement expression.
  • 43. The sizeof Operator • Although you never make clear about size of data type in your program, sometimes you need to know this information. • Now you can use the sizeof operator to determines sizes. • Example:
  • 44. Command-Line Arguments • Similar to Java when you want to pass some value from the command line to your Objective-C program when they are executed. These value are called command line arguments. • The command line are handle using main() function arguments.
  • 45. Command-Line Argument (cont.) • Click  Product  Scheme  Edit Scheme then show this dialog, click add argument.
  • 46. How Things Works Because of Objective-C language has the C language underneath so this section will explain how relationship between Objective C and C language and there are four factors that we will talk about it. Fact 1 : Instance Variables Are Store in Structures In C language to manipulate instance variables or to defines a physically grouped list of variables to be placed under one name. On the other hand, In Objective C we use class to manipulate instances and objects.
  • 47. How Things Works (cont.) • Fact 2 : An Object Variable Is Really a Pointer Objective-C has pointers because it is an evolution of C, which used pointers extensively. In C you may usually use pointer with array or structure and so on. Objective- C provides convenient access to memory addresses through the use of pointers to particular types. The main advantage of pointer types is that they allow you to interpret any memory address as the potential location of a variable.
  • 48. How Things Works (cont.) • Fact 3 : Methods Are Functions, and Message Expressions Are Function Calls Methods are really function. In Objective C, there are sender and receiver that sender send the message and receiver will receive the message from sender. The way that we send or receive the message is call sending message that mean calling function. • Fact 4 : The id Type is Generic Pointer Type Objective-C provides support for dynamic typing via the id data type. The id type is a unique Objective-C type that can hold a pointer to any type of Objective-C object, regardless of its class.
  • 49. Block • Block is use like a function but it have some difference from function • Block can declare out of class it is not follow by class, it can declare everywhere • Block can not create in file.h, it can create only file.m • if we create in file.h it is not error at compile time but it is error at runtime • it follow by Caret sign (^) • it follow by the semi-colon (;)

Editor's Notes

  1. This case , I focus on Structures not Struct keyword.. That mean in C to manipulate instance we use struct{} But in Objective-C we use class to manipulate it.
  2. That mean in C language we use pointer to declare array pointer variable and so on cos pointer reference to address in memory SO Object variable in Objective C is a Pointer too.