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

4번째 줄: 4번째 줄:


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

2017년 5월 14일 (일) 00:48 판

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++

#include <iostream>
using namespace std;

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

4 참고 자료

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