COMPUTER TRAINING: Operators & Array

Monday, 24 December 2012

Operators & Array

Operators
 
Arithmetic Operators
 
Arithmetic operators are used for mathematical expressions.
 
The given table shows various arithmetic operators and their description:
 
OperatorsSymbolDescription of Symbol
Subtraction-Subtracts two operands (val1-val2)
Addition+Adds two operands (val1-val2)
Multiplication*Multiply two operands (val1*val2)
Division/Divides 2 operands (val1/val2)
Negation~Negates the operand
ModuloModGives the remainder after division (Val1 mod Val2)
String Concatenation&Concatenates two strings (val1 & val2)
Exponentiation^Raises the first operands to the power of second operand (val1^val2)
 
 
 
 
Operators
 
Logical Operators
 
These are also known as Boolean operators.Boolean operators are used in the conditions where condition can be true or false case.
Basically logical operators are used to form logical expressions that represent true or false conditions.
 
For Example:
 
The 'Or' operator returns the result when only one operands is true.
 
The given table summarizes various logical operators and their description:
 
OperatorsDescription of Symbol
NotReturn the negative of two expressions.
AndReturns true only when both conditions are true.
OrReturns true when only one condition is true.
ImpReturns false only when 1st operand is true and 2nd is false.
EqvReturns true only when both conditions are true.
XorReturn true only if both operands are of opposite sign.
 
 
 
 
Operators
 
Relational Operators
 
There are six relational/Comparison operators used in testing expressions.
They are >= (greater than or equal to), <= (Less than or equal to), (less than), >(greater than), <> (Not equal to).
 
Comparison operators are used to compare two expressions.They are also known asrelational operators.
 
The table below contains a list of operators used in Visual Basic:
 
OperatorsFunction
<First expression is less than second.
<=First expression is less than or equal to second.
>First expression is greater than second.
>=First expression is greater than or equal to second.
<>First expression is not equal to second.
=First expression is equal to second.
 
 
 
 
Arrays
 
Introduction of Array
 
An array is the collection of similar data types.The individual elements of an array is identified by using an index.
 
Each index number in an array is allocated individual memory space. Hence users declarearrays of larger size than required.
 
Array helps in creating smaller and simpler code in many situation.You can setup loopsthat deal efficiently with any number of cases by using the index number.
 
loop is used to execute a group of statements repeatedly, based on a condition.
 
 
 
 
 
Arrays
 
Declaration Of Array
Syntax:
Dim arrayname(number) as Datatype
 
Example:
Dim total(10) as integer
 
Here total is name of array ,10 is no of elements in the array & integer is the data type.Number 10 included in the parenthesis is the upper limit of the array.
 
The above declaration creates an array with index numbers ranging from 0 to 9.
 
If you want to specify lower limit ,then the parenthesis should include both the lower and upper limit along with the 'To' keyword.
 
An example is shown below
 
Dim num(1 To 5) As integer
In above statement, an array of 5 element is declared but with the index numbers ranging from to 5.
 
Mainly Visual Basic supports 2 types of Array:
 
Fixed-Size array:
The size of array always remains the same.
 
Dynamic array:
The size of array can be changed at run time.
 
 
 
 

No comments:

Post a Comment