DATA TYPES AND OPERATORS IN C
CHAPTER 2
DATA TYPES , USER I/O OPERATORS
DATA TYPES
DATA TYPES
Thedatatypespecifythetypeofdatathatavariablecanstore.
• A datatype 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
• ANSI C supports three classes of data types.
1. Primary or Fundamental data types.
2. User-defined data types.
3. Derived data types.
Primary Data Types
Primary Data Types
C provides 5 primary or fundamental data types
- Character- char
- integer- int
- floating point -float double
- void.
Extended data type
We can also use the short, long, signed and unsigned keywords to extend the primary data types. So, they are called extended data types
Primary Data Types in C

Integer Types
Integer Types
Size and Range Of Data types on 16 bit machine
Floating Point Types
VOID
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. • Thegeneralformistypedeftypeidentifier; 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. • enumidentifier{value1,value2,......valuen}; |
Derived data type |
• C allows a different types of derived data structure • Different types of datatypes are • Pointer |
DECLARATION OF VARIABLES |
• Declarationsdoestwothings: Primary Type Declaration • The syntax is Eg: int count; |
User-defined type declaration |
|
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. Declaring a variable as volatile •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 |
C language has standard libraries that allow input and output in a program. The stdio.h or standard input output library in C that has methods for input and output. |
scanf() function |
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. |
Comments
Post a Comment