Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ch 4 - 1 Chapter 4 Basic Data Types and Variables 4.1 Basic Data Types In C TABLE 4.1 Introduction to Basic Data Types in C Type SizeDescription char 1.

Similar presentations


Presentation on theme: "Ch 4 - 1 Chapter 4 Basic Data Types and Variables 4.1 Basic Data Types In C TABLE 4.1 Introduction to Basic Data Types in C Type SizeDescription char 1."— Presentation transcript:

1 Ch 4 - 1 Chapter 4 Basic Data Types and Variables 4.1 Basic Data Types In C TABLE 4.1 Introduction to Basic Data Types in C Type SizeDescription char 1 byte Characters or small integer variables int 2 or 4 bytes Integer values float 4 bytes Floating point numbers double 8 bytes Floating point numbers

2 Ch 4 - 2 4.2 CHARACTERS The Standard for Text: ASCII(American Standard Code for Information Interchange) was first defined by the American National Standards Institute in 1986. In this code, each letter of the alphabet, punctuation mark, and decimal number is assigned a unique 7-bit code number. With 7 bits, 128 unique symbols can be coded. See Table 4.2.

3 Ch 4 - 3 TABLE 4.2 ASCII Character Format

4 Ch 4 - 4 4.2.1 Defining Character Variables in C Program 4.1: C Program Containing Variables int main ( void ) { /* Beginning of the (main) block.*/ Char cAChar;/* We put variable definitions here.*/ cAChar = 65 ;/* Executable statement : assign the */ /* code for ‘A’ to “cAChar”*/ }/* End of (main) block */

5 Ch 4 - 5 4.2.2 Character Constants cAChar = ‘A’ ;/*assign ‘A’ to character */ /* variable “cAChar” */

6 Ch 4 - 6 4.2.3 Escape Characters

7 Ch 4 - 7 Remark 4.2

8 Ch 4 - 8 4.3 INTEGERS Consider for example the declarations int iPennies; int iCounter; Initial Values can also be supplied in definitions, as with int iCounter = 0; int iNickels = 5;

9 Ch 4 - 9 4.3.1 Short and Long Integers short<=int<=long

10 Ch 4 - 10 4.3.2 Unsigned Integers Ex: unsigned int uiPennies; unsigned uUpCounter;

11 Ch 4 - 11 4.4 SINGLE AND DOUBLE PRECISION FLOATING POINT NUMBERS

12 Ch 4 - 12 4.4.1 Floating Point Variables Floating point variables and constants: 3.4,-45.33,2.714, Exponential notation: 3.0e-25,4.5e+05,2.345678e+19,

13 Ch 4 - 13 Figure 4.2

14 Ch 4 - 14 Table 4.5

15 Ch 4 - 15 Program 4.2 : Print size of some basic data types

16 Ch 4 - 16 接續 Program 4.2

17 Ch 4 - 17 4.5 ENUMERATION DATA TYPES enum weekday { Mon, Tue, Wed, Thu, Fri, Sat, Sun }; or enum dayofweek { Mon=1, Tue, Wed, Thu, Fri, Sat, Sun }; Program 4.3

18 Ch 4 - 18

19 Ch 4 - 19 4.6 VARIABLE ATTRIBUTES: TYPE, ADDRESS, NAME, AND VALUE int iVal = 10; Type Name Value

20 Ch 4 - 20 Program 4.4

21 Ch 4 - 21

22 Ch 4 - 22 4.7 VARIABLE NAMING CONVENTIONS A variable name cannot start with a digit, and it cannot have the same as a reserved word.

23 Ch 4 - 23 An appropriate name name for our count variable: int iCount ; unsigned int uiCount ; unsigned uCount;

24 Ch 4 - 24


Download ppt "Ch 4 - 1 Chapter 4 Basic Data Types and Variables 4.1 Basic Data Types In C TABLE 4.1 Introduction to Basic Data Types in C Type SizeDescription char 1."

Similar presentations


Ads by Google