the usefulness on your hello world programs shown within the whole previous section is quite questionable. we had to put in writing many lines of code, compile them, then execute the ensuing program only to get an easy sentence written by the screen as result. it certainly would are a lot of faster to type the output sentence by ourselves. though, programming isn't restricted solely to printing simple texts by the screen. so as to visit alittle any on in order to become able to put in writing programs that perform useful tasks that extremely save us work we have out to be compelled to introduce the idea of variable.
allow us to suppose that i raise one to retain the quantity 5 located within mental memory, then i raise one to memorize conjointly the quantity 2 with the same time. you could have only stored 2 different values located within memory. currently, if i raise one to add 1 onto the 1st range i aforesaid, you really should be retaining the numbers 6 ( that would be 5+1 ) and 2 located within memory. values that many of us may currently -for example- subtract and obtain 4 as result.
the full method that you could have only done along with your mental memory may be a simile of what a computer can perform with 2 variables. the very same method often is expressed in c++ when using the following instruction set :
a = 5 ;
b = 2 ;
a = a + 1 ;
result = a - b ;
obviously, this is often a really simple example since we've got solely used 2 small integer values, other then think about that your computer will store innumerable numbers like these with the same time and conduct refined mathematical operations around with them.
thus, we are able to define a variable currently being a small portion memory to store a determined price.
every variable desires an identifier that distinguishes it coming from the others. for instance, within the whole previous code the variable identifiers were a, b and result, however i could afford known as variables any names we needed to invent, as long like they were valid identifiers.
Data Type
when programming, we store the variables in your computers memory, however the computer has to learn what more than a little information need to'>we desire to store in them, since it's not intending to occupy the exact number of memory to store a straightforward variety than to store a unmarried letter or maybe a massive variety, and these aren't likely to actually be interpreted the exact approach.
the memory in your computers is organized in bytes. a byte will be the minimum number of memory that many of us will manage in c++. a byte will store a relatively small number of information : one unmarried character or maybe a small integer ( usually an integer between zero and 255 ). additionally, the computer will manipulate a lot of advanced information types that originate from grouping many bytes, like long numbers or non-integer numbers.
next you could have a summary of one's basic fundamental information types in c++, and even like the choice of values that can possibly be represented with the whole lot :
char
character or small integer, size 1byte, range signed : -128 to 127 unsigned: 0 to 255
short int
short Integer, size 2bytes, range signed : -32768 to 327676 unsigned: 0 to 65535
int
integer, size 4bytes, signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295
long int
long integer, size 4bytes, signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295
bool
boolean value. It can take one of two values: true or false, size 1byte, range true or false
float
floating point number, size 4bytes, range +/- 3.4e +/- 38 (~7 digits)
double
double precision floating point number, size 8bytes, range +/- 1.7e +/- 308 (~15 digits)
long double
long double precision floating point number, size 8bytes, range +/- 1.7e +/- 308 (~15 digits)
nice info :)
ReplyDelete