c++ - 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
解决方案
编译器使用类型信息。它知道每种类型的字节大小,并将创建一个可执行文件,该可执行文件在运行时将正确访问每个变量的内存。
推荐阅读
- r - R中相关随机游走的边界限制
- ruby-on-rails - 如何在 Macbook 上测试 Windows Outlook App 的电子邮件设计?
- java - IllegalAnnotationExceptions:XmlIDREF 属性引用了没有 XmlID 属性的类型“java.lang.String”
- javascript - 在页面加载之前运行模块脚本?
- reactjs - 使用 Jest 模拟 React 组件时出现 TypeScript 错误 TS2339
- python - 全新安装后 conda update --all 失败 (Anaconda3-2020.11-Linux-x86_64)
- mongodb - 为什么 MongoDB 的 db.getRoles 返回空?
- c++ - 如何计算元素的执行排列并在c ++中显示Quicksort的排序过程?
- c - XC16 编译器局部变量赋值不起作用
- c++ - c++:强制将 std::string 强制转换为 string_view 而不是模板