Notes on learning c++: chapter 1(second part)

來源:互聯網
上載者:User

標籤:chapter   nat   pos   elves   ted   names   init   operator   another   

chapter 1

1.3a  To print more than one thing on the same line, the output operator(<<) can be used mutiple times.

   When uesd with std::cout, std::endl inserts a nwline character(causing the cursor to go to the start of the next line).

   << is used with std::cout, and shows the direction that data is moving from the r-value to the console. std::cout<<4 moves the value of 4 to the console.

   >> is used with std::cin, and shows the direction that data is moving from the console into the variable. std::cin>>x moves the value from the console into the variable.

1.4   A function is a reusable sequence of statements designed to do a particular job.

   A program will be executing statements sequentially inside one function when it encounters a function call. A function call is an expression that tells the CPU to interrupt the current function and execute another function.

   The function initiating the function call is called the caller, and the function being called is called callee or called function.

   To tell the compiler that a function does not return a value, a return type of void is used.

   This value is called a status code, and it tells the operating system(and any other programs that called ours) whether your program executed successfully or not.

1.4a  A function parameter is a variable used in a function where the value is provided by te caller of the function. Function parameters are placed in between the parenthsis after the function identifier, with mutiple parameters being separated by commas.

   An argument is a value that is passed from the caller to the function when a function all is made.

1.4b  Here are a few basic guidelines for writing functions:

   1) code that appears more than once in a program should generally be made into a function.

   2) code that has a discrete set of inputs and outputs is a good candidate for a function, particularly if it is complicated.

   3) a function should generally perform one(and only one) task.

   4) when a function becomes too long, too complicated, or hard to understand, it should be split into mutiple functions. This is called refactoring.

1.4c  The name of a variable, function, type, or other kind of object in C++ is called an identifier.However, there are a few rules that must be followed when naming identifiers:

   1) the identifier can not be a keyword.

   2) the identifier can only be composed of letters, numbers, and the underscore character.(not contain symbols nor whitespace).

   3) the identifier must begin with a letter or an underscore.

   4) C++ distinguishes between lower and upper case letters.

   Identifier names that start with a capital letter are typically used for structs, calsses, and enumerations.

   If the variable or function name is muti-word, there are two common conventions: separated by underscores, or intercapped.

   Give your identifier names that actually describe what they are.

   A clarifying comment can go a long way.

1.4d  A variable‘s scope determines when a variable can be seen and used during the time it is instantiated. Function parameters and variables defined inside the function body both have local scope.

1.5    Expression: a combination of literals, variables, functions, and operators that evaluates to a value.

   A literal is a fixed value that has been inserted(hardcoded) directly into the source code, such as 5, or 3.14159. Literals always evaluate to themselves.

   Literals, variables, and function calls that return values are all known as operands. Operands supply the data that the expression works with.

   Operators tell the expression how to combine one or more operands to produce a new result.

 

Notes on learning c++: chapter 1(second part)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.