{"id":4770,"date":"2022-02-23T11:18:47","date_gmt":"2022-02-23T02:18:47","guid":{"rendered":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=4770"},"modified":"2025-11-14T16:42:48","modified_gmt":"2025-11-14T07:42:48","slug":"c-printf","status":"publish","type":"post","link":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=4770","title":{"rendered":"C &#8211; printf"},"content":{"rendered":"<h1>C &#8211; printf<\/h1>\n<h2>Hello, World!<\/h2>\n<pre><code class=\"language-c\">#include &lt;stdio.h&gt;\n\nint main() {\n    printf(&quot;Hello, World!\\n&quot;);\n}<\/code><\/pre>\n<h2>\uae30\ubcf8\ud615 \ucd9c\ub825 (int, char *, char)<\/h2>\n<p><code>%d<\/code> \uc640 <code>%i<\/code> \ub294 \ub3d9\uc77c\ud558\uac8c \uc791\ub3d9\ud55c\ub2e4.<br \/>\n<code>%c<\/code> \uc640 <code>%C<\/code> \ub294 \ub3d9\uc77c\ud558\uac8c \uc791\ub3d9\ud55c\ub2e4.<\/p>\n<pre><code class=\"language-c\">#include &lt;stdio.h&gt;\n\nint main() {\n    int i = 20;\n    char s[] = &quot;Hello, World!&quot;;\n    char a = &#039;A&#039;;\n    printf(&quot;int : %d, char * : %s, char : %c\\n&quot;, i, s, a);\n}<\/code><\/pre>\n<h2>\uc22b\uc790 \ucd9c\ub825 (unsigned int, float, double)<\/h2>\n<p><code>%x<\/code> \uc640 <code>%X<\/code> \ub294 \ub3d9\uc77c\ud558\uac8c \uc791\ub3d9\ud55c\ub2e4.<\/p>\n<pre><code class=\"language-c\">int main() {\n    unsigned int u = 20;\n    printf(&quot;unsigned int : %u, int(16\uc9c4\uc218) : %x, int(8\uc9c4\uc218) : %o\\n&quot;, u, u, u);\n}<\/code><\/pre>\n<p>0.2 \ub97c \ubd99\uc5ec\uc11c \uc18c\uc218\uc810 \uc544\ub798 2\uc790\ub9ac\uae4c\uc9c0\ub9cc \ud45c\uc2dc\ud558\ub3c4\ub85d \ud560 \uc218 \uc788\ub2e4.<\/p>\n<pre><code class=\"language-c\">int main() {\n    float f = 3.14159265;\n    double d = 3.14159265;\n    printf(&quot;float : %0.2f, double : %0.4f\\n&quot;, f, d);\n}<\/code><\/pre>\n<h2>\uc22b\uc790\ucd9c\ub825 (long, long int, long long int)<\/h2>\n<p><code>long<\/code> \uc740 <code>long int<\/code> \uc640 \uac19\uc740 \uc758\ubbf8\uc774\ub2e4.(int \ub294 \uc0dd\ub7b5 \uac00\ub2a5)<\/p>\n<pre><code class=\"language-c\">int main() {\n    long ld = 100;\n    long long int lld = 1000;\n    printf(&quot;long int : %ld, long long int : %lld\\n&quot;, ld, lld);\n}<\/code><\/pre>\n<h2>32\ube44\ud2b8 \uc22b\uc790\ucd9c\ub825(uint32_t)<\/h2>\n<pre><code class=\"language-c\">#include &lt;inttypes.h&gt;\nuint32_t k = 0;\nprintf(&quot;k [ %&quot;PRIu32&quot; ]\\n&quot;, k);<\/code><\/pre>\n<p>\ud558\uc9c0\ub9cc \uc544\ub798\ucc98\ub7fc \uc791\uc131\ud558\ub294 \uac83\uc774 \ub354 \uae54\ub054\ud574 \ubcf4\uc778\ub2e4.<\/p>\n<pre><code class=\"language-c\">printf( &quot;%lu&quot;, (unsigned long ) k);<\/code><\/pre>\n<p>g++ \ub864 \ucef4\ud30c\uc77c\ud558\ub294 \uacbd\uc6b0 <code>%u<\/code> \ub97c \uc0ac\uc6a9\ud560 \uc218 \uc788\ub2e4.<\/p>\n<pre><code class=\"language-cpp\">printf( &quot;%u&quot;, k);<\/code><\/pre>\n<h2>64\ube44\ud2b8 \uc22b\uc790\ucd9c\ub825(int64_t, uint64_t)<\/h2>\n<pre><code class=\"language-c\">int main() {\n    int64_t lld = 100;\n    uint64_t llu = 1000;\n    printf(&quot;int64_t : %lld, uint64_t : %llu\\n&quot;, lld, llu);\n    \/\/ OS \uc5d0 \ub530\ub77c %lu \uac00 \ub418\uae30\ub3c4 \ud568\n    \/\/ printf(&quot;int64_t : %lld, uint64_t : %lu\\n&quot;, lld, llu);\n}<\/code><\/pre>\n<h2>pointer \ucd9c\ub825<\/h2>\n<p>\ud3ec\uc778\ud130\ub294 16\uc9c4\uc218\ub85c \ud45c\uc2dc\ub41c\ub2e4.<\/p>\n<pre><code class=\"language-c\">int main() {\n    char s[] = &quot;Hello, World!&quot;;\n    printf(&quot;pointer : %p\\n&quot;, s);\n}<\/code><\/pre>\n<h2>size_t \ucd9c\ub825<\/h2>\n<p><code>z<\/code> \ub97c \uc0ac\uc6a9\ud55c\ub2e4.<\/p>\n<pre><code class=\"language-c\">int main() {\n    int i = 100;\n    printf(&quot;unsigned int : %zu, 16\uc9c4\uc218 : %zx, signed int : %zd\\n&quot;, sizeof(i), sizeof(i), sizeof(i));\n}<\/code><\/pre>\n<h2>16\uc9c4\uc218, 8\uc9c4\uc218, 2\uc9c4\uc218 \ucd9c\ub825<\/h2>\n<p><code>%o, %x<\/code> \ud615\uc2dd\uc73c\ub85c 8\uc9c4\uc218\/16\uc9c4\uc218\ub97c \ud45c\uc2dc\ud569\ub2c8\ub2e4.<br \/>\n<code>%#o, %#X<\/code> \uc640 \uac19\uc774 \uc9c0\uc815\ud558\uba74 \uc9c4\uc218\ud615\uc2dd\uc774 \ud3ec\ud568\ub418\uc5b4 \ud45c\uc2dc\ub429\ub2c8\ub2e4.<\/p>\n<p>\uc774\uc9c4\uc218\ub294 0x80000000 (\uc774\uc9c4\uc218\ub85c\ub294 1000 0000 0000 0000 0000 0000 0000 0000) \uc640 \ubcc0\ud658\ud558\ub824\ub294 \uac12\uc744 and \uc5f0\uc0b0\uc744 \uc218\ud589\ud558\uba74\uc11c \uac12\uc774 \uc788\ub294 \uc790\ub9ac\uc218\uc5d0 1 \uc744 \ud45c\uc2dc\ud558\ub294 \ubc29\uc2dd\uc73c\ub85c \uc774\uc9c4\uc218\ub97c \ucd9c\ub825\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<pre><code class=\"language-c\">#include &lt;stdio.h&gt;\n\n\/\/ 10\uc9c4\uc218 -&gt; 2\uc9c4\uc218 \ubcc0\ud658 (\ubc18\ubcf5\uc801 \ubc84\uc804: \ube44\ud2b8)\nvoid ten_to_two(unsigned n) {\n    unsigned a = 0x80000000; \/\/ 1000 0000 0000 0000 0000 0000 0000 0000(2) &lt;\uc57d 21\uc5b5&gt;\n    for (int i = 0; i &lt; 32; i++) {\n        if ((a &amp; n) == a)\n            printf(&quot;1&quot;);\n        else\n            printf(&quot;0&quot;);\n        a &gt;&gt;= 1;\n    }\n}\n\nint main() {\n    int i = 10;\n    \/\/ 10, 12, a, 012, 0XA\n    printf(&quot;%d, %o, %x, %#o, %#X\\n&quot;, i, i, i, i, i);\n    \/\/ 00000000000000000000000100000000\n    ten_to_two(256);\n    return 0;\n}<\/code><\/pre>\n<h2>\uae30\ud0c0 \ud3ec\ub9e4\ud305<\/h2>\n<pre><code class=\"language-c\">int main() {\n    int i = 100;\n    float f = 3.14159265;\n\n    printf(&quot;[%8d]\\n&quot;, i);    \/\/ 8\uce78 \uac04\uaca9\uc548\uc5d0 \uc22b\uc790\ud45c\uc2dc(\uc624\ub978\ucabd \uc815\ub82c)\n    printf(&quot;[%-8d]\\n&quot;, i);   \/\/ 8\uce78 \uac04\uaca9\uc548\uc5d0 \uc22b\uc790\ud45c\uc2dc(\uc67c\ucabd \uc815\ub82c)\n    printf(&quot;%.5f\\n&quot;, f);     \/\/ \uc18c\uc218\uc810 \uc544\ub798 5\uc790\ub9ac\uae4c\uc9c0 \ud45c\uc2dc\n    printf(&quot;%+d\\n&quot;, i);      \/\/ \ud50c\ub7ec\uc2a4\/\ub9c8\uc774\ub108\uc2a4 \ud45c\uc2dc\n    printf(&quot;[%08d]\\n&quot;, i);   \/\/ \uc81c\ub85c \ud328\ub529\n}<\/code><\/pre>\n<pre><code class=\"language-bash\">[     100]\n[100     ]\n3.14159\n+100\n[00000100]<\/code><\/pre>\n<h2>\uc815\ub82c<\/h2>\n<h3>\uc624\ub978\ucabd \uc815\ub82c<\/h3>\n<pre><code class=\"language-c\">int main() {\n    int i = 0;\n    printf(&quot;%4d\\n&quot;, i + 50);\n    printf(&quot;%4d\\n&quot;, i + 1000);\n    printf(&quot;%4d\\n&quot;, i + 150);\n}<\/code><\/pre>\n<h3>\uc67c\ucabd \uc815\ub82c<\/h3>\n<pre><code class=\"language-c\">int main() {\n    int i = 0;\n    printf(&quot;%-4d\\n&quot;, i + 50);\n    printf(&quot;%-4d\\n&quot;, i + 1000);\n    printf(&quot;%-4d\\n&quot;, i + 150);\n}<\/code><\/pre>\n<h2>\ud2b9\uc218\ubb38\uc790<\/h2>\n<table>\n<thead>\n<tr>\n<th>\ud2b9\uc218\ubb38\uc790<\/th>\n<th>\ud45c\uc2dc<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>backslash<\/td>\n<td><code>\\\\<\/code><\/td>\n<\/tr>\n<tr>\n<td>double quote<\/td>\n<td><code>\\&quot;<\/code><\/td>\n<\/tr>\n<tr>\n<td>tab<\/td>\n<td><code>\\t<\/code><\/td>\n<\/tr>\n<tr>\n<td>newline<\/td>\n<td><code>\\n<\/code><\/td>\n<\/tr>\n<tr>\n<td>single quote<\/td>\n<td><code>\\&#039;<\/code><\/td>\n<\/tr>\n<tr>\n<td>question mark<\/td>\n<td><code>\\?<\/code><\/td>\n<\/tr>\n<tr>\n<td>%<\/td>\n<td><code>%%<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>C &#8211; printf Hello, World! #include &lt;stdio.h&gt; int main() { printf(&quot;Hello, World!\\n&quot;); } \uae30\ubcf8\ud615 \ucd9c\ub825 (int, char *, char) %d \uc640 %i \ub294 \ub3d9\uc77c\ud558\uac8c \uc791\ub3d9\ud55c\ub2e4. %c \uc640 %C \ub294 \ub3d9\uc77c\ud558\uac8c \uc791\ub3d9\ud55c\ub2e4. #include &lt;stdio.h&gt; int main() { int i = 20; char s[] = &quot;Hello, World!&quot;; char a = &#039;A&#039;; printf(&quot;int : %d, char * :\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=4770\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-4770","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/4770","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4770"}],"version-history":[{"count":14,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/4770\/revisions"}],"predecessor-version":[{"id":11093,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/4770\/revisions\/11093"}],"wp:attachment":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}