As far as I know is that when I declare an integer type of variable in c++, 4 bytes of memory is allocated by OS (windows).
For testing, I have declared two int type variables (a and b) in main function and compared their memory addresses. I found out that gap between two variable's addresses were 12 bytes. (I was expecting 4 bytes of difference)
below is an simple testing code.
int main()
{
int a;
int b;
std::cout << &a << std::endl;
std::cout << &b << std::endl;
return 0;
}
Output: 007BFDF4 007BFDE8
as shown, gap between two addresses are 12. (I got expected memory addresses when I used arrays) Is this because of byte padding? or any other reason?
ps. I tested this on visual studio 2019 / windows 10.