C++ Variable
A variable is a name of memory location. It is used to store data. Its value can be changed and it can be reused many times.
It is a way to represent memory location through symbol so that it can be easily identified.
syntax
Datatype variable name;
Example of declaring variable
int x;
float y;
char z;
Here, x, y, z are variables and int, float, char are data types.
We can also provide values while declaring the variables
int x=5,b=10; //declaring 2 variable of integer type
float f=30.8;
char c='A';
Rules for defining variables
A variable can have alphabets, digits and underscore.
A variable name can start with alphabet and underscore only. It can't start with digit.
No white space is allowed within variable name.
A variable name must not be any reserved word or keyword e.g. char, float etc.
Valid variable names:
int a;
int _ab;
int a30;
Invalid variable names:
int 4;
int x y;
int double;
C++ Data Types
Enumerated Types
An enumerated type declares an optional type name and a set of zero or more identifiers that can be used as values of the type. Each enumerator is a constant whose type is the enumeration.
Creating an enumeration requires the use of the keyword enum.
The general form of an enumeration type is −
enum enum-name { list of names } var-list;
Here, the enum-name is the enumeration's type name. The list of names is comma separated.
By default, the value of the first name is 0, the second name has the value 1, and the third has the value 2, and so on. But you can give a name, a specific value by adding an initializer. For example, in the following enumeration, green will have the value 5.
enum color { red, green = 5, blue };
Here, blue will have a value of 6 because each name will be one greater than the one that precedes it
C++ Keywords
A keyword is a reserved word. You cannot use it as a variable name, constant name etc.
C++ Operators
An operator is simply a symbol that is used to perform operations. There can be many types of operations like arithmetic, logical, bitwise etc.
There are following types of operators to perform different types of operations in C language.
v Arithmetic Operators
v Relational Operators
v Logical Operators
v Bitwise Operators
v Assignment Operator
v Unary operator
v Ternary or Conditional Operator
v Misc Operator
Misc Operators
Precedence of Operators in
C++
The precedence of operator species that which operator will be evaluated first and next. The associativity specifies the operators direction to be evaluated, it may be left to right or right to left.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.