Data type and operator
Download
1 / 24

Data Type and Operator - PowerPoint PPT Presentation


  • 118 Views
  • Uploaded on

Data Type and Operator. By: Muhammad Zidny Naf’an. 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;.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Data Type and Operator' - reya


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Data type and operator

Data Type and Operator

By: Muhammad Zidny Naf’an



Declaration
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;



Operator
Operator

Operator the sign that use for operating or manipulation

Variable or value that operated called the operand

3 + 2

operand

operator

operand



Arithmetic operator1
Arithmetic Operator

  • Using arithmetic operator


Assignment operator
Assignment Operator

  • To give a value to variable

  • Ex:

    a = 1;

    c = 2 + (b = 1);

    a = b = c = d = e = 1;


Increment and decrement operator
Increment and Decrement Operator

  • Symbol of decrement operator: --

    Used for subtracting by 1

  • The symbol of increment operator: ++

    used for adding by 1

    Ex:

    x++ like with x = x + 1.

    y-- like with y = y – 1.

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


Increment and decrement operator1
Increment and Decrement Operator

  • The effect for placing the operator:

    a = 7;

    b = 2;

    c = b + a++;

    value of c is 9 not 10

    that statements above like with this statement below:

    c = b + a;

    a = a + 1;


Increment and decrement operator2
Increment and Decrement Operator

  • If 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;


Bitwise operator
Bitwise Operator

  • For manipulating bit

  • Bitwise operator only for int or char



Compound operator
Compound Operator

  • shorten assignment operator,

  • Example x = x + 2 x += 2


Relationship operator
Relationship Operator

  • Compare the relationship between two operands



Condition operator
Condition Operator

  • Obtain the value of two possibles, ex:

    statement1 ? statement12: statement3

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



Comma operator
Comma Operator

  • Placing two statement in one rule that need one statement

  • Example use in looping for:

  • for(i=0, j=0; i<10; i++, j--) { ..}


Logic operator
Logic Operator

  • Connecting two or more statements to make one condititon statement



Exercise
Exercise

  • If x is integer, from these values, where the value can put to x?

  • 10

  • 5.7

  • 40000

  • Change these formulas into C++ language


Exercise1
Exercise

  • A program to calculate the final score of a student has 5 variables for student name, studentidentification numbers, the value of the task, the mid term and final exam scores of the semester. The final value calculated by the formula: (task * 20%) + (midterm * 40%) + (final exam * 40%). Make the program!


Exercise2
Exercise

Write the program to display the number of days, hours, minutes, and seconds of inputin the form of the length of time in seconds. For example, input 100.000 seconds willproduce output 

1 day, 3 hours, 46 minutes, 40 seconds.Input of the program is of type long integer.Program output is the number of days, hours, minutes, and seconds from the input.


ad