Sams Teach Yourself C in 24 Hours by Zhang Tony
Author:Zhang, Tony.
Language: eng
Format: epub, pdf
19 067231861x pt 4 1/25/00 10:27 AM Page 241
PART IV
Functions and Dynamic
Memory Allocation
Hour
15 Working with Functions
16 Applying Pointers
17 Allocating Memory
18 Using Special Data Types and Functions
19 067231861x pt 4 1/25/00 10:27 AM Page 242
20 067231861x CH15 4.10.2000 11:03 AM Page 243
HOUR 15
Working with Functions
Form follows function.
âL. H. Sullivan
In Hour 14, âUnderstanding Scope and Storage Classes,â you might have
noticed that a function definition is always given first, before the function is called from a main() function. In fact, you can put a function definition anywhere you want, as long as you put the function declaration before the first place where the function is called. Youâll learn about many features of functions from the following topics covered in this lesson:
⢠Function declarations
⢠Prototyping
⢠Values returned from functions
⢠Arguments to functions
⢠Structured programming
In addition, several C library functions and macros, such as time(),
localtime(), asctime(), va_start(), va_arg(), and va_end() are
introduced in this hour.
20 067231861x CH15 4.10.2000 11:03 AM Page 244
244
Hour 15
Declaring Functions
As you know, you have to declare or define a variable before you can use it. This is also true for functions. In C, you have to declare or define a function before you can call it.
Declaration Versus Definition
According to the ANSI standard, the declaration of a variable or function specifies the interpretation and attributes of a set of identifiers. The definition, on the other hand, requires the C compiler to reserve storage for a variable or function named by an identifier.
A variable declaration is a definition, but a function declaration is not. A function declaration alludes to a function that is defined elsewhere and specifies what kind of value is returned by the function. A function definition defines what the function does, as well as gives the number and type of arguments passed to the function.
A function declaration is not a function definition. If a function definition is placed in your source file before the function is first called, you donât need to make the function declaration. Otherwise, the declaration of a function must be made before the function is invoked.
For example, Iâve used the printf() function in almost every sample program in this book. Each time, I had to include a header file, stdio.h, because the header file contains the declaration of printf(), which indicates to the compiler the return type and prototype of the function. The definition of the printf() function is placed somewhere else.
In C, the definition of this function is saved in a library file that is invoked during the linking states.
Specifying Return Types
A function can be declared to return any data type, except an array or function. The return statement used in a function definition returns a single value whose type should match the one declared in the function declaration.
By default, the return type of a function is int, if no explicit data type is specified for the function. A data type specifier is placed prior to the name of a function like this: data_type_specifier
function_name();
Here data_type_specifier specifies the data type that the function should return.
function_name is the function name that should follow the rules of naming identifiers in C.
Download
Sams Teach Yourself C in 24 Hours by Zhang Tony.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(7851)
Learning SQL by Alan Beaulieu(5411)
Weapons of Math Destruction by Cathy O'Neil(5036)
Big Data Analysis with Python by Ivan Marin(3004)
Blockchain Basics by Daniel Drescher(2890)
Hands-On Machine Learning for Algorithmic Trading by Stefan Jansen(2516)
Pandas Cookbook by Theodore Petrou(2500)
Mastering Python for Finance by Unknown(2474)
Building Statistical Models in Python by Huy Hoang Nguyen & Paul N Adams & Stuart J Miller(2466)
Azure Data and AI Architect Handbook by Olivier Mertens & Breght Van Baelen(2435)
Serverless Machine Learning with Amazon Redshift ML by Debu Panda & Phil Bates & Bhanu Pittampally & Sumeet Joshi(2370)
How The Mind Works by Steven Pinker(2213)
Data Wrangling on AWS by Navnit Shukla | Sankar M | Sam Palani(2152)
Building Machine Learning Systems with Python by Richert Willi Coelho Luis Pedro(2058)
Data Engineering with dbt by Roberto Zagni(2049)
Driving Data Quality with Data Contracts by Andrew Jones(2020)
Network Science with Python and NetworkX Quick Start Guide by Edward L. Platt(1970)
Python Natural Language Processing by Jalaj Thanaki(1892)
Machine Learning Model Serving Patterns and Best Practices by Md Johirul Islam(1813)