Advice: Deciding which Type to Use C++, like C, is designed to let programs get close to the hardware when necessary. The arithmetic types are defined to cater to the peculiarities of various kinds of hardware. Accordingly, the number of arithmetic types in C++ can be bewildering. Most programmers can (and should) ignore these complexities by restricting the types they use. A few rules of thumb can be useful in deciding which type to use: • Use an unsigned type when you know that the values cannot be negative. • Use int for integer arithmetic. ... If your data values are larger than the minimum guaranteed size of an int, then use long long. • Do not use plain char or bool in arithmetic expressions. Use them only to hold characters or truth values. .... • Use double for floating-point computations.... |
Modern C++ can be thought of as comprising three parts: • The low-level language, much of which is inherited from C • More advanced language features that allow us to define our own types and to organize large-scale programs and systems • The standard library, which uses these advanced features to provide useful data structures and algorithms Most texts present C++ in the order in which it evolved. They teach the C subset of C++ first, and present the more abstract features of C++ as advanced topics at the end of the book. There are two problems with this approach: Readers can get bogged down in the details inherent in low-level programming and give up in frustration. Those who do press on learn bad habits that they must unlearn later. We take the opposite approach: Right from the start, we use the features that let programmers ignore the details inherent in low-level programming. For example, we introduce and use the library string and vector types along with the built-in arithmetic and array types. Programs that use these library types are easier to write, easier to understand, and much less error-prone. |
Even for the professional programmer, it is impossible to first learn a whole programming language and then try to use it. A programming language is learned in part by trying out its facilities for small examples. Consequently, we always learn a language by mastering a series of subsets. The real question is not ‘‘Should I learn a subset first?’’ but ‘‘Which subset should I learn first?’’ One conventional answer to the question ‘‘Which subset of C++ should I learn first?’’ is ‘‘The C subset of C++.’’ In my considered opinion, that’s not a good answer. The C-first approach leads to an early focus on low-level details. It also obscures programming style and design issues by forcing the student to face many technical difficulties to express anything interesting. C++’s better support of libraries, better notational support, and better type checking are decisive against a ‘‘C first’’ approach. |
Our approach is possible only because C++, and our understanding of it, has had time to mature. That maturity has let us ignore many of the low-level ideas that were the mainstay of earlier C++ programs and programmers. The ability to ignore details is characteristic of maturing technologies. For example, early automobiles broke down so often that every driver had to be an amateur mechanic. It would have been foolhardy to go for a drive without knowing how to get back home even if something went wrong. Today's drivers don't need detailed engineering knowledge in order to use a car for transportation. They may wish to learn the engineering details for other reasons, but that's another story entirely. We define abstraction as selective ignorance--concentrating on the ideas that are relevant to the task at hand, and ignoring everything else--and we think that it is the most important idea in modern programming. The key to writing a successful program is knowing which parts of the problem to take into account, and which parts to ignore. Every programming langauge offers tools for creating useful abstractions, and every successful programmer knows how to use those tools. ... If abstractions are well designed and well chosen, we believe that we can use them even if we don't understand all the details of how they work. |
|
|
All that you need to know right now, in addition to what you already know is: It is possible to interpret any sequence of 1s ans 0s as a number. https://en.wikipedia.org/wiki/Binary_numeral_system |
I have ordered this book - http://www.amazon.com/dp/0321714113 and it should be arriving in a few days. |
int ival = 100 ; // fine
double salary = double wage = 9999.99;
|
|
double result = calc() ;
double wage = 9999.99;
is not an expression.
|
|
int i = 23 ;
is not an expression; it defines a variable and initialises it.i + 7
is an expression; when evaluated it yields 30 as the result. i = 45
is an expression; the =
here is assignment, not initialisation. When evaluated, it assigns the value 45 to i and yields the result i.JLBorges wrote: |
---|
int i = 23 ; is not an expression; it defines a variable and initialises it. |
|
|