1.main()
2.{
3. int a=0;
4. while(...)
5. {
6. int a=9;
7. }
8.}

now friendz question is
question is what make a of 3 global and a of line 6 local what is happend at the time of local decla.. and at the time of global decl...

would u plz help me to understand this...

1.main()
2.{
3. int a=0;
4. while(...)
5. {
6. int a=9;
7. }
8.}

now friendz question is
question is what make a of 3 global and a of line 6 local what is happend at the time of local decla.. and at the time of global decl...

would u plz help me to understand this...

hi there,
i don't know if i understood your question...
if you want to know how those variables are stored in memory
well, in my opinion, none of them are global. the one declared in line 3 is local to main function, and resides on the respective stack, and the one declared in the while loop, should be put in a register, because it is accessed very often, and the compiler can see this.

1.main()
2.{
3. int a=0;
4. while(...)
5. {
6. int a=9;
7. }
8.}

now friendz question is
question is what make a of 3 global and a of line 6 local what is happend at the time of local decla.. and at the time of global decl...

would u plz help me to understand this...

i think a in 3rd line is not global its local to the main function and if you change the value of a in the 6th line or ne where inside the program it will display the new value...

i think a in 3rd line is not global its local to the main function and if you change the value of a in the 6th line or ne where inside the program it will display the new value...

ABSOLUTELY WRONG !!!

a on line 3 is local to main(), while the scope of a in line 6 is limited to the while loop. Inside the while loop, the most local variable is given preference. And if you change a inside the while loop, the value of a on line 3 will remain unaffected. Try it out by using printf statements in between.

but the updation is done in the while loop and so the value of a will be the new value even if we print the value after the termination of the loop.......:-/

This article has been dead for over six months. Start a new discussion instead.