码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2018-01-24 17:00:26      阅读:201      评论:0      收藏:0      [点我收藏+]

标签: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)

标签:chapter   nat   pos   elves   ted   names   init   operator   another   

原文地址:https://www.cnblogs.com/zimingzhu/p/8336004.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!