by Dinesh Thakur Category: Function and Pointer

As we know, the expression x [i] to access the ith element of vector x can be equivalently written using pointer notation as * (x+i) . Thus, the expression a [i] [j] to access the ijth element of matrix a can be equivalently written as * (*(a+i) +j). Observe that this expression is obtained by applying twice the construct used for a vector. The address of a [i][j] is thus given as * (a+i) +j. These results are summarized below.

 
by Dinesh Thakur Category: Function and Pointer

When a C program is compiled, the compiler allocates memory to store different data elements such as constants, variables (including pointer variables), arrays and structures. This is referred to as compile-time or static memory allocation. There are several limitations in such static memory allocation:

 
by Dinesh Thakur Category: Function and Pointer

The return statement is used to terminate the execution of a function and transfer program control back to the calling function. In addition, it can specify a value to be returned by the function. A function may contain one or more return statements. The general format of the return statement is given below.

 
by Dinesh Thakur Category: Function and Pointer

If elements of an array are two-dimensional arrays, the array is called a three-dimensional array. Therefore, a three-dimensional array may be considered as an array of matrices. Let Arm be a 3-dimensional array or an array of matrices. The declaration of pointer and its initialization is carried out as given below.

 
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

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

The name or identifier of an array is itself a constant pointer to the array. Its value is the address of the first element of the array. Thus, a pointer to an array may be declared and assigned as shown below.

 
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.

 

Page 3 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