在Visual Studio中,我们都有"baadf00d",在运行时在C++中检查调试器中的变量时看到过"CC"和"CD".
根据我的理解,"CC"仅处于DEBUG模式,以指示内存何时是new()或alloc()并且是单元化的."CD"代表删除或免费内存.我在RELEASE版本中只看过"baadf00d"(但我可能错了).
偶尔会遇到内存泄漏,缓冲区溢出等问题,这些信息会派上用场.
是否有人能够指出何时以何种模式将内存设置为可识别的字节模式以进行调试?
我只是在读书
ISO/IEC 9899:201x委员会草案 - 2011年4月12日
我在5.1.2.2.3程序终止下找到了
..reaching the } that terminates the main function returns a value of 0.
Run Code Online (Sandbox Code Playgroud)
这意味着如果你没有指定任何return语句main(),并且如果程序成功运行,那么在main的右括号中将返回0.
但是在下面的代码中我没有指定任何return语句,但它不返回0
#include<stdio.h>
int sum(int a,int b)
{
return (a + b);
}
int main()
{
int a=10;
int b=5;
int ans;
ans=sum(a,b);
printf("sum is %d",ans);
}
Run Code Online (Sandbox Code Playgroud)
编
gcc test.c
./a.out
sum is 15
echo $?
9 // here it should be 0 but it shows 9 why?
Run Code Online (Sandbox Code Playgroud) 有没有办法从c ++中的main函数返回字符串?我提到下面的示例程序
string main(int argv, char* argc[])
{
.
.
return "sucess";
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试做一些简单的事情,如打印字符串的反向.示例:
Hello World! This is me
Run Code Online (Sandbox Code Playgroud)
需要的O/P:
me is This World! Hello
Run Code Online (Sandbox Code Playgroud)
我的代码是这样的:
#include<stdio.h>
#include<string.h>
int main(){
char *arr[20] ;
int i,j;
int size;
char *revarr[20];
printf(" enter the number of words\n");
scanf("%d",&size);
for(i=0;i<size;i++)
scanf("%s",&arr[i]);
for(i=0;i<size;i++)
{
printf("%s\n",&arr[size-1-i]); //overwritten words
revarr[i]=arr[size-1-i];
}
printf(" the reversed sentence is %s\n",(char *)revarr);
}
Run Code Online (Sandbox Code Playgroud)
我除了arr [0],arr [1]等是单独的实体,但在打印和存储它们时它们似乎重叠如下:i/p:
Hello World
Run Code Online (Sandbox Code Playgroud)
O/P:
World
HellWorld
the reversed sentence is WorlHell@#$
Run Code Online (Sandbox Code Playgroud)
我似乎无法弄清楚出了什么问题!提前致谢!
编辑: 打印时
printf(&arr[0]);
printf(&arr[1]);
Run Code Online (Sandbox Code Playgroud)
我明白了:
HellWorld
World
Run Code Online (Sandbox Code Playgroud)
我期望它打印的是
Hello
World
Run Code Online (Sandbox Code Playgroud) 我试图模仿strtok功能,但得到分段错误.请帮帮我.
这是我的代码:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char argv[])
{
int i=0;
char c[]="get the hell out of here";
char *p;
char *temp=(char *)malloc(100);
while(c[i]!='\0')
{
if(c[i]!=' ')
{
*temp=c[i];
temp++;
i++;
}
else
{
*temp='\0';
printf("printing tokenn");
puts(temp);
i++;
temp="";
}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)