1. Welcome to PHCorner Forums. Take a moment to Sign up and gain unlimited access and extra privileges that guests are not entitled to, such as:

    All that and more! Registration is quick, simple and absolutely free. Join our community today!

C and C++ Structure of a Program

Discussion in 'Coding, Programming' started by DCCS, Mar 6, 2015.

  1. DCCS

    DCCS Forum Veteran Established

    Hi guys eto po yung karugtong ng thread ni bro fazz12fazz12

    Bago kayo mag proceed dito sa Thread na ito be sure na basahin niyo muna yung first part which is here Please or Register to view links

    Magdadagdag lang tayo ng statement sa program natin.
    Yung unang ginawa natin ay "Hello World!". Ngayon naman dagdagan natin ng "I'm a C++ programmer"

    Special Note: cout read as See-Out , std read as Studio

    Okay let us start.

    Part II

    // my second program in C++
    [HASHTAG]#include[/HASHTAG] <iostream>

    int main ()
    {
    std::cout << "Hello World! ";
    std::cout << "I'm a C++ program"; // Eto yung dinagdag natin.
    }

    Sa code natin ngayon nagdagdag tayo ng dalawang magkaibang statement. Kung Gusto niyong mag try i-run yung program pwede niyong gawin dito yan ---> Please or Register to view links

    Katulad ng sinabi ko sa 1st page.
    Pwede niyong paikliin ang statement like this

    int main () { std::cout << " Hello World! "; std::cout << " I'm a C++ program "; }

    Wag niyo lang kalilimutan ang head

    [HASHTAG]#include[/HASHTAG] <iostream>

    Complete code:

    [HASHTAG]#include[/HASHTAG] <iostream>

    int main () { std::cout << " Hello World! "; std::cout << " I'm a C++ program "; }

    Pwede rin namang i-divide (hatiin sa dalawa o higit pa) ang code natin.
    Like this:

    int main ()
    {
    std::cout <<
    "Hello World!"; // Prints Hello World!
    std::cout
    << "I'm a C++ program"; // Prints I'm a C++ program
    }

    Part III: Using Namespace std

    If you have seen C++ code before, you may have seen cout being used instead of std::cout. Both name the same object: the first one uses its unqualified name (cout), while the second qualifies it directly within the namespacestd(as std::cout).

    cout is part of the standard library, and all the elements in the standard C++ library are declared within what is a called a namespace: the namespace std.

    In order to refer to the elements in the std namespace a program shall either qualify each and every use of elements of the library (as we have done by prefixing cout with std::), or introduce visibility of its components. The most typical way to introduce visibility of these components is by means of using declarations:

    Code:

       Sorry you need to Register / Login to see this Codes!    

    The above declaration allows all elements in the std namespace to be accessed in an unqualified manner (without the std:: prefix).

    With this in mind, the last example can be rewritten to make unqualified uses of cout as:

    Code:

       Sorry you need to Register / Login to see this Codes!    

    Both ways of accessing the elements of the std namespace (explicit qualification and using declarations) are valid in C++ and produce the exact same behavior. For simplicity, and to improve readability, the examples in these tutorials will more often use this latter approach with using declarations, although note that explicit qualification is the only way to guarantee that name collisions never happen.
    ---------------
    Dyan na lang muna sa ngayon :) try niyo i-run at isulat yung mga code ng walang tinginan para makabisado mo o niyo ang code (y)
     
    PurpleFox and mha30 like this.
  2. derx

    derx El Vampiro Staff Member Moderator

  3. DCCS

    DCCS Forum Veteran Established

    (y) /msg short
     
  4. fazz12

    fazz12 Addict Established

Tags / Keywords: