All about programming in GNU/LINUX

Simple exercise on Incrementing Pointer to an structure ….

#include<stdio.h>
#include<stdlib.h>
typedef struct
{
    int j;
    int m;

}kar;
kar *ptr;
kar *ttr;
int main()
{
    int i;
    printf("%lu\n",sizeof(kar));
    ptr=malloc(16);
    ttr=ptr;
        for(i=0;i<4;i++)
    {
        (ptr->j)=i+1;
        ptr++;
    }
    ptr=ptr-4;
    for(i=0;i<4;i++)
    {

       printf("%d\n",ptr->j);
       ptr++;
    }
}
Advertisements

One response

  1. can you give the comments on each line of code so that it will help better understanding for the readers? sort of a documentation..

    November 2, 2011 at 3:18 pm

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