by Dinesh Thakur Category: Function and Pointer

Since a pointer to type T is analogous to an array of type T, a pointer to a pointer (T**) is analogous to an array of type T*, i. e., an array of pointers to type T. Each element in this array of pointers can be used further to point to an array of type T. Thus, a pointer to a pointer can be used to represent two-dimensional arrays, as illustrated in Fig.

 
by Dinesh Thakur Category: Function and Pointer

A function definition comprises a head (or header) and a body. The header gives the information about type of function, name of function, and a list of parameters. The list of parameters comprises types and names of parameters enclosed in parentheses and separated by commas. An illustration of function definition is given below.



 
by Dinesh Thakur Category: Function and Pointer

The default returns value from a function in int. In other words generally unless explicitly specified the default return value by compiler would be integer value from function. So when a programmer wants other than integer values to be returned from function then it is essential that the programmer takes some steps in doing this namely:

 
by Dinesh Thakur Category: Function and Pointer

The main () is a special function that marks the beginning of the program. The type int before main signifies that function main () returns an integer value to the system on its completion.

 
by Dinesh Thakur Category: Function and Pointer

An individual element of an array may be regarded as a variable of the type declared in the declaration of the array. All the operators that can be applied to a variable of that type are applicable to the elements of array as well. Program, the array elements are subjected to arithmetic operations with the help of pointers.

 
by Dinesh Thakur Category: Function and Pointer

The Tower of Hanoi problem consists of three poles, left, middle, and right. One of the poles (say, the left) contains n disks of different sizes placed on each other, as shown in Fig. The objective of the problem is to transfer all the disksfrom the left pole to right pole such that only one disk can be moved at a time (to any pole) and a larger  disk cannot be placed on top of a smaller disk.

 
by Dinesh Thakur Category: Function and Pointer

It accepts three parameters  x,y, and z, each of type double and returns a value of type double.

 
by Dinesh Thakur Category: Function and Pointer

The clock function is used to determine the processor time in executing a program or part of a program. The header file <time.h> should be included in the program for its application. The function prototype is given below.

 
by Dinesh Thakur Category: Function and Pointer

The values of pointer variables are unsigned integer numbers which are addresses of other variables. An unsigned integer is allocated 4 bytes of memory for its storage on a typical 32-bit system. Thus, pointers to all types of data occupy the same size of memory because the value of a pointer is the memory address - an unsigned integer. However, the variables to which the pointers point to, of course, occupy different sizes of memory blocks according to their types.

 
by Dinesh Thakur Category: Function and Pointer

We can use typecast operator to convert the type of value returned by a pointer dereference expression to another suitable type. For example, if pa is a pointer to a variable a of type int, we can use typecast as (double) *pa to convert the integer value of *pa to type double.

 
by Dinesh Thakur Category: Function and Pointer

The C language permits a pointer to be declared for any data type. The declaration of a pointer variable takes the following general form:



 
by Dinesh Thakur Category: Function and Pointer

We have seen that a function can be called from another function. In fact, the C language allows a function to be called from within itself. Such a function is called a recursive function.

 
by Dinesh Thakur Category: Function and Pointer

This program defines a function named func which has two parameters, a and b of type int. Within its body, this function first prints these parameter values, initializes them to 30 and prints them again. The main function declares two variables, a and b of type int. It first prints the values of these variables and then calls the function func with variables a and b as its arguments. Finally, the main function prints the values of variables a and b again.

 
by Dinesh Thakur Category: Function and Pointer

exit () is used to exit the program as a whole. In other words it returns control to the operating system.

After exit () all memory and temporary storage areas are all flushed out and control goes out of program. In contrast the return statement is used to return from a function and return control to the calling function.



 
by Dinesh Thakur Category: Function and Pointer

The length of a string is defined as the number of characters in it excluding the null terminator. The strlen function returns the length of a specified string. A typical call to this function takes the following form:

 
by Dinesh Thakur Category: Function and Pointer

Another commonly required string operation is that of converting the case of a given string. The C standard library does not provide any function for case conversion. However, some C implementations provide the strlwr and strupr functions. The strlwr function converts all characters in a given string to lowercase, whereas the strupr function converts all characters to uppercase. Typical calls to these functions take the following forms:

 
by Dinesh Thakur Category: Function and Pointer

So far we have studied functions that either return a value or have a void return type. A function can also return a pointer to a data item of any type. However, we must be careful while returning pointers from a function. A common mistake would be to return a pointer to a local variable or value parameter in that function as they are destroyed when control returns to the calling function.

 
by Dinesh Thakur Category: Function and Pointer

We have studied that an array is a powerful built-in data structure in the C language. It is a collection of data items of the same type stored in consecutive memory locations. An element of an array can be accessed using subscript notation, as in a [i ] , b [ i ] [ j ] , etc. Also, we can process entire arrays using loops and pass them to functions.

 
by Dinesh Thakur Category: Function and Pointer

Every variable has a type associated with it which decides the values that can be assigned to it and the operations that can be performed on it. In addition, we can specify a storage class for a variable which decides the following:

 
by Dinesh Thakur Category: Function and Pointer

A standard C header file contains the declarations or prototypes of functions of a particular category. A function 'prototype usually specifies the type of value returned by that function, the function name and a list specifying parameter types as

 

Page 9 of 16



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.