In no case can they begin with a digit.Ĭ++ uses a number of keywords to identify operations and data descriptions therefore, identifiers created by a programmer cannot match these keywords. They can also begin with an underline character ( _), but such identifiers are -on most cases- considered reserved for compiler-specific keywords or external identifiers, as well as identifiers containing two successive underscore characters anywhere. In addition, identifiers shall always begin with a letter. Spaces, punctuation marks, and symbols cannot be part of an identifier. For example, in the previous code the variable names were a, b, and result, but we could have called the variables any names we could have come up with, as long as they were valid C++ identifiers.Ī valid identifier is a sequence of one or more letters, digits, or underscore characters ( _). We can now define variable as a portion of memory to store a value.Įach variable needs a name that identifies it and distinguishes it from the others. Obviously, this is a very simple example, since we have only used two small integer values, but consider that your computer can store millions of numbers like these at the same time and conduct sophisticated mathematical operations with them. The same process can be expressed in C++ with the following set of statements: The whole process described above is a simile of what a computer can do with two variables. ![]() Then we could, for example, subtract these values and obtain 4 as result. Now, if I ask you to add 1 to the first number I said, you should be retaining the numbers 6 (that is 5+1) and 2 in your memory. You have just stored two different values in your memory (5 and 2). Let's imagine that I ask you to remember the number 5, and then I ask you to also memorize the number 2 at the same time. In order to go a little further on and to become able to write programs that perform useful tasks that really save us work, we need to introduce the concept of variables. ![]() However, programming is not limited only to printing simple texts on the screen. It certainly would have been much faster to type the output sentence ourselves. We had to write several lines of code, compile them, and then execute the resulting program, just to obtain the result of a simple sentence written on the screen. The usefulness of the "Hello World" programs shown in the previous chapter is rather questionable.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |