Data Type and Operator

Post on 22-Feb-2016

37 views

Category:

Documents

DESCRIPTION

Data Type and Operator. By: Muhammad Zidny Nafan. Data Type. Declaration. Data type and variable declaration: data_type variable_name; Set a value to variable: variable = value; We can directly set a value to varible when declaration: data_type variable_name = value;. - PowerPoint PPT Presentation

TRANSCRIPT

Data Type and Operator

Data Type and OperatorBy: Muhammad Zidny Nafan

Data Type

Data type and variable declaration:data_type variable_name;Set a value to variable:variable = value;We can directly set a value to varible when declaration:data_type variable_name = value;

DeclarationModification of Data Type

Operator the sign that use for operating or manipulation

Variable or value that operated called the operandOperator3 + 2operandoperandoperatorArithmetic OperatorOperatorInformationExample*multiply2 * 3/divide7 /2%modulus 5 % 4 = 1+add4 + 5-subtraction5 6 Using arithmetic operatorArithmetic Operator

To give a value to variable Ex:a = 1;c = 2 + (b = 1);a = b = c = d = e = 1;Assignment OperatorSymbol of decrement operator: -- Used for subtracting by 1

The symbol of increment operator: ++ used for adding by 1Ex:x++ like with x = x + 1.y-- like with y = y 1.

Can be placed front (pre-) or behind (post-) operand.

Increment and Decrement OperatorThe effect for placing the operator:a = 7;b = 2;c = b + a++;value of c is 9 not 10that statements above like with this statement below:c = b + a;a = a + 1;

Increment and Decrement OperatorIf increment operator placed in front of operand, so operand will add by 1 first. Ex:a = 7;b = 2;c = b + ++a;that statements above like with this statement below:a = a + 1;c = b + a;c = 10;

Increment and Decrement OperatorFor manipulating bitBitwise operator only for int or char

Bitwise OperatorOperatorInformationExample~Bitwise NOT~25> 2& Bitwise AND25 & 2^Bitwise XOR25 ^ 2|Bitwise OR25 | 2Example

Bitwise Operator

shorten assignment operator, Example x = x + 2 x += 2Compound OperatorCompare the relationship between two operands

Relationship OperatorOperatorInformation==Equal!=Not equal

More than=More than or equalEx

Relationship Operator

Obtain the value of two possibles, ex:statement1 ? statement12: statement3

If statement1 true than the result equal with statement2, if false than statement3.

Condition OperatorContoh:

Condition Operator

Placing two statement in one rule that need one statementExample use in looping for:for(i=0, j=0; i