Friday, July 17, 2009

C++ Tutorial For The First Program


C++ Tutorial

Quiz :

1) What differs compiler from interpreter ?
2) Give the steps involved in the normal development cycles

Exercises :

1) Create a c++ program that displays your name.
2) Find the bug in the following program :

#include <iostream>

int main ();
{

    std::cout << "I love C++";

    return 0;
}


Solution of the Quiz :

1) Interpreters turn program instruction directly into actions by reading through the source code. Compilers create an executable program by translating the source code that can be run later.
2) Editing source code, compiling, linking, running and when required repeat it.

Solution of the Exercises :

1) A c++ program that displays name :

#include <iostream>

int main ()
{

    std::cout << "Mohammed Homam";

    return 0;
}

2) The main function is terminated by the semicolon.

Please do comment if you don't understand any part or want to know more or just want to say thanks. I love programming and love to teach my friends. Your suggestions and appreciation will make this blog much better.
Want to learn more? View List Of All Chapters

6 comments:

  1. When I compile the program using F9, I dont see the output window. Thanks, Ajay

    ReplyDelete
  2. You might be using dev c++. You can add std::cin.get(); or system("PAUSE"); before the return 0; statement.

    I recommend you to use codeblocks. It is better than dev c++. You can download it from here: http://www.codeblocks.org/downloads/binaries

    In codeblocks and visual studio, you don't need to add std::cin.get(); or system("PAUSE"); before return 0; statement.

    ReplyDelete
  3. Thanks Mohammed.

    ReplyDelete
  4. but why i am wrong it says syntax error

    i'm using devC++

    ReplyDelete
    Replies
    1. Because there is syntax error that you have to find it. The error is that main function is terminated by the semicolon. [main ();] Just remove the semicolon after main function and the program will run fine.

      Delete
  5. These are truly amongst the wonderful informative blogs.
    c++ programming

    ReplyDelete