S
Shadyabhi
#include<iostream>
using namespace std;
int main()
{
for (int i=0;i<1;i++)
{
cout<<i;
int i=7;
cout<<i;
}
return 0;
}
The above code gives output: 07
How come is the output that? When i run this program through GDB, i
found out that both these variables have same address.
TERMINAL OUTPUT WHILE USING GDB:
(gdb) break 8
Breakpoint 1 at 0x40093e: file test.cpp, line 8.
(gdb) break 9
Breakpoint 2 at 0x400945: file test.cpp, line 9.
(gdb) r
Starting program: /home/codefire/prgs/a.out
Breakpoint 1, main () at test.cpp:8
8 int i=7;
(gdb) p i
$1 = 0
(gdb) p &i
$2 = (int *) 0x7fff3323d628
(gdb) n
Breakpoint 2, main () at test.cpp:9
9 cout<<i;
(gdb) p i
$3 = 7
(gdb) p &i
$4 = (int *) 0x7fff3323d628
(gdb)
As far as i can say, it should have been error of redeclaration of i.
Please let me know of whats happening.
using namespace std;
int main()
{
for (int i=0;i<1;i++)
{
cout<<i;
int i=7;
cout<<i;
}
return 0;
}
The above code gives output: 07
How come is the output that? When i run this program through GDB, i
found out that both these variables have same address.
TERMINAL OUTPUT WHILE USING GDB:
(gdb) break 8
Breakpoint 1 at 0x40093e: file test.cpp, line 8.
(gdb) break 9
Breakpoint 2 at 0x400945: file test.cpp, line 9.
(gdb) r
Starting program: /home/codefire/prgs/a.out
Breakpoint 1, main () at test.cpp:8
8 int i=7;
(gdb) p i
$1 = 0
(gdb) p &i
$2 = (int *) 0x7fff3323d628
(gdb) n
Breakpoint 2, main () at test.cpp:9
9 cout<<i;
(gdb) p i
$3 = 7
(gdb) p &i
$4 = (int *) 0x7fff3323d628
(gdb)
As far as i can say, it should have been error of redeclaration of i.
Please let me know of whats happening.