"C언어 문자 리터럴 사이즈"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(사용자 3명의 중간 판 6개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==개념==
==개념==
;문자 리터럴 사이즈
;문자 리터럴 사이즈
* 'a' 문자 리터럴 사이즈 확인
* 'a' 문자를 통한 리터럴 사이즈 확인


==C==
==C==
* C언어에서는 문자 리터럴이 int와 동일하게 4바이트임
* C언어에서는 문자 리터럴이 int와 동일하게 4바이트임
<source lang='C'>
<syntaxhighlight lang='C'>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
16번째 줄: 16번째 줄:
   return 0;
   return 0;
}
}
</source>
</syntaxhighlight>


==C++==
==C++==
* C++에서는 문자 리터럴이 char와 동일하게 1바이트임
* C++에서는 문자 리터럴이 char와 동일하게 1바이트임
<source lang='C'>
<syntaxhighlight lang='C'>
#include <iostream>
#include <iostream>
using namespace std;
using namespace std;


29번째 줄: 30번째 줄:
     cout << sizeof(char) << endl; // 1
     cout << sizeof(char) << endl; // 1
}
}
</source>
</syntaxhighlight>
 
==같이 보기==
* [[리터럴]]
* [[C언어 강좌]]
* [[C언어 sizeof()]]


==참고 자료==
==참고==
* http://david.tribble.com/text/cdiffs.htm#C99-char-literal
* http://david.tribble.com/text/cdiffs.htm#C99-char-literal


[[분류:C]]
[[분류:C]]

2020년 11월 2일 (월) 02:40 기준 최신판

1 개념[ | ]

문자 리터럴 사이즈
  • 'a' 문자를 통한 리터럴 사이즈 확인

2 C[ | ]

  • C언어에서는 문자 리터럴이 int와 동일하게 4바이트임
#include <stdio.h>
#include <string.h>

int main()
{
    printf("%lu\n", sizeof('a')); // 4
    printf("%lu\n", sizeof(int)); // 4

   return 0;
}

3 C++[ | ]

  • C++에서는 문자 리터럴이 char와 동일하게 1바이트임
#include <iostream>

using namespace std;

int main()
{
    cout << sizeof('a') << endl; // 1
    cout << sizeof(char) << endl; // 1
}

4 같이 보기[ | ]

5 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}