Thursday, July 19, 2012

C concepts


A pointer is a special kind of variable. Pointers are designed for storing memory address i.e. the address of another variable. Declaring a pointer is the same as declaring a normal variable except you stick an asterisk '*' in front of the variables identifier.
·         There are two new operators you will need to know to work with pointers. The "address of" operator '&' and the "dereferencing" operator '*'. Both are prefix unary operators.
·         When you place an ampersand in front of a variable you will get it's address, this can be stored in a pointer vairable.
·         When you place an asterisk in front of a pointer you will get the value at the memory address pointed to.

Arrays

For every type T, except void and function types, there exist the types “array of N elements of type T”.
An array is a collection of values, all of the same type, stored contiguously in memory. An array of size N is indexed by integers from 0 up to and including N-1.
For example:
int cat[10];
Arrays can be initialized with a compound initializer, but not assigned. Arrays are passed to functions by passing a pointer to the first element.

Pointer types

For every type T there exists a type “pointer to T”.
Variables can be declared as being pointers to values of various types, by means of the * type declarator. To declare a variable as a pointer, precede its name with an asterisk.
char *square;
long *circle;

No comments:

Post a Comment

About ShankarChinn

My photo
Bangalor, karnataka, India
I created this Blog to store knowledge and help other with the same. URL:http://shankarchinn.blogspot.in/ By : Shankar Nath.Chokkam