Lesson 12 - Function - Compatibility Mode
Lesson 12 - Function - Compatibility Mode
Introduction
Functions
1 2
3 4
3 4
5 6
5 6
1
FUNCTION DEFINITIONS FUNCTION PROTOTYPES
Declarations and statements: function body (block) Function prototype
Variables can be declared inside blocks (can be nested) Function name
Function can not be defined inside another function Parameters - what the function takes in
7 8
7 8
9 10
• int A;
• void main() VARIABLE
SCOPE RULES
{ A = 1; SCOPE
Block scope myProc();
printf ( "A = %d\n", A);
Identifier declared inside a block }
Nguyen Thi Thu Huong - SoICT -HUST
11 12
2
DATA STRUCTURES (STRUCT)
14
13 14
15 16
17 18
3
ACCESSING STRUCT MEMBERS
SAMPLE PROGRAM WITH STRUCTS
Individual members of a struct variable may be /* This program illustrates creating structs and
accessed using the structure member operator (the then declaring and using struct variables.
Note that struct personal is an included data
(*myptr).letter ;
19 20
js.person.id = 123456789 ;
js.person.gpa = 3.4 ;
printf ("%s %ld %f\n", js.name, js.person.id,
js.person.gpa) ;
printf ("%s %ld %f\n", ptr->name, ptr->person.id,
ptr->person.gpa) ;
}
21
21