Chapter 4 Functions Instructor Bindra Shrestha University of
Chapter 4 Functions Instructor: Bindra Shrestha University of Houston – Clear Lake
Acknowledgement Structured Programming Approach Using C By Behrouz A. Forouzan and Richard F. Gilberg
Function Modules 3
Function calls 4
Parameters and Return 5
Void Parameter and Void Return 6
Pass by Value, Return Void 7
Pass by Value 8
Function Defination 9
Passing two values by copy • A compound assignment is a shorthand notation for a simple assignment. • Compound assignment operators are: *=, /=, %=, +=, and -= • For example: For x*=y, equivalent simple expression is: x = x * y • Similarly, • x /= y is x = x/y • x -= y+ 4 is x = x- ( y+ 4) • x %= y is x = x % y • x *= y+2 is x = x* ( y+ 2). 10
• The postfix increment/decrement operates at the second level of the Precedence Table ( see inside front cover) • a ++ Here a is an operand while ++ is a postfix operator. • a++ has the same effect as a =a+1. • Although the result of both expression is the same, there is a major difference. For example: If variable a contains 4 before the expression is evaluated, the value of the expression a ++ is 4 • After the evaluating the expression and its side effects, then only a becomes 5. • 11
Different ways of calling #include <stdio. h> int main (void) /* example of Postfix increment*/ { int a; a = 5; printf("%dt", a); printf("%dt", a++); printf("%dn", a); return 0; } /* Results: 5 5 6 */ 12
One-way communication 13
Two-way communication 14
Two-way swapping values example 15
Mixed communication 16
Variable Scopes 17
- Slides: 17