C static array pointer address -


we have code.

#include <stdio.h>  int* aa(int s){     static int ad[2] = {0};     ad[0] = s;     printf("aa() -> %p\n", &ad);     return ad; }  int main(void) {     int *k = aa(3);     printf("main() -> %p\n", &k);     return 0; } 

compile, run.. output

aa() -> 0x80497d0 main() -> 0xbfbe3e0c 

or misunderstood or code have problems.

we returning same address static array ad why on output differ?

in main you're printing address of k pointer variable, not address of array points to. if do:

printf("main() => %p\n", k); 

you'll same address printed in aa.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -