Author Topic: & and * pointers  (Read 949 times)

thrushitha

  • Full Member
  • ***
  • Posts: 26
& and * pointers
« on: July 11, 2011, 03:52:31 am »
what is happening in below piece of code, where both pointers are used.

#define GFAST   /*NOTHING*/
GVP GFAST *gcurvp;
gcurvp = &gdata.viewports[ vp ];



THANX IN ADVANCE :) 

administrator

  • Administrator
  • Full Member
  • *****
  • Posts: 69
Re: & and * pointers
« Reply #1 on: July 11, 2011, 05:54:28 am »
what is happening in below piece of code, where both pointers are used.

#define GFAST   /*NOTHING*/
GVP GFAST *gcurvp;
gcurvp = &gdata.viewports[ vp ];

THANX IN ADVANCE :)

You have given the partial code. However with the given information, I will try to explain.

gdata is a struct GDATA and has member variable like "GVP viewports[100];"

struct _GDATA {
    GVP viewports[100];
} GDATA;

GDATA gdata;
GVP *gcurvp;
int vp = 0; // 0 based index
gcurvp = &gdata.viewports[ vp ];

gcurvp is a pointer pointing to the address of viewports[0] in the struct gdata;


It is something like below:

int m = 20;
int *p = &m;
*p = 10;
printf("%d", m); // will display 10

thrushitha

  • Full Member
  • ***
  • Posts: 26
Re: & and * pointers
« Reply #2 on: July 12, 2011, 12:35:29 am »
thank u  :D

 


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1