Presentation is loading. Please wait.

Presentation is loading. Please wait.

Objectives A data type is  A set of values AND  A set of operations on those values A data type is used to  Identify the type of a variable when the.

Similar presentations


Presentation on theme: "Objectives A data type is  A set of values AND  A set of operations on those values A data type is used to  Identify the type of a variable when the."— Presentation transcript:

1 Objectives A data type is  A set of values AND  A set of operations on those values A data type is used to  Identify the type of a variable when the variable is declared  Identify the type of the return value of a function  Identify the type of a parameter expected by a function CoxSimple Data Types 1

2 01-April-2013Simple Data Types 2 Two Classifications of Data Types Built-in data types  Fundamental data types ( int, char, float )  Derived data types (array, string, structure) Programmer-defined data types  Structure  Union  Enumeration

3 01-April-2013Simple Data Types 3 Data types in C Only really four basic types:  char  int (short, long, long long, unsigned)  float  double Size of these types on CLEAR machines: Sizes of these types vary from one machine to another! TypeSize (bytes) char1 int4 short2 long8 8 float4 double8

4 01-April-2013Simple Data Types 4 Integers Definition: - Integer is a fundamental (i.e. built into the compiler) type used to define numeric variables holding whole numbers.variables Example:- Integer is short for integer. As only whole numbers can be stored in an Int variable. 7, 4908 or -6575 are ok. 5.6 is not. Numbers with fractional parts requires a float type variable.float

5 01-April-2013Simple Data Types 5 Non-Integral Numbers: How? Fixed-size representations  Rational numbers (i.e., pairs of integers)  Fixed-point (use integer, remember where point is)  Floating-point (scientific notation) Variable-size representations  Sums of fractions (e.g., Taylor-series)  Unbounded-length series of digits/bits

6 01-April-2013Simple Data Types 6 Floating-point Definition: Float is short for floating point and is a fundamental (i.e. built into the compiler) type used to define numbers with fractional parts.type Example:- The float type can represent values ranging from approximately 1.5 × 10 −45 to 3.4 × 10 38 with a precision of 7 digits.precision

7 01-April-2013Simple Data Types 7 FP Overflow & Underflow Binary version of scientific notation 1.001101110 × 2 5 = 100110.1110 = 38.875 binary point

8 01-April-2013Simple Data Types 8 String:- Definition:- Strings are arrays of chars. String literals are words surrounded by double quotation marks. Example:- To declare a string of 49 letters, you would want to say: char string[50]; This would declare a string with a length of 50 characters. Technically, in a fifty char array you could only hold 49 letters and one null character at the end to terminate the string.

9 Character:- Definition: - A char is a type of variable that holds a character in C and Ca. char is 8 bits, which is the same size as a byte.typevariablebyte Example:- In c programming we define a character as: char ch=‘A’ 01-April-2013Simple Data Types9

10 Program:- #include void main(void) { char ch=‘A’ string[]=“My College”; int num=2; float fnum=2; clrscr(); printf(“character =%c\n”,ch); printf(“string=%s\n”); printf(“integer =%d\n”,num); printf(“float =%f\n”,fnum); getch(); } Cox & NgSimple Data Types10

11 01-April-2013Simple Data Types11


Download ppt "Objectives A data type is  A set of values AND  A set of operations on those values A data type is used to  Identify the type of a variable when the."

Similar presentations


Ads by Google