首页 > 解决方案 > C++ Question about memory pretty basic but this is confusing me

问题描述

Not really too c++ related I guess but say I have a signed int int a =50; This sets aside like 32 bits memory for this right it'll get some bit patternand a memory address, now my question is basically well we created this variable but the computer ITSELF doesn't know what the type is it just sees some bit pattern and memory address it doesn't know this is an int, but my question is how? Does the computer know that those 4 bytes are all connected to a? And also how does the computer not know the type? It set aside 4 bytes for one variable I get that that doesn't automatically make it an int but does the computer really know nothing? The value was 50 the number and that gets turned into binary and stored in the bit pattern how does the computer know nothing

标签: c++

解决方案


编译器使用类型信息。它知道每种类型的字节大小,并将创建一个可执行文件,该可执行文件在运行时将正确访问每个变量的内存。


推荐阅读