video n.
Skip this Video
Loading SlideShow in 5 Seconds..
VIDEO PowerPoint Presentation
Download Presentation
VIDEO

Loading in 2 Seconds...

  share
play fullscreen
1 / 18
Download Presentation

VIDEO - PowerPoint PPT Presentation

will
138 Views
Download Presentation

VIDEO

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. VIDEO

  2. Variables, Constants and Data Types Variables, Constants and Data Types Modifiers Keywords

  3. Temperature => default value / size for data type • Items => data types

  4. Objective • At the end of the class, student able to; • Student able to explain modifier concept by using their own word • Student able to explain in writing form about 4 data types modifier by using their own word correctly • Student able to list out 4 type of keywords in C Programming

  5. Modifiers • The modifiers define the amount of storage allocated to the variable. • ANSI has the following rules: short int <= int <= long int float <= double <= long double What this means is that a 'short int' should assign less than or the same amount of storage as an 'int' and the 'int' should be less or the same bytes than a 'long int'.

  6. Basic data type

  7. what this means in the real world is:

  8. Example. • Let us consider an example of a program, which will accept an age from the user to do some processing. Because the age is represented in numbers, so we will have to use the integer data type int. We all know that even under exceptional case an age of a person cannot exceed more than 150. Now, that we are using an integer data type it occupies 2 Bytes of memory, which would not be required to represent the value 150. Instead the value 150 could easily be saved in an integer of 1 Byte in size, but the default size of an integer is 2 Bytes. So we have a problem here.

  9. Data type modifiers 1. signed 2.unsigned 3.long 4. short

  10. Data Type Modifiers • signedBy default all data types are declared as signed. Signed means that the data type is capable of storing negative values. • unsigned To modify a data type’s behavior so that it can only store positive values, we require to use the data type unsigned. For example, if we were to declare a variable age, we know that an age cannot be represented by negative values and hence, we can modify the default behavior of the int data type as follows: unsigned int age; This declaration allows the age variable to store only positive values. An immediate effect is that the range changes from (-32768 to 32767) to (0 to 65536)

  11. Continue.. • longMany times in our programs we would want to store values beyond the storage capacity of the basic data types. In such cases we use the data type modifier long. This doubles the storage capacity of the data type being used. E.g. long int annual salary will make the storage capacity of variable annual salary to 4 bytes. • The exception to this is long double, which modifies the size of the double data type to 10 bytes. Please note that in some compilers this has no effect. • short If long data type modifier doubles the size, short on the other hand reduces the size of the data type to half. Please refer to the example of age variable to explain the concept of data type modifiers. The same will be achieved by providing the declaration of age as follows: short int age; • This declaration above, will provide the variable age with only 1 byte and its data range will be from -128 to 127.

  12. continue • Sintaks : • <modifier> data type = <nilai_awal>; • Contoh : • unsigned int Jumlah_Mahasiswa=40; • signed float Suhu_Celcius = 36.5; • unsigned long int Total_Jumlah_Penduduk; • short Tinggi_Rumah; // bererti integer • long Jarak_Antar_Kota; // bererti integer

  13. Exercises

  14. Keywords • Definition : Keywords are reserved words for which the meaning is already defined to the compiler. • There are 32 keywords in C Language :

  15. Playing with dart.. • Identify which of the following are valid identifiers. If invalid, explain why. ABCDE FGHIJ

  16. Summary • Modifiers define the amount of storage allocated to the variable. • Data Types Modifiers - signed • unsigned • long • Short

  17. 3 . Keywords are reserved words for which the meaning is already defined to the compiler. • Data types, modifiers and storage class specifiers • User defined data types and type related • Conditional • Flow control

  18. Maklumattambahan: • http://www.sunilb.com/c-programming/c-tutorial-constants-variables-and-data-type-modifiers • E-book : page 26. CARILAH ILMU HINGGA KE NEGERI CINA GOOD LUCK..