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

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.

 

转载于:https://www.cnblogs.com/zimingzhu/p/8336004.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值