O'Reilly logo

C Primer Plus, Fourth Edition by Stephen Prata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 code ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required