Skip to main content

Introduce constants, variables, operators and expressions and apply them.

 .

Variable

A variable is a quantity that values is change any time when program execution. It is a memory location used to store a data value. A variable name should be choose carefully by programmer so that it is used in entire program. 
Example :    Int salary;
                    flout P, T, R;
                    char x;
                    String Name [20]

variable declaration

Variable is declaration as following syntax.
<Datatype> <variable_name>;

Example : Int x, y, sum =0;
                  float p, t, r, si=0;
                  double salary;

Rules for variable declaration

  • A variable should not used keywords.
  • Variable must begin with latter and underscore(-).
  • Wide space is not allowed.
  • Max length is 8 character only.
  • Example :

 Valid

 Invalid

 sum

switch/goto/while 

 emp_name/emp_salary

 emp salary

 emp_age12

12emp_age 

 _Age

Age_ 


Operators

An operator is a symbol that perform certain mathematical and logical operation on operator. It is define as an action upon the two possible values. This type of operation is strictly defined for any set of date.
Example : A + B where A & B are operands '+' is operator. 

According to utilization and action operator are classified as :
  1. Arithmetic Operator
  2. Relational Operator
  3. Logical Operator
  4. Assignment Operator
  5. Increment / Decrement Operator
  6. Conditional Operator
  7. Bitwise Operator
  8. Special Operator

1. Arithmetic Operator

Arithmetic Operators are the operators which are used to perform mathematical calculations like addition (+), subtraction (-), multiplication (*), division (/) and modulus(%). It performs all the operations on numerical values (constants and variables).

 Operator

Meaning 

Example 

Add 

A + B 

 -

Sub 

A - B 

 *

Mul 

A * B 

 /

Div 

A/B 

 %

Modulo 

A%B 



2. Relational Operator 

Relational Operator are specifically used to compare two quantities or values in a program. It checks the relationship between two operands.

 Operator

Meaning 

Example 

 >

Greater than 

A>B 

 >=

Greater equal to 

A>=B 

 <

Less than 

A<B 

 <=

Less equal to 

A<=B 

 = =

equal to 

A= =B 

 !=

No equal to 

A!=B 



3. Logical Operator

An operator are used to compare and evaluate logical expressing. Then operator produce result either true (1) or false (0) form.

 Operator

Meaning 

Example 

 &&

Logical AND 

(a>b && a>c) 

 ||

Logical OR 

(a>b || a>c) 

 !=

Logical NOT

a!=b 


4. Assessment Operator 

An assignment operator is mainly responsible for assigning a value to a variable in a program. It is used to assign the result of an expression to a variable.
 shorthand assignment operator as

Expression 

Shorthand 

 a = a+b

a+ = b 

 a = a-b

a- = b 

 a = a*B

a* = b 

 a = a/b

a/ = b  

 a = a%b

a% = b 


5. Increment / Decrement Operator 

An operator which is used in increment / decrement value of an operands by one. It is also called unary operator because it takes only one operand for manipulation.

 Operator

Meaning 

 a++

a = a + 1 

 a--

a = a - 1 


6. Conditional Operator

An operator which takes pair of operator ("?") to evaluate an expression. It is also called Ternary operator because its takes three operands for manipulation.
Syntax:
Expression ? Result 1 : Result 2

Example 
        If a = 5, b = 6
            a>b? 10:20
Note : if condition is true result is first else result is second.
            Hence, Result is 20. 


Comments

Popular posts from this blog

BCA mathematics -I (Unit I Set)

 .

BCA Mathematics -I (Unit I Complex Number)

 .

BCA Mathematics -I (Unit I Natural Number)

.