EmbLogic's Blog

Pointers.

#include<stdio.h>
#include<stdlib.h>

int main()
{
void *ptr;

char i;

ptr = malloc(sizeof(int ) * 5);

for(i = 0; i<(sizeof(int) * 5); i++)
{
*(int *)(ptr + i) = i;
printf(” ptr + %d = %p\t %d\n”, i, (ptr + i – 1), *(int *)(ptr + i – 1));
}
return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>