Unit 2 Data Types
Unit 2 Data Types
STRUCTURED DESIGN
Prof.RITU JAIN, Asst. professor
Computer Science & Engineering
CHAPTER-2
DATA TYPES,USER I/O AND OPERATORS
DATA TYPES
• The data type specify the type of data that a variable can store.
• 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
DATA TYPES
• ANSI C supports three classes of data
types.
We can also use the short, long, signed and unsigned keywords to extend the primary data types.
The void data type is generally used with function to denote that function is return nothing
User-defined type declaration
• C allows user to define an identifier that would represent an existing data type.
• The general form is typedef type identifier;
Eg:
typedef int units;
typedef float marks;
• Another user defined data types is enumerated data type which can be used to
declare variables that can have one of the values enclosed within the braces.
• enum identifier {value1,value2,……valuen};
Derived data type
• C allows a different types of derived data structure
• Different types of datatypes are
• array
• Functions
• Pointer
• Structure
DECLARATION OF VARIABLES
• Declarations does two things:
⮚ It tells the compiler what the variable name is
⮚ It specifies what type of data the variable will hold
• Another user defined data types is enumerated data type which can be used to declare variables
that can have one of the values enclosed within the braces.
• enum identifier {value1,value2,……valuen};
User-defined type declaration
Declaring a variable as constant
Eg:
const int class_size=40;
• This tells the compiler that the value of the int variable class_size must not be modified by the program.
•By declaring a variable as volatile, its value may be changed at any time by some external source.
Eg:
volatile int date;
USER I/O
The scanf() method, in C, reads the value from the console as per the type specified.
Syntax:
scanf(“%X”, &variableOfXType); where %X is the format specifier in C.
Printf()function
The printf() method, in C, prints the value passed as the parameter to it, on the console screen.
Syntax: