Function with Arguments
By now, you're familiar with using function arguments. The next step along the road to function mastery is learning how to write your own functions that use arguments. Let's preview that skill now. (At this point, you might want to review the butler() function example near the end of Chapter 2, "Introducing C;" it shows how to write a function without an argument.) Listing 5.15 includes a pound() function that prints a specified number of pound signs (# ). The example also illustrates some points about type conversion.
Listing 5.15 The pound.c program.
/* pound.c -- defines a function with an argument */ #include <stdio.h> void pound(int n); /* ANSI prototype */ int main(void) { int times = 5; char ch = '!'; /* ASCII ... |
Get C Primer Plus®, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.