{"id":2560,"date":"2020-03-21T18:17:39","date_gmt":"2020-03-21T18:17:39","guid":{"rendered":"https:\/\/itteacheritfreelance.hk\/wordpress\/?p=2560"},"modified":"2020-03-21T18:46:38","modified_gmt":"2020-03-21T18:46:38","slug":"c-c-programming","status":"publish","type":"post","link":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/2020\/03\/21\/c-c-programming\/","title":{"rendered":"C  C++  programming  C\u8bed\u8a00 \u7f16\u7a0b \u8bed\u8a00 \u6559\u5b78"},"content":{"rendered":"<p><br \/><!--StartFragment--><\/p>\n\n\n<html><body><h2 class=\"wp-block-heading\">getchar()&#12289;putchar()&#65306;<br><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt; cstdio >\n#include &lt; cstdlib >\n\nint main() {\n    printf(\"\u8acb\u8f38\u5165\u4e00\u500b\u5b57\u5143\uff1a\");\n    char c = getchar();\n    putchar(c);\n    putchar('\\n');\n    system(\"PAUSE\");\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p>getchar()\u53d6\u5f97\u4f7f\u7528\u8005\u8f38\u5165\u7684\u5b57\u5143\uff0cputchar()\u8f38\u51fa\u4e00\u500b\u5b57\u5143\u3002<\/p>\n\n\n\n<p>gets()\u3001puts()\uff1a<br>gets()\u6703\u53d6\u5f97\u4f7f\u7528\u8005\u7684\u8f38\u5165\u5b57\u4e32\uff0c\u4e0d\u5305\u62ec\u6309\u4e0bEnter\u7684\u63db\u884c\u5b57\u5143\u78bc\uff0cputs()\u7528\u4f86\u8f38\u51fa\u5b57\u4e32\uff0c\u4e26\u76f4\u63a5\u9032\u884c\u63db\u884c\u3002<\/p>\n\n\n<p><br>\n<!--StartFragment--><\/p>\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/itteacheritfreelance.hk\/test\/wordpress\/wp-content\/uploads\/2016\/04\/c-c-programming-for-hackers-part-1-introduction.1280x600.jpg\" alt=\"C++ ,C\u8bed\u8a00, \u96fb\u8166\u73ed, C\u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00, C\/C++\u96fb\u8166\u73ed, \u96fb\u8166\u8ab2\u7a0b, \u96fb\u8166\u8ab2\u7a0b, C++\u88dc\u7fd2\u6559\u5b78, C++\u88dc\u7fd2,C++\u7a0b\u5f0f\u7de8\u5beb,C++\u8ab2\u7a0b\u88dc\u7fd2,C++, \u5927\u5b78\u751fC++\u8ab2\u7a0b ,C++1 \u5c0d 1 \u79c1\u4eba\u96fb\u8166\u8ab2\u7a0b, C++1 \u5c0d 1 \u79c1\u4eba\u96fb\u8166\u88dc\u7fd2,C++\u79c1\u4eba\u88dc\u7fd2, C++\u96fb\u8166\u8208\u8da3\u73ed, C++\u96fb\u8166\u88dc\u7fd2\u73ed\" class=\"wp-image-175\"\/><figcaption>C\/C++<\/figcaption><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt; cstdio >\n#include &lt; cstdlib >\n\nint main(void) {\n    char str[20];\n    puts(\"\u8acb\u8f38\u5165\u5b57\u4e32\uff1a\");\n    gets(str);\n    puts(\"\u8f38\u5165\u7684\u5b57\u4e32\u70ba\uff1a\");\n    puts(str);\n    system(\"PAUSE\");\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u683c\u5f0f\u63a7\u5236\u5668\u3001\u683c\u5f0f\u65d7\u6a19(cout)<\/h2>\n\n\n\n<p>cout\u6709\u9810\u8a2d\u7684\u8f38\u51fa\u683c\u5f0f\uff0c\u4e5f\u53ef\u4ee5\u81ea\u884c\u6307\u5b9a\u683c\u5f0f\uff0c\u50cfendl\u5c31\u662f\u683c\u5f0f\u63a7\u5236\u5668\u7684\u4e00\u7a2e\uff0c\u5b83\u6703\u8f38\u51fanew line\u5b57\u5143\u81f3\u4e32\u6d41\u4e2d\uff0c\u683c\u5f0f\u63a7\u5236\u5668\u53ea\u6703\u5f71\u97ff\u76ee\u524d\u6b63\u5728\u8655\u7406\u7684\u4e32\u6d41\uff0c\u4e32\u6d41\u8655\u7406\u7d50\u675f\u5f8c\u5373\u56de\u5fa9\u6210\u9810\u8a2d\u7684\u683c\u5f0f\uff0c\u683c\u5f0f\u63a7\u5236\u5668\u4e5f\u53ef\u4ee5\u6307\u5b9a\u53c3\u6578\uff0c\u5982\u679c\u8981\u4f7f\u7528\u5177\u6709\u53c3\u6578\u7684\u683c\u5f0f\u63a7\u5236\u5668\uff0c\u5fc5\u9808\u542b\u5165iomanip\u9019\u500b\u6a19\u982d\u6a94\u6848\uff0c\u4e0b\u9762\u70ba\u7c21\u55ae\u7684\u4f7f\u7528\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream> \n#include &lt;iomanip>\nusing namespace std;\n\nint main() {\n    cout &lt;&lt; oct &lt;&lt; 30 &lt;&lt; endl;    \/\/8\u9032\u4f4d\u986f\u793a \n    cout &lt;&lt; hex &lt;&lt; 30 &lt;&lt; endl;    \/\/16\u9032\u4f4d\u986f\u793a \n    cout &lt;&lt; setw(2) &lt;&lt; 5 &lt;&lt; endl; \/\/\u5bec\u5ea6\u70ba2\n    system(\"PAUSE\");\n    return 0;\n}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u683c\u5f0f\u63a7\u5236\u5668\u53ef\u4ee5\u6539\u8b8a\u76ee\u524d\u7684\u4e32\u6d41\u683c\u5f0f\uff0c\u5982\u679c\u60f3\u8981\u8b93\u6240\u6709\u7684\u4e32\u6d41\u90fd\u7dad\u6301\u7279\u5b9a\u683c\u5f0f\uff0c\u53ef\u4ee5\u4f7f\u7528\u683c\u5f0f\u5316\u65d7\u6a19\uff0c\u4f7f\u7528setf()\u8207unsetf()\u4f86\u8a2d\u5b9a\u8207\u53d6\u6d88\u683c\u5f0f\u5316\u65d7\u6a19\uff0c\u4e0b\u9762\u70ba\u7c21\u55ae\u7684\u793a\u7bc4\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream> \nusing namespace std;\n\nint main() {\n    cout.unsetf(ios::dec);              \n    cout.setf(ios::hex); \n    cout &lt;&lt; 120 &lt;&lt; endl;\n    cout &lt;&lt; 50 &lt;&lt; endl;\n\n    cout.setf(ios::dec);\n    cout.setf(ios::scientific);\n    cout &lt;&lt; 50.25 &lt;&lt; endl;\n\n    system(\"PAUSE\");\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Basic types of Variables<\/h2>\n\n\n\n<p>Each variable while declaration must be given a datatype, on which the memory assigned to the variable depends. Following are the basic types of variables,<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td><code>bool<\/code><\/td><td>For variable to store <a href=\"http:\/\/itteacheritfreelance.hk\/index.php\" title=\"\u672c\u7db1\u9801\u63d0\u4f9b\u4e00\u500b\u65b9\u4fbf\u7684\u5e73\u53f0, \u70ba\u5927\u5bb6\u914d\u5c0d\u96fb\u8166\u88dc\u7fd2,IT freelance, \u79c1\u4eba\u8001\u5e2b , PHP\u88dc\u7fd2, HTML\u88dc\u7fd2, CSS\u88dc\u7fd2, JavaScript\u88dc\u7fd2, XML, Java\u88dc\u7fd2,Server\u88dc\u7fd2, MySQL\u88dc\u7fd2, \u4e2d\u5b78\u96fb\u8166\u79d1\u79c1\u4eba\u88dc\u7fd2, \u5728\u8077\u4eba\u58eb\u96fb\u8166\u63d0\u5347\u88dc\u7fd2,\u5c08\u696d\u8003\u8a66\u96fb\u8166 \u88dc\u7fd2,\u96fb\u8166\u5716\u50cf\u8a2d\u8a08\u96fb\u8166\u88dc\u7fd2, gra\">boolean<\/a> values( True or False )<\/td><\/tr><tr><td><code>char<\/code><\/td><td>For variables to store character types.<\/td><\/tr><tr><td><code>int<\/code><\/td><td>for variable with integral values<\/td><\/tr><tr><td><code>float<\/code>&nbsp;and&nbsp;<code>double<\/code>&nbsp;are also types for variables with large and floating point values<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Declaration and Initialization<\/h2>\n\n\n\n<p>Variable must be declared before they are used. Usually it is preferred to declare them at the starting of the program, but in C++ they can be declared in the middle of program too, but must be done before using them.<\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int i;      \/\/ declared but not initialised\nchar c; \nint i, j, k;  \/\/ Multiple declaration\n<\/code><\/pre>\n\n\n\n<p>Initialization means assigning value to an already declared variable,<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int i;   \/\/ declaration\ni = 10;  \/\/ initialization\n<\/code><\/pre>\n\n\n\n<p>Initialization and declaration can be done in one single step also,<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int i=10;         \/\/initialization and declaration in same step\nint i=10, j=11;\n<\/code><\/pre>\n\n\n\n<p>If a variable is declared and not initialized by default it will hold a garbage value. Also, if a variable is once declared and if try to declare it again, we will get a compile time error.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int i,j;\ni=10;\nj=20;\nint j=i+j;   \/\/compile time error, cannot redeclare a variable in same scope\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/itteacheritfreelance.hk\/test\/wordpress\/wp-content\/uploads\/2016\/04\/c-c-programming-for-hackers-part-1-introduction.1280x600.jpg\" alt=\"C++ ,C\u8bed\u8a00, \u96fb\u8166\u73ed, C\u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00, C\/C++\u96fb\u8166\u73ed, \u96fb\u8166\u8ab2\u7a0b, \u96fb\u8166\u8ab2\u7a0b, C++\u88dc\u7fd2\u6559\u5b78, C++\u88dc\u7fd2,C++\u7a0b\u5f0f\u7de8\u5beb,C++\u8ab2\u7a0b\u88dc\u7fd2,C++, \u5927\u5b78\u751fC++\u8ab2\u7a0b ,C++1 \u5c0d 1 \u79c1\u4eba\u96fb\u8166\u8ab2\u7a0b, C++1 \u5c0d 1 \u79c1\u4eba\u96fb\u8166\u88dc\u7fd2,C++\u79c1\u4eba\u88dc\u7fd2, C++\u96fb\u8166\u8208\u8da3\u73ed, C++\u96fb\u8166\u88dc\u7fd2\u73ed\" class=\"wp-image-175\"\/><figcaption>C\/C++<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/itteacheritfreelance.hk\/test\/wordpress\/wp-content\/uploads\/2016\/03\/2014032it-1024x631.jpg\" alt=\"IT\u96fb\u8166\u88dc\u7fd2, IT Teacher IT Freelance\" class=\"wp-image-8\"\/><figcaption>IT Freelance<\/figcaption><\/figure>\n\n\n<p><\/p>\n<p><!--EndFragment--><br>\n<br>\n<\/p>","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>getchar()&#12289;putchar( <a class=\"mh-excerpt-more\" href=\"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/2020\/03\/21\/c-c-programming\/\" title=\"C  C++  programming  C\u8bed\u8a00 \u7f16\u7a0b \u8bed\u8a00 \u6559\u5b78\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":14,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"C C++ programming C\u8bed\u8a00 \u7f16\u7a0b \u8bed\u8a00 \u6559\u5b78 - ITTeacherITFreelance.hk","description":"getchar()&#12289;putchar()&#65306; getchar()\u53d6\u5f97\u4f7f\u7528\u8005\u8f38\u5165\u7684\u5b57\u5143\uff0cputchar()\u8f38\u51fa\u4e00\u500b\u5b57\u5143\u3002 gets()\u3001puts()\uff1a gets()\u6703\u53d6\u5f97\u4f7f\u7528\u8005\u7684\u8f38\u5165\u5b57\u4e32\uff0c\u4e0d\u5305\u62ec\u6309\u4e0bEnter\u7684\u63db\u884c\u5b57\u5143\u78bc\uff0cputs()\u7528\u4f86\u8f38\u51fa\u5b57\u4e32\uff0c\u4e26\u76f4\u63a5\u9032\u884c\u63db\u884c\u3002 \u683c\u5f0f\u63a7\u5236\u5668\u3001\u683c\u5f0f\u65d7\u6a19(cout)"},"footnotes":""},"categories":[1306],"tags":[],"_links":{"self":[{"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/2560"}],"collection":[{"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=2560"}],"version-history":[{"count":1,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/2560\/revisions"}],"predecessor-version":[{"id":2561,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/2560\/revisions\/2561"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/media\/14"}],"wp:attachment":[{"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=2560"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=2560"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=2560"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}