170 likes | 202 Views
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. Function calls. Parameters and Return. Void Parameter and Void Return.
E N D
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
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).
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.
Different ways of calling #include <stdio.h> int main (void) /* example of Postfix increment*/ { int a; a = 5; printf("%d\t", a); printf("%d\t", a++); printf("%d\n", a); return 0; } /* Results: 5 5 6 */