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

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

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

memchr (): The function searches for first occurrence of c through the first n characters of the string pointed to by S. If successful it returns pointer to c in the string. If not successful, it returns NULL or 0.

 
by Dinesh Thakur Category: Function and Pointer

For example, consider the declarations of a three-dimensional array of size 2 x 3 x 4 given below.

 
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.

 
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

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. 



 

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