Download presentation
Presentation is loading. Please wait.
Published byRobert McLaughlin Modified over 9 years ago
1
Data Types
2
Data types Data type tells the type of data, that you are going to store in memory. It gives the information to compiler that how much memory ( No. of bytes ) will be stored by the variable.
3
Types of data types. 1.Primary data types. 2.User-defined data types. 3.Derived data types. 4.Empty data set.
4
1. Primary Data Type 1.Integral Type 1.1. Character 1.1.1 signed char 1.1.2 unsigned char 1.2. Integer 1.2.1 Signed type int short int long int 1.2.2. Unsigned Type unsigned int unsigned short int unsigned long int 2. Floating Point Type 2.1. float 2.2. double 2.3. long double
5
Variable Type C has the following simple data types:
6
Basic Types Type (16 bit)Smallest ValueLargest Value short int-32,768(-2 15 )32,767(2 15 -1) unsigned short int065,535(2 16 -1) Int-32,76832,767 unsigned int065,535 long int-2,147,483,648(-2 31 )2,147,483,648(2 31 -1) unsigned long int04,294,967,295
7
Basic Types Type (32 bit)Smallest ValueLargest Value short int-32,768(-2 15 )32,767(2 15 -1) unsigned short int065,535(2 16 -1) Int-2,147,483,648(-2 31 )2,147,483,648(2 31 -1) unsigned int04,294,967,295 long int-2,147,483,648(-2 31 )2,147,483,648(2 31 -1) unsigned long int04,294,967,295
8
Floating Types float single-precision floating-point double double-precision floating-point long double extended-precision floating-point TypeSmallest Positive Value Largest ValuePrecision float1.17*10 -38 3.40*10 38 6 digits double2.22*10 -308 1.79*10 308 15 digits double x; long double x; scanf(“%lf”, &x); scanf(“%Lf”, &x); printf(“%lf”, x); printf(“%Lf”, x);
9
2. User – Defined Data Type C supports a feature of “type definition” that allows user to define an identifier that would represent an existing data type. User – defined data type identifier can later be used to declare variables such as: typedef enum The general form for given above user – defined data type is as follows: typedef datatype identifier; enum identifier {value1,value2,…..valuen};
10
3. Derived Data Type C Compiler supports following derived data type: 1. Array 2. Function 3. Structure 4. Pointer
11
4. Empty Data Set The C Compiler supports the Empty data set which is mainly described in functions. The “void” is an Empty data set.
12
printf() and scanf() printf() is used for printing formatted output. scanf() is used for reading formatted input. Both have a list of arguments. control_string and other_arguments
13
Conversion Characters 13 Conversion Character Interpretation cCharacter ddecimal integer ffloating-point number ( float ) lffloating-point number ( double ) Lffloating-point number ( long double ) sstring
14
Type Conversion long double double float Unsigned long int long int unsigned int int
15
Type Conversion char c; short int s; int i; unsigned int u; long int l; unsigned long int ul; float f; double d; long double ld; i = i + c; /* c is converted to int */ i = i + s; /* s is converted to int */ u = u +i; /* i is converted to unsigned int */ l = l + u; /* u is converted to long int */ ul =ul + l; /* l is converted to unsigned long int */ f = f + ul; /* ul is converted to float */ d = d + f; /* f is converted to double */ ld = ld + d; /* d is converted to long double */
16
Casting ( type-name ) expression float f, frac_part; frac_part = f – (int) f; float quotient; int dividend, divisor; quotient = (float) dividend / divisor; short int i; int j = 1000; i = j * j; /* WRONG */
17
Storage Classes Every C variable has a characteristic is called its storage class. The Storage class defines two characteristics of the variable. – Lifetime – Visibility (Scope) Lifetime :- The lifetime of a variable is the length of time it retains a particular value. Visibility :- The visibility of a variable refers to which parts of a program will be able to recognize it. A variable may be visible in a block of function, a file, a group of files, or an entire program.
18
Storage Classes AutomaticExternalStaticRegister StorageMemory Register Default Initial value Garbage ValueZero Garbage value ScopeLocal to the block GlobalLocal to the block LifeTill the control remains in the block As long as the program’s execution doesn’t come to an end Value of variable persists between different function call Till the controls remains in the block
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.