C和C++中未定义,未指定和实现定义的行为有什么区别?
c c++ undefined-behavior unspecified-behavior implementation-defined-behavior
为什么会出现在当代码使用两个编译器编译产生的输出的差值gcc和turbo c.
#include <stdio.h>
int main()
{
char *p = "I am a string";
char *q = "I am a string";
if(p==q)
{
printf("Optimized");
}
else{
printf("Change your compiler");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到"Optimized"的gcc和"Change your compiler"上turbo c.为什么?
你能解释的家伙我溢出和下溢如何工作的signed char,并unsigned char?
int main () {
signed char c;
scanf("%d",&c);
printf("%d\n",c);
printf("%c\n",c);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,如果谢谢scanf,我说c=200有一个溢出,这是由第一个显示printf.
第二个printf给我相同的ASCII符号200 ...
为什么?
用于打印char的十进制值的程序:
#include<stdio.h>
int main(void){
char ch = 'AB';
printf("ch is %d\n",ch);
}
Run Code Online (Sandbox Code Playgroud)
为什么打印第二个字符的十进制值,为什么不是第一个字符的十进制值?
输出: ch is 66
这个程序适用于输入: "problem"
但停下来: "this is the problem,this is the problem,this is the problem"
为什么?
#include <stdio.h>
int main()
{
char *p;
gets(p);
puts(p);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
有没有内存保护问题?
任何人都可以澄清一下吗?
char str[1];
strcpy(str, "HHHHHHHHHHHH");
Run Code Online (Sandbox Code Playgroud)
这里我声明了一个大小为1的char数组,但是程序不会崩溃,直到我输入超过12个字符而且我只有一个数组大小.为什么?
c ×6
c++ ×2
arrays ×1
char ×1
implementation-defined-behavior ×1
memory ×1
optimization ×1
pointers ×1
string ×1