Sams Teach Yourself C in 21 Days
13: 14: int main( void ) 15: { 16: int guess_value = -1; 17: int number; 18: int nbr_of_guesses; 19: int done = NO; 20: 21: prin ...
Find the Number 95 If you want to cheat, you can add a line to the program that prints the answer after the program generates it ...
08 448201x-T&R2 8/13/02 11:20 AM Page 96 ...
DAY 5 WEEK 1 Packaging Code in Functions Functions are central to C programming and to the philosophy of C program design. You’v ...
What Is a Function? .............................................................................................. Today you wil ...
Packaging Code in Functions 99 5 10: printf(“Enter an integer value: “); 11: scanf(“%d”, &input); 12: answer = cube(input); ...
Line 12 calls the function cubeand passes the variable inputto it as the function’s argu- ment. The function’s return value is a ...
Packaging Code in Functions 101 5 execution passes back to the place from which the function was called. A function can be calle ...
be included in the function header. Following the header is the function body, containing the statements that the function will ...
Packaging Code in Functions 103 5 A related advantage of structured programming is the time you can save. If you write a functio ...
names and addresses” function and the “Modify existing entries” function. The same is true for “Save the updated list to disk.” ...
Packaging Code in Functions 105 5 Now that you know what functions are and why they’re so important, the time has come for you t ...
In these examples, you can see that func1returns an integer,func2returns a floating- point number, and func3doesn’t return anyth ...
Packaging Code in Functions 107 5 the same number and type of arguments each time it’s called, but the argument values can be di ...
value of 65.11. When the program runs, it prints the correct number for each. The values inxandyare passed into the argument kof ...
Packaging Code in Functions 109 5 they are declared. You can declare any of C’s variable types in a function. Here is an example ...
Before calling demo(), x = 1 and y = 2. Within demo(), x = 88 and y = 99. After calling demo(), x = 1 and y = 2. Listing 5.3 is ...
Packaging Code in Functions 111 5 What about function length? C places no length restriction on functions, but as a matter of pr ...
8: 9: int main( void ) 10: { 11: puts(“Enter two different integer values: “); 12: scanf(“%d%d”, &x, &y); 13: 14: z = la ...
Packaging Code in Functions 113 5 One final note on this program. Line 11 is a new function that you haven’t seen before. puts() ...
«
2
3
4
5
6
7
8
9
10
11
»
Free download pdf