Posted by: Sourav | November 20, 2014

An interesting pointer example in C


#include <stdio.h>
#include <stdlib.h>
int integers(int listsize,int **list)
{
int i;
*list=(int *)malloc(listsize*sizeof(int));
if (*list == NULL)
return(0);
for (i=0; i<listsize; i++)
(*list)[i]=10+i; /* mixed array/pointer syntax */
return(1);
}
int main(int argc, char *argv[])
{
int *numbers;
int i;
i=integers(3,&numbers);
for (i=0; i<3; i++)
printf(“%d\n”,numbers[i]);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: