Showing posts with label pointer in C. Show all posts
Showing posts with label pointer in C. Show all posts

Wednesday, October 21, 2009

RAGGED ARRARY

The two-dimensional array character type arrays occupy a fixed amount of memory space for each row that is rarely needed .Therefore , instead of making each row fixed number of characters . We can make it a pointer to a string of varying length.
The character Arrays with the rows of varying length are called "RAGGED ARRAY " and are better handled by pointer . For example :
char *cname[3] = {"india", "nepal" ,"bhutan"}; // is the declaration and intialisation of Ragged Array.

Saturday, October 17, 2009

POINTER

BASE ADDRESS AND CONSTANT POINTER :- When an array (any data type ) is declared , the compiler allocate a base address and sufficient amount of storage to contain all the element of the array in contiguous location .The BASE ADDRESS is the location of the first element( index 0) of the array .The compiler also defines the array name as a CONSTANT POINTER to the first element .Example int num = {12 , 5 , 107 , 55 , 291 } -- here an int type array num is declared and "num" is the constant pointer that denotes the base address of &num[0].

Friday, October 16, 2009

SCALE FACTOR

When we increment a pointer , its value is increased by the length of the data type that it points to .this length is called SCALE FACTOR .[i,e.ptr = ptr + 1 or ptr++].The no of bytes used to stored various data types can be found by making use of "SIZE OF" operator . For example , if X is a variable , the size of (X) returns the number of bytes needed for the variable.

SOME C DEFINITION

1.POINTER VALUE : It is the variable address the pointer contains and the VALUE THE POINTER to is the content of that variable whose address stored in the pointer .The "&" operator can be remembered as ADDRESS OF and the indirection operator "*" can be remembered as VALUE AT ADDRESS .We use "%u" format for printing Address values as Memory address are Unsigned Integers.