什么是char s ='2'和char s ='\ 2'之间的区别? [英] Whats the difference between char s='2' and char s= '\2' ?
问题描述
我找到了字符的ascii值。
char s ='2'和char s ='\ 2'之间的区别是什么?
Ascii Value char ='2'。输出= 50.
Ascii char的值='\ '2'。输出= 2.
什么是\的重要性?
我尝试了什么: < br $>
char s ='\''';
char v ='2';
cout< < int(v)<< endl;
cout<< int(s)<< endl;
返回0;
I am finding the ascii value for characters.
whats the difference between char s='2' and char s= '\2' ?
Ascii Value of char = '2'. Output = 50.
Ascii Value of char = '\2'. Output = 2.
Whats the significance of "\" ?
What I have tried:
char s = '\2';
char v = '2';
cout << int(v) << endl;
cout << int(s) << endl;
return 0;
推荐答案
怎么样'文档':转义序列 - cppreference.com [ ^ ]?
区别在于第一行中的引用值是对ASCII值的引用2,而第二个引用值是对字符'2'的ASCII代码的引用。
看看这个页面
注意任意八进制值
的格式是\ nnn
- 这是您在
The difference is that the quoted value in the first line is a reference to the ASCII value 2 while the second quoted value is a reference to the ASCII code for the character '2'.
Take a look at this page
Note that the format forarbitrary octal value
is\nnn
- this is format you are using in
char s = '\2';
这意味着你将八进制值2(或002)赋给变量s。
在第二行中,您指定ASCII字符'2'(八进制值) 062,十进制50)到变量v。
我希望有所帮助。
This means that you are assigning the octal value 2 (or 002) to the variable s.
In the second line you are assigning the ASCII character '2' (octal value 062, decimal 50) to the variable v.
I hope that helps.
这篇关于什么是char s ='2'和char s ='\ 2'之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!