C සඳහා උදාහරණ – 3

පසුගිය ලිපි
C සඳහා උදාහරණ – 1
C සඳහා උදාහරණ – 2

දැන් ඔබ තේරුම් ගන්න ඕනෙ printf() කියන්නෙ ටිකාක් විතර සංකීර්ණ නියෝගයක් කියල. ඒක එහෙම වෙන්න හේතුව එම නියෝගය නිකම්ම වචන තිරයේ දැක්වීමට වඩා දෙයක් කළ හැකි නියෝගයක් වීමයි. ඒවා ගැන අපි පස්සෙ හිමින් හිමින් කතා කරමු.

නිකම්ම වචන තිරයේ දැක්විය හැකි මීට වඩා සරල නියෝගයක් Ubuntu උඩ වැඩ කරන gcc වලත් Windows XP උඩ උඩ කරන MinGW වල gcc වලත් තිබෙනවා. ඒ තමයි puts කියන නියෝගය. මේ නියෝගය වැඩ කරන හැටි ඉගෙන ගැනීම සඳහා පහත දැක්වෙන පරිගණක වැඩ සටහන ටයිප් කර යම් තැනක ගබඩා කර Compile කර Run කරන්න.

Test3A.c

Test3A.c

හැබැයි මේ නියෝගයට නම් “\n” යන්න එකතු කරන්න ඕනෙ නෑ ඊළඟ පේළියට පනින්න. ඒක එක වෙනසක්. මේ නියෝගය Text හැර වෙන දේවල් ප්‍රින්ට් කරන්න යොදා ගන්න බෑ. ඒ ඊළඟ වෙනස.

මේ නියෝගය Turbo C++ වල නම් නෑ. නමුත් ඒකෙ වෙන නියෝගයක් තියෙනවා cout<< කියල ඒක තියෙන්නෙ iostream.h කියන Header File එකෙයි. ඕන්න මම ඒ වැඩ සටහනත් දැම්මා.

Test3B.c

Test3B.c

Turbo C++ වල “\n” වෙනුවට වෙනම endl කියල ලියන්නත් පුළුවන්.

Test3C.c

Test3C.c

මේක ම තනි නියෝගයක් හැටියට ලියන්න උත්සාහ ගන්න.

අමතර ලිපි
පළමුවන හා දෙවන පරම්පරාවල පරිගණක භාෂා
Compilers හා Interpreters
gcc හා g++
පළමු C උදාහරණයේ සැඟවුණු කරුණු
C භාවිතා කිරීම අරඹන විට මුහුණ පාන ප්‍රශ්ණ

This entry was posted in 16. C++, සිංහල. Bookmark the permalink.

8 Responses to C සඳහා උදාහරණ – 3

  1. Wathsala Vithanage says:

    Let me extend ths C++ section a little bit. Newer and up to date C++ compilers such as g++ follow the new C++ standard which omits the .h part of the header file. Instead of writing #include write #include . However when you change over to this new standard you have to indicate that you are using std namespace by writing using namespace std; just after including the iostream file. If you do not write it after inclusion of iostream header then you will have to write both endl and cout followed by std::. The code given above can be rewritten as given below to comply with the new standard, you can still follow the old standard but the compiler will throw a deprecation warning regarding the use of old standard.


    #include
    using namespace std;
    int main(int argc, char *argv[])
    {
    cout<<”Hello World”<<endl;
    return 0;
    }

    Or

    #include
    int main(int argc, char *argv[])
    {
    std::cout<<”Hello World”<<std::endl;
    return 0;
    }

    It will be great if this could be translated to Sinhala (I do not have a proper keyboard driver at the moment to type Sinhala).

    • Wathsala Vithanage says:

      Too bad angle bracketd header file names get lost even inside “code” tags.

      • kumudupinto says:

        Either you have to convert it to an image and display it, or else force to display the angle brackets.

  2. kumudupinto says:

    ඉහත පරිගණක වැඩ සටහනේ main() හි වරහන් තුළ ලියා ඇති දේ ගැන වැඩිය බය වෙන්න එපා. අපි Parameters ගැන හා Arrays ගැන කතා කළායින් පස්සෙ ඒ කොටස තේරෙයි.

  3. risenfall says:

    සිංහලෙන් පලවෙන C ලිපි පෙලනම් අපූරැයි. නමුත් පටුනක් නැති නිසා කෙනෙකුට පිලිවෙලකට කියවීමට ටිකක් අපහසුයි. කොහොමද සියලු C ලිපි ටික විකී පොතක් ලෙස නැවත පල කලොත්.

    විකී පොතක් පලකිරීමට උපදෙස්.

    http://en.wikibooks.org/wiki/Help:Starting_a_new_page_or_book

    • kumudupinto says:

      පළවෙනි කාරණේ දැන් පටුන නමින් පිටුවක් තිබෙනවා. එහි එක් එක් මාතෘකාවක් යටතේ පළ වන ලිපි සඳහා යොමු තිබෙනවා. දෙවෙනි කාරණේ මම විකි පොතක් පළ කිරීමට උත්සාහ ගන්නම්. හැබැයි “පුංචිත්තන්ට ප්‍රෝග්‍රැමින්” යනුවෙන් මා තවත් සහෘදයකු සමඟ පළ කළ පොත් පෙලෙහි C++ සඳහා පොත් දෙකක් ද තිබුණා.

  4. “පුංචිත්තන්ට ප්‍රෝග්‍රැමින්” යනුවෙන් මා තවත් සහෘදයකු සමඟ පළ කළ පොත් පෙලෙහි C++ සඳහා පොත් දෙකක් ද තිබුණා.

    සර් මේ ගැන විස්තර ටිකක් දෙන්න පුලුවන්ද?

    • kumudupinto says:

      විස්තර දුන්නට වැඩක් නැතිවෙයි. ඒ පොත් ඔක්කොම Out of Stock !

Leave a comment