{"id":5435,"date":"2026-04-23T11:08:46","date_gmt":"2026-04-23T02:08:46","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=5435"},"modified":"2026-04-23T11:12:45","modified_gmt":"2026-04-23T02:12:45","slug":"basic-pointer-namespace-header","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2026\/04\/23\/basic-pointer-namespace-header\/","title":{"rendered":"[Basic]\ud3ec\uc778\ud130,\ub124\uc784\uc2a4\ud398\uc774\uc2a4,\ud5e4\ub354 \/Pointer,Namespace,Header"},"content":{"rendered":"\n<p>\ud83d\udc49\ud83c\udffb \ud3ec\uc778\ud130 \/ Pointer<\/p>\n\n\n\n<p>\u2714\ufe0f \ubcc0\uc218\uc758 \uc8fc\uc18c \uac12\uc744 \uc800\uc7a5\ud558\ub294 \ubcc0\uc218<br>A variable that stores the address value of a variable<\/p>\n\n\n\n<p>\u2714\ufe0f \uc8fc\uc18c\uc5f0\uc0b0\uc790(&amp;)\ub97c \uc0ac\uc6a9\ud558\uba74 \ubcc0\uc218\uc758 \uc8fc\uc18c\ub97c \uac00\uc838\uc62c \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br>You can get the address of a variable by using the address operator (&amp;).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>string* ptv = &amp;name;<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb\ub124\uc784\uc2a4\ud398\uc774\uc2a4 \/ namespace<\/p>\n\n\n\n<p>\u2714\ufe0f\uc5ec\ub7ec \ub77c\uc774\ube0c\ub7ec\ub9ac\ub098 \ubaa8\ub4c8\uc744 \ud568\uaed8 \uc0ac\uc6a9\ud560 \ub54c, \ud574\ub2f9 \uc774\ub984\ub4e4\uc744 \uadf8\ub8f9\ud654\ud558\uc5ec \uc11c\ub85c \uac04\uc12d\ud558\uc9c0 \uc54a\ub3c4\ub85d \uaca9\ub9ac\ud558\ub294 \uc5ed\ud560\uc744 \ud569\ub2c8\ub2e4.<br>When using multiple libraries or modules together, it serves to group their names and isolate them to prevent interference.<\/p>\n\n\n\n<p>\u2714\ufe0f cout\uc744 \uc0ac\uc6a9\ud558\ub294 \uacbd\uc6b0 \uc544\ub798\uc5d0\uc11c \ub450\uac00\uc9c0 \ud615\ud0dc\uc758 \ucf54\ub4dc\ub97c \ubcfc \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br>When using cout, you can see two forms of code below.<\/p>\n\n\n\n<p>\u2714\ufe0f usiing namespace std; \ub97c \uc0ac\uc6a9\ud558\uba74 &#8220;std::&#8221; \ub97c \uc0dd\ub7b5 \ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br>If you use namespace std; you can omit &#8220;std::&#8221;.<\/p>\n\n\n\n<p>&#8212; \uccab\ubc88\uc9f8 \/ first<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cout &lt;&lt; name &lt;&lt; \"\\n\";<\/code><\/pre>\n\n\n\n<p>&#8211;\ub450\ubc88\uc9f8 \/ second<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>std::cout &lt;&lt; \"ftest message\\n\" &lt;&lt; std::endl;<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb\ud5e4\ub354 \/ header<\/p>\n\n\n\n<p>\u2714\ufe0f \uc77c\ubc18\uc801\uc73c\ub85c \ud5e4\ub354\ud30c\uc77c(.h)\uc5d0\ub294 \ucc45\uc758 \ubaa9\ucc28\ucc98\ub7fc \uae30\ub2a5\uc5d0 \ub300\ud55c \ubaa9\ub85d\uc744 \uc815\uc758\ud569\ub2c8\ub2e4.<br>Generally, header files (.h) define a list of functions, much like a table of contents in a book.<\/p>\n\n\n\n<p>\u2714\ufe0f cpp\ud30c\uc77c\uc5d0 \uc2e4\uc9c8\uc801\uc740 \uae30\ub2a5\uc744 \uc815\uc758\ud569\ub2c8\ub2e4.<br>Define the actual functionality in the cpp file.<\/p>\n\n\n\n<p>\u2714\ufe0f \ud5e4\ub354\ud30c\uc77c\uc5d0 \uae30\ub2a5\uae4c\uc9c0 \uc815\uc758\ud560 \uc218 \uc788\uc9c0\ub9cc \ud2b9\ubcc4\ud55c \uacbd\uc6b0\uac00 \uc544\ub2c8\uba74 \uad8c\uc7a5\ub418\uc9c0 \uc54a\uc2b5\ub2c8\ub2e4.<br>You can define functions in header files, but this is not recommended unless there is a special case.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb\ucf54\ub4dc \/ Code<\/p>\n\n\n\n<p>\u2714\ufe0f header.h<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ if not define HEADER_H\n\/\/ -- \ub9cc\uc57d HEADER_H\uc2ec\ubcfc\uc774 \uc815\uc758\ub418\uc5b4 \uc788\uc9c0 \uc54a\uc73c\uba74\n\/\/    If the HEADER_H symbol is not defined\n\/\/ define HEADER_H\n\/\/ -- HEADER_H \uc2ec\ubcfc\uc744 \uc815\uc758\ud55c\ub2e4.\n\/\/    Defines the HEADER_H symbol.\n\/\/\n#ifndef HEADER_H\n#define HEADER_H\n\n\n\/\/ \ub124\uc784\uc2a4\ud398\uc774\uc2a4 \/ namespace\nnamespace my {\n\n    \/\/ -- \ud074\ub798\uc2a4\ub97c \uc0ac\uc6a9\ud560 \uacbd\uc6b0 -- \/\n    \/\/ -- When using classes -- \/\n    \/\/\n    \/\/ class Server {\n    \/\/     public:\n    \/\/     int add(int x, int y)\n    \/\/     {\n    \/\/         return x + y;\n    \/\/     }\n    \/\/ };\n\n\n    \/\/ -- \uba64\ubc84 \ud568\uc218\ub85c \uc0ac\uc6a9\ud560 \uacbd\uc6b0 -- \/\n    \/\/ -- When used as a member function -- \/\n    int add(int x, int y)\n    {\n        return x + y;\n    }\n\n}\n\n\/\/ \ud5e4\ub354 \uc0ac\uc6a9\uc5d0 \uad8c\uc7a5\ub418\uc9c0 \uc54a\uc740 \ubc29\uc2dd\n\/\/ Not recommended method for using headers\nvoid ftest(){\n    std::cout &lt;&lt; \"ftest message\\n\" &lt;&lt; std::endl;\n}\n\n\/\/ \ud5e4\ub354 \uc0ac\uc6a9\uc5d0 \uad8c\uc7a5\ub418\ub294 \ubc29\uc2dd\n\/\/ Recommended way to use headers\nvoid message (std::string&amp; msg);\n\n#endif\n<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f pointer.cpp<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream>\n#include &lt;string>\n#include \"header.h\" \/\/ \ud5e4\ub354 \ud3ec\ud568 \/ Includes header\n\nusing namespace std; \/\/ std \ub124\uc784\uc2a4\ud398\uc774\uc2a4 \uc0ac\uc6a9\ud558\uae30 \/ Using the std namespace\n\nvoid message(string&amp; msg){\n    cout &lt;&lt; msg &lt;&lt; \"\\n\" &lt;&lt; endl;\n}\n\nstd::string my_message = \"pointer complete!!\";\nint main(){\n\n    \/\/ -- \ud5e4\ub354\uc5d0 \ud074\ub798\ub85c \uc120\uc5b8\ub41c \uacbd\uc6b0 \uc0ac\uc6a9 \ud615\uc2dd -- \/\/\n    \/\/ -- Usage format when declared as a class in the header -- \/\/\n    \/\/ &lt;\ub124\uc784\uc2a4\ud398\uc774\uc2a4>::&lt;\ud074\ub798\uc2a4\ub124\uc784> &lt;\uac1d\uccb4>\n    \/\/ my::Server svr;\n    \/\/\n\n    \/\/ \uc77c\ubc18 string\ubcc0\uc218 \/ General string variable\n\tstring name = \"Ayloy\";\n\n\t\/\/ *ptr => \ud3ec\uc778\ud130\ubcc0\uc218 \/ Pointer Variable\n\t\/\/ &amp;food => \uc77c\ubc18\ubcc0\uc218\uc758 \uc8fc\uc18c \uac12 \/ Address value of a regular variable\n\tstring* ptv = &amp;name;\n\n\t\/\/ \ubcc0\uc218 \ucd9c\ub825 \/. variable output\n\tcout &lt;&lt; name &lt;&lt; \"\\n\";\n\tcout &lt;&lt; &amp;name &lt;&lt; \"\\n\";\n\tcout &lt;&lt; ptv &lt;&lt; \"\\n\";\n\n\t\/\/ print value\n\tcout &lt;&lt; *ptv &lt;&lt; \"\\n\";\n\n\t\/\/ \ud3ec\uc778\ud130\ubcc0\uc218\uc5d0 \uac12 \ubcc0\uacbd\n\t\/\/ change pointer value\n\t*ptv = \"SilverHand\";\n\tcout &lt;&lt; *ptv &lt;&lt; \"\\n\";\n\n\t\/\/ \ud5e4\ub354\uc5d0 \ud074\ub798\uc2a4\ub85c\uc120\uc5b8\ub41c \uacbd\uc6b0 \/ When declared as a class in the header\n    \/\/cout &lt;&lt; \"The sum of 1 and 2 is \" &lt;&lt; svr.add(1, 2) &lt;&lt; std::endl;\n\n    \/\/ \ud5e4\ub354\uc5d0 \uba64\ubc84 \ud568\uc218\ub85c \uc120\uc5b8\ub41c \uacbd\uc6b0 \/ When declared as a member function in the header\n    cout &lt;&lt; \"The sum of 1 and 2 is \" &lt;&lt; my::add(1, 2) &lt;&lt; std::endl;\n\n    \/\/ ftest\ud568\uc218 \uc2e4\ud589 \/ Excute ftewt function\n    ftest();\n    \/\/ message\ud568\uc218 \uc2e4\ud589, \ucc38\uc870\ub85c \uc804\ub2ec \/ Execute message function, passed by reference\n    message(my_message);\n\treturn 0;\n}\n<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \ucef4\ud30c\uc77c \/ Compiling<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>g++ pointer.cpp -o pointer -std=c++17<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f\uc2e4\ud589 \/ Run<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/pointer<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \uacb0\uacfc \/ Results<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Ayloy\n0x16cf4f0e0\n0x16cf4f0e0\nAyloy\nSilverHand\nThe sum of 1 and 2 is 3\nftest message\n\npointer complete!!\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\udc49\ud83c\udffb \ud3ec\uc778\ud130 \/ Pointer \u2714\ufe0f \ubcc0\uc218\uc758 \uc8fc\uc18c \uac12\uc744 \uc800\uc7a5\ud558\ub294 \ubcc0\uc218A variable that stores the address value of a variable \u2714\ufe0f \uc8fc\uc18c\uc5f0\uc0b0\uc790(&amp;)\ub97c \uc0ac\uc6a9\ud558\uba74 \ubcc0\uc218\uc758 \uc8fc\uc18c\ub97c \uac00\uc838\uc62c \uc218 \uc788\uc2b5\ub2c8\ub2e4.You can get the address of a variable by using the address operator (&amp;). \ud83d\udc49\ud83c\udffb\ub124\uc784\uc2a4\ud398\uc774\uc2a4 \/ namespace \u2714\ufe0f\uc5ec\ub7ec \ub77c\uc774\ube0c\ub7ec\ub9ac\ub098 \ubaa8\ub4c8\uc744 \ud568\uaed8 \uc0ac\uc6a9\ud560 \ub54c, \ud574\ub2f9 \uc774\ub984\ub4e4\uc744 \uadf8\ub8f9\ud654\ud558\uc5ec \uc11c\ub85c \uac04\uc12d\ud558\uc9c0 \uc54a\ub3c4\ub85d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,1],"tags":[],"class_list":["post-5435","post","type-post","status-publish","format-standard","hentry","category-cpp","category-uncategorized","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=5435"}],"version-history":[{"count":4,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5435\/revisions"}],"predecessor-version":[{"id":5439,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5435\/revisions\/5439"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=5435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=5435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=5435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}