Showing posts with label Pointer. Show all posts
Showing posts with label Pointer. Show all posts

Friday, August 17, 2012

Pointer In C (In Depth) (Final) Part 4

Generic Pointer in C Programming

Generic pointer:
void pointer in c is known as generic pointer. Literal meaning of generic pointer is a pointer which can point type of data.

Example:

void *ptr;

Here ptr is generic pointer.

Thursday, August 16, 2012

Pointer in C (In Depth) Part 3


Pointer to function in c programming

What will be output if you will execute following code?
int * function();
void main(){
auto int *x;
int *(*ptr)();
ptr=&function;
x=(*ptr)();
printf("%d",*x);
}
int *function(){
static int a=10;
return &a;
}
Output: 10
Explanation: Here function is function whose parameter is void data type and return type is pointer to int data type.
x=(*ptr)()
=> x=(*&functyion)() //ptr=&function
=> x=function() //From rule *&p=p
=> x=&a
So, *x = *&a = a =10


Pointer in C (In Depth) Part 2


Arithmetic Operation with Pointer in C Programming


Rule 1:

Address + Number= Address
Address - Number= Address
Address++ = Address
Address-- = Address
++Address = Address
--Address = Address

Monday, August 13, 2012

Pointer In C (In Depth) Part 1



POINTER

Pointer is a variable just like other variables of c but only difference is unlike the other variable it stores the memory address of any other variables of c. This variable may be type of int, char, array, structure, function or any other pointers. 

For examples:

(1) Pointer p which is storing memory address of a int type variable:
int i=50;
int *p=&i;

(2) Pointer p which is storing memory address of an array:

int arr[20];
int (*p)[20]=&arr;