
For practice, look again at the long program in Appendix B. You might see additional pairs of braces within a main() function as well. Chapter 30, “Organizing Your Programs with Functions,” covers writing your own functions.Īfter the word main(), you always see an opening brace ( ), main() is finished. As you improve your C skills, you’ll learn why adding functions after main() improves your programming power even more. The programs in the next several chapters have only one function: main(). Therefore, for readability, make main() the first function in every program you write. Even if main() is not the first function listed in your program, main() still determines the beginning of the program’s execution. Just as the home page is the beginning place to surf a website, main() is always the first place the computer begins when running your program. You can use uppercase for the functions that you write, but most C programmers stay with the lowercase function name convention. The required main() function and all of C’s supplied function names must contain lowercase letters. (Spaces aren’t allowed in function names.) Stay away from typing words in all uppercase, but an uppercase letter for clarity once in a while is okay. If a name has multiple parts, as in doReportPrint(), it’s common practice to use uppercase letters to begin the separate words, to increase readability. However, the preceding section said you should stay away from uppercase letters. One of the functions just listed, calcIt(), contains an uppercase letter. Most of the time, authors want to clarify the differences between functions and nonfunctions as much as possible, so you’ll usually see the parentheses. You’ll learn to recognize function names soon enough, so such differences won’t matter much to you.

For example, you might read about the printf function instead of printf(). When you read other C programming books, manuals, and webpages, the author might decide to omit the parenthesis from the end of function names. These are functions: main() calcIt() printf() strlen() and these are commands: return while int if float A function is distinguished from a command by the parentheses that follow the function name. Each program must always include a main() function. C programs are made up of one or more functions. Some functions come with C, and some are created by you. A function is nothing more than a routine that performs some task. Although at this point the distinction is not critical, main() is a C function, not a C command. Both of the programs discussed earlier have main() functions. The most important part of a C program is its main() function. The execution of a C program begins from the main() function.C Programming Absolute Beginner's Guide, 3rd Edition Such functions created by the user are known as user-defined functions. You can also create functions as per your need. Visit standard library functions in C programming to learn more. The function is defined in the math.h header file.

The standard library functions are built-in functions in C programming. There are two types of function in C programming: You can create two functions to solve this problem:ĭividing a complex problem into smaller chunks makes our program easy to understand and reuse. Suppose, you need to create a program to create a circle and color it.


A function is a block of code that performs a specific task.
