BASIC PROGRAM ELEMENTS / BASIC C++ PROGRAM (APPLY OPERATORS AND EXPRESSION) π₯
VARIABLE AND CONSTANT β
β Give the computer the name or address of a memory location where the data to be save.
β Tell the computer , the data type you want to save.
β Computer will reserves a location inside the computer memory for the computer memory for the variable value.
DECLARE VARIABLE π
β Use a variable in C++ , it must be defined.
β When define the variable , the compiler reserves a location inside the computer memory for the variable value.
β Can define a variable anyplace within a program as long as it is defined before it is used.
β DEFINE CHARACTER
β The system will reserve a memory place named which is character data type and with a size of 1 bit and another 1 bit will be automatically reserve by the system for the terminator "\0" which means end of data.
πΊ DEFINE STRING
π© The system will reserve a memory place named name which is character data type but group in string and with a size of 4 bit as defined.
β UNLIMITED STRING
β The system will reserve a memory place name which is character data type but group in string and with a enough space size.
π CONSTANT
β Constant refers to fixed values that cannot be changed by the program.
β It is a good programming practice to give constant name is CAPITAL LETTER to differentiate between variable name and constant name.
π© STRING CONSTANT
β Use some information like our name , our address or our phone number , as a example for printing purpose.
πΎ COUT
β FORMAT
β cout<<item1<<item2<<item3;
β Getting out fixed numeric information.
β Getting out fixed character information.
β Getting out variable information.
β Defination
β cout is the standard output stream OBJECT.
β CIN
π© FORMAT
β cin>>item1
π© Header File Needed
β <iostream>
π© Rules
β only one character is read at a time.
π₯ IDENTIFIER SCOPE
π΄ LOCAL
β Local variables are declared inside a function and can be used only inside that function.
β It is possible to have local variables with the same name in different function.
β Even the name is the same , they are not the same . It's like two people with the same name. Even the name is the same , the persons are not.
π΄ GLOBAL
β Global variables are declared outside any function , and they can be accessed on any function in the program.
β The scope of a variables refers to where is a variables visible or accesible. If a person asks what is the scope of a variable , she's asking whether it is local or global.
π₯ ARITHMETIC OPERATION
β
β DIVISION (/)
β Only the divide operator need special attention.
β When divide two integer number , you may get a floating-point answer.
β Warning of possible losing of data.
β MODULUS OPERATOR (%)
β Simply generate the remainder that when you divide 2 integers.
β The modulus operator can only used for integers and will generate a compiler error if you attempt to apply it to floating values.
π© PRECEDENCE OPERATOR
β All operator within parentheses are performed first ()
β Parentheses within parenthesesn( ( ) ) inner parentheses will be performed first , from inside out.
β The *,/,% are performed first , from left to right.
β The +,- are performed last , from left to right.
β LOGICAL OPERATION
β BOOLEAN OPERATION / RELATIONAL OPERATION