Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/694305e8-d7f8-800e-a8d8-fbf410be6545
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Assistant: いい質問。 === いい質問。 C言語では明確に区別されてるので、そこを押さえると混乱しない。 ==== - <code>'\'</code> → そもそも書けない(エラー) ==== * <code>'\\'</code> → 1文字(<code>char</code>) * "\" → 文字列(<code>char[2]</code>:<code>\</code> + <code>\0</code>) ==== ### ==== * 型:int(実質 1文字) * バックスラッシュは エスケープ開始文字 ❌ ダメ <syntaxhighlight lang="c">'\' </syntaxhighlight> ⭕ 正解 <syntaxhighlight lang="c">'\\' // 1文字の「\」 </syntaxhighlight> ===== - 型:char[] ===== * 最後に '\0' が自動で付く <syntaxhighlight lang="c">"\" // ❌ エラー "\\" // ⭕ 「\」1文字の文字列 </syntaxhighlight> 中身は: <syntaxhighlight>[ '\\', '\0' ] </syntaxhighlight> ==== ### ==== → 違う C言語は: * 文法上 - \ = エスケープ開始 * 実体上 - \\ → 1文字の \ ==== <syntaxhighlight lang="c">char c = '\\'; // 1文字 ==== char* s = "\\"; // 文字列(長さ1) </syntaxhighlight> <syntaxhighlight lang="c">sizeof(c) // 通常 1 sizeof(s) // ポインタサイズ strlen(s) // 1 </syntaxhighlight> ==== <syntaxhighlight lang="c">"C:\\Windows\\System32" ==== </syntaxhighlight> 実体の中身は: <syntaxhighlight>C:\Windows\System32 </syntaxhighlight> ==== : ==== つまり: * 概念上:1文字 * 表記上:\\ が必要 * 文字列とは別物 この次は '' <code>char''</code> と <code>char[]</code> の違い * なぜ文字リテラルが <code>int</code> 型なのか * ワイド文字(L'\')はどうなるか どれ行く?
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)