Here is my code , I want to print 15 and 12 but due to instance member hiding the local value of a is getting printed twice.
#include <stdio.h>
int a = 12;
int main()
{
int a = 15;
printf("Inside a's main local a = : %d\n",a);
printf("In a global a = %d\n",a);
return 0;
}
Why and is there any way to print it in c ? ... BTW I know it in c++.
Use the extern
specifier in a new compound statement.
This way:
#include <stdio.h>
int a = 12;
int main(void)
{
int a = 15;
printf("Inside a's main local a = : %d\n", a);
{
extern int a;
printf("In a global a = %d\n", a);
}
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With