How to get the address of an array element through a structure pointer?
I have a sample code as follows:
#include<stdio.h> #include<string.h> typedef struct { int mynam ; } transrules; typedef struct { int ip ; int udp; transrules rules[256]; }__attribute__ ((__packed__)) myudp; myudp udpdata ; myudp* ptrudp = &udpdata ; int main(){ memset (&udpdata , 0 ,sizeof(udpdata)); ptrudp->ip = 12 ; ptrudp->udp = 13 ; ptrudp->rules[0].mynam = 15 ; printf("%d",ptrudp->rules[0].mynam); return 0; }
My function wants the address of the rules [0] to be passed as an argument. Is it possible to print the address of rule [0] or, in fact, any rule [n]?
source share