c - Pointers, structure, passing arguments, recursion -



c - Pointers, structure, passing arguments, recursion -

i have code this:

typedef struct _statistics { code here } statistics; void function1(char *string, statistics *statistic){ code here function1(string1, statistic); } int main(){ statistics statistic; function1(string, &statistic); }

this idiotic question, don't understand pointers completely: understand why utilize & in main function, & send address of variable statistic, in function1 can modify it. why don't utilize & in recursive function1?

sometimes helps write way:

void function1(char* string, statistics* statistic){

the variable statistic pointer statistics, not statistics itself. if did in function1:

function1(string1, &statistic);

you passing pointer (because of &) pointer (because of * in declaration) statistics, incorrect.

your declaration of statistic in main statistic adds confusion: you're using same variable name different types in 2 scopes.

with different variable names it's clearer:

typedef struct _statistics { code here } statistics; void function1(char* string, statistics* ptrstat){ code here function1(string1, ptrstat); } int main(){ statistics statistic; function1(string, &statistic); }

c pointers recursion struct argument-passing

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -