Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    May 2009
    Posts
    28
    Thanks
    9
    Thanked 0 Times in 0 Posts

    a question about integers

    ok, im really begining at c++. i know int means integer.so when i was writing a basic code liek this:


    #include <iostream>
    using namespace std;

    int main ()
    {
    int a, b, c;
    int result;

    a= 9;
    b= 12;
    c= 459;
    a= a + b + 2 * c -a * b;
    result= a * b + 6;

    cout << result;
    cin.get();

    return 0;
    }


    ok, <iostream> is blue because i was wondering, what exactly does that do in this code.

    i made int main(); red because i thought integers were supposed to be used somewhere in the code again like the int. a, b, and c, and result. what does main() do?

  • #2
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post
    A function is a block of code.
    It has been put together so that you can make use of it without re-writing the whole thing wherever you need that functionality.
    So, you can call that block (called function) any number of times.

    main() is one such function and it is the starting point of your C code. This function will be called by the startup routine which will reside in one of the libraries that gets compiled with your C code.

    Hope it helps,
    Mywk

  • Users who have thanked Mywk for this post:

    saadhamza (06-14-2009)

  • #3
    New Coder
    Join Date
    May 2009
    Posts
    28
    Thanks
    9
    Thanked 0 Times in 0 Posts
    ok, thank you. i think i get it a little now.

  • #4
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    The #include <iostream> line means to include a system file called iostream. The #include is called an include directive. It does much as the name implies, it tells the compiler to include a file at that line. The iostream file has a grouping of functions that give you basic input/output functionality.

    If you see a include directive like this: #include "somefile.h" where there are quotes instead of angles, it means the file is a user file and it uses the path specified instead of searching the system include paths.

    Does that make sense?
    OracleGuy

  • Users who have thanked oracleguy for this post:

    saadhamza (06-15-2009)

  • #5
    New Coder
    Join Date
    May 2009
    Posts
    28
    Thanks
    9
    Thanked 0 Times in 0 Posts
    yea. thanx


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •