Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

atjari

  • 4 years ago

Can someone explain me the method of writing a C++ program?

  • This Question is Closed
  1. Vibhor16
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 5

    "->" is used to separate code from text .It is not used in C++(for this purpose) ->#include<iostream.h> 1)# is a pre-processor indicator 2)include is a pre processor command to "add" a file to your program. 3)<___> file name should come in pointing brackets. 4)iostream.h is the file which allows us to give output or take input. ->void main() -> { ->(body/commands/statement) -> } 1)void is a data type .It indicates that the function (main) will return nothing. other data types are int(for digits),char(for characters),float(for decimals). 2)main() is a function. generally functions are called by writing their name but main() is special is the first one to be called by the compiler itself.You can also write your own functions in C++. 3){} are also called blocks and contains the body of the function. 4)The empty space in the body is used to write commands. ->cout<<"Hi"; 1)cout<< is a keyword in iostream.h file that allows us to print output. 2)Anything to be printed comes within the " ". 3)Every C/C++ command ends with ; ->int v; v=5; 1)int is the data type for digits, 2)v is a variable.int indicates that it can hold only digits. 3)v is assigned the value 5. ->cin>>v; 1)cin>> is a keyword in iostream.h to take a value from user and store it in v. The value v can hold depends on its data type. Sample Code: ->#include<iostream.h> ->void main() -> { ->int no; ->cout<<"Enter your number : "; ->cin>>no; ->// Comments are written like this in c++ ->//coments are ignored by the compiler ->// to leave a space of a line in c++ use \n ->cout<<"\nWelcome number "<<v; -> } ALSO TRY THIS: a complete guide which will make you comfortable with theory part and understanding of C++ http://www.cplusplus.com/doc/tutorial/introduction/

  2. atjari
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanx a lot.

  3. agdgdgdgwngo
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    void main? why? the C++ standard mandates that main() has an int return type (unless you're developing under some OS which cannot handle return values)

  4. Vibhor16
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 5

    I prefer void over int for main though it does not makes any difference.Its just if you use int you will have to write "return 0;" at the end which is equivalent to void.I prefer int in functions with calculations but for a code such as : cout<<"Hello World"; it would make no difference in such cases.

  5. agdgdgdgwngo
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    It's non-standard though and Stroustrup advises against it: http://www2.research.att.com/~bs/bs_faq2.html#void-main here are some more reasons: http://users.aber.ac.uk/auj/voidmain.shtml

  6. Vibhor16
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 5

    OK.Good info.....

  7. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy