by Dinesh Thakur Category: Function and Pointer

Before a function is called in a program, the system should know where to look for the function definition. In case of functions belonging to C standard library we include the relevant header files in which the function is defined. This is done above the main() function. In case of user-defined functions, a function may be defined above or below the main function, because, a function cannot be defined inside another function. If a function is defined above the main function, there is no need of a separate declaration of function. However, if the function is defined below the main function, it is a good programming practice to declare the functions being used above the main. A function declaration may be done by the function header or by its prototype.

 
by Dinesh Thakur Category: Function and Pointer

We have defined a pointer as a variable which keeps the address of another variable. Since pointer is also a variable and is allocated memory space in which its value is stored, so we can have another variable which keeps the address of the pointer. That would be a pointer to a pointer. Such a pointer to a pointer is depicted in Fig, in which pointer ppa points to pointer pa, which in turn points to variable a. These pointers can be initialized as shown below.

 
by Dinesh Thakur Category: Function and Pointer

In many cases and particularly in computer games, a seed number cannot be provided on every event. We need some function whose return value is always changing. Time is always changing; so, we make use of function time() defined in the header file <time.h>.



 
by Dinesh Thakur Category: Function and Pointer

C allows programmers to define their own functions. Such functions are called user defined functions. In fact, the main function that must be present in every C program is a user-defined function. A programmer may define additional functions in the following situations:

 
by Dinesh Thakur Category: Function and Pointer

Just like every variable in a program has an address, every function in a program too has an address. The name of the function can be used to obtain the address of a function. This address can be stored in a special type of variable which are pointers to functions. We had seen that even though all addresses are similar, there exist different types of address variables to store the addresses of different data types. For example, an int * variable stores the address of an int type variable and a long * variable stores the address of a long type variable. In a similar fashion, we will need different types of pointers to functions depending on the different types of functions. 



 
by Dinesh Thakur Category: Function and Pointer

We may often require a horizontal line of a dash, underline or some other character to be printed, particularly when printing results in a tabular format. Consider a situation in which we require a line containing a fixed number of a specific character (e.g., 65 dash characters) to be printed several times.

 
by Dinesh Thakur Category: Function and Pointer

The function time () returns the current calendar time, i.e., the number of seconds elapsed since 00:00:00 hour January 1, 1970 GMT (or gmt are used alternatively) up to the execution of the function. The function prototype is written as follows:

 
by Dinesh Thakur Category: Function and Pointer

The exit function can be used to terminate program execution and return a specified value as program status to the calling program, usually the operating system. A zero value indicates success. An example of the exit function indicating unsuccessful termination of a program is shown below.



 
by Dinesh Thakur Category: Function and Pointer

A function may have another function as one of its parameters besides having parameters of other data types. A function is a derived type object; its type is derived from the type of data it returns. Like arrays, the name of a function also holds the address of the function.

 

Page 6 of 8

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content







Popular Article