Code
#include<iostream>
int main()
{
int a=3;
char ch[5];
std::cout<<&a<<"\n"<<(void*)(ch)<<"\n";
long int k1=strtol("0x70fe14",nullptr,16); // 7405076
long int k2=strtol("0x70fe00",nullptr,16); // 7405056
std::cout<<k1<<"\n"<<k2<<"\n";
std::cout<<a<<"\n";
std::cin>>ch;
std::cout<<a<<"\n";
std::cout<<ch<<"\n";
}
Output
0x70fe14
0x70fe00
7405076
7405056
3
12345678912345678912 // I entered this input for cin>>ch
0
12345678912345678912
I entered 20 characters for input cin>>ch
so they will acquire memory from 7405056-7405075
so why it is corrupting data of variable a
whose memory address start from 7405076
?