我想知道为什么 int 的大小取决于 C 和 C++ 中使用的操作系统。如果指针的大小不同是可以的,但是为什么整数的大小不同呢?如果 16 位操作系统 sizeof(int) = 2 字节,则对于 32 位操作系统 sizeof(int) = 4 字节。为什么这样?
谢谢。
我有简单的代码,
#include "stdafx.h"
#include <malloc.h>
int main()
{
char *p = (char*) malloc(10);
p = "Hello";
free(p);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
此代码在终止时给出运行时异常.以下是错误最快的,
调试断言失败!
程序:...\my documents\visual studio 2010\Projects\samC\Debug\samC.exe文件:f:\ dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c行:1322
表达式:_CrtIsValidHeapPointer(pUserData)
有关程序如何导致断言失败的信息,请参阅有关断言的Visual C++文档.
我是Linux环境的新手,我刚开始使用gcc.我们有一个小项目,有7到8个cpp文件.当我尝试编译我的文件时,我想知道为什么每个.cpp文件都有.o文件.只有一个主要的.