int main(int argc, char** argv) {
int i=5;
{
int i=7;
printf("%d\n", i);
}
return 0;
}
If I want to access outer i (int i=5) value in printf then how it can done?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The relevant part of the C99 standard, section 6.2.1 (Scopes of identifiers):
Update
To prevent pmg’s answer from disappearing: You can access the outer block variable by declaring a pointer to it before the hiding occurs:
Of course giving hiding variables like this is never needed and always bad style.