Explanation about the term Data type
What are data types in C?
C is strongly typed language. C language is rich in its data types and also supports a wide variety of data types. In C, data types can be broadly classified as
Primary Data Types
All C compiler support the following primary or standard or basic or fundamental data types are namely
Classification of Primary Data types
int data type
Character data type
Character data type is used to represent individual characters. The char data type generally needs one byte of memory for their storage. In order to have control over the range of characters, signed and unsigned character data types are used, both occupying one byte each, but having different ranges. How a char can have a sign?
Consider the statement, char ch=’A’; here, the binary equivalent of the ASCII value of ‘A’ (that is, binary of 65) is stored in the variable ch. The binary equivalent of -54 can also stored, in a signed char. A signed char is same as an ordinary char and has a range from -128 to 127, whereas, an unsigned char has a range from 0 to 255. What happens when we attempt to store +128 in a char?
The first number on the negative side, i.e, -128 gets stored. This is because from the 9-bit binary of +128, 010000000, only the right-most 8 bits get stored. But when 10000000 is stored the left-most bit is 1 and it is treated as a sign bit. C deals with several kinds of numbers.
float (Single-Precision floating point type)
double(double-precision floating point type)
long double data type
Type Definition
C supports a feature known as ‘type definition’ that allows users to define an identifier that represent an existing data type. Note that, the keyword typedef is used to define new data type names, not actually creating a new data type, but defining a new name for an existing data type. The general form of defining a new data type is typedef datatype identifier;
typedef int age; where age symbolizes int typedef float average; where average symbolizes float The user-defined data type identifier can be later used to declare variables as, age child, adult; Where, child and adult are declared as integer variables average mark1, mark2; Where, mark1 and mark2 are declared as floating-point variables.
{ char name[30]; int age; float bs; }; typedef struct employee EMP; EMP e1; struct employee { char name[30]; int age; float bs; }; typedef struct employee *EMP; EMP e1; Enumerated Data type
An enumerated data type is another user-defined type which provides a way for attaching names to numbers, thereby increasing comprehensibility of the code. The enumerated data type gives an opportunity to invent your own data type and define what values the variable of this data type can take. This can help in making the program listings more readable, when a program gets complicated or when more than one programmer would be working on it. Using enumerated data type can also help reduce programming errors. General Form enum identifier { enumeration_list } list_of_variables; The declaration has two parts; 1)The first part declares the data type and specifies its possible values. These values are called ‘enumerators’. 2)The second part declares variables of this data type. where, enum is a keyword, which is used to specify the enumerated data type,
enum week { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday } day1, day2;
Enumerated variables are usually used to clarify the operation of a program.
/* understand about enumeration list */ #include <stdio.h> #include <conio.h> main() { enum empDepartment { assemply, manufacturing, accounts, stores }; struct employee { char name[30]; int age; float bs; enum empDepartment department; }e; strcpy(e.name,”Raja”); e.age=28; e.bs=5575.50; e.department=manufacturing; printf("\nName = %s", e.name); printf("\nAge = %d", e.age); printf("\nBasic salary = %f", e.bs); printf("\nDepartment = %d", e.department); } |
Qualifiers are used to provide some control over the numbers and storage space. Depending upon the qualifiers, the integer data type can be classified as
Signed type
Unsigned type
16-bit compiler: A 16-bit compiler like Turbo C or Turbo C++ means that when it compiles a C program it generates machine language code that is targeted towards working on a 16-bit microprocessor like Intel 8086/8088. TC/TC++ performs all float operations using a software piece called Floating Point Emulator. This emulator has limitations and produces less accurate results. Also this emulator becomes part of the EXE file and also the bigger code would take more time to execute. Two bytes used to store an integer, the highest bit (16th bit) is used to store the sign of the integer. This bit is 1 if the number is negative and 0 if the number is positive.
32-bit compiler: A 32-bit compiler like VC++ means that when it compiles a C program it generates machine language code that is targeted towards working on a 32-bit microprocessor like Intel Pentium. For example, 22.0/7.0 would be reported more accurately by VC++ compiler as compared to TC/TC++ performs compilers. Four bytes used to store an integer, the highest bit (32nd bit) is used to store the sign of the integer. This bit is 1 if the number is negative and 0 if the number is positive.
Note: - A program compiled using Turbo C would run successfully but that time the 32-bit processor would work as if it were a 16-bit processor. This happens because a 32-bit processor provides support for programs compiled using 16-bit compilers. If this backward compatibility support is not provided the 16-bit program would not run on it. Derived data types are based on fundamental data types. i.e. a derived data types is represented in the memory as a fundamental data type.
|
- Home
-
C Language
- C++
- Java
-
B.C.A
- Subject Details
- COBOL
- Digital Logic Fundamentals
- Fundamental of Digital Computers
- Microprocessor and its applications
- Programming in C
- Computer Graphics
- Operating System
- Programming in C++ and Data Structures
- DBMS
- Programming in Java
- Data Communication and Networking
- Software Engineering
- Software Testing
- Web Technology
- Elective - I >
- Elective - II >
- Elective - III >
- Maths Questions >
- English
-
B.Sc
- B.Sc (Cs) Subject Details
- Computer Architecture and Organization
- Digital Electronics and Microprocessor
- Data Structure Using C++
- Microprocessor and Its Applications
- Programming in C
- Programming in C++ and Data Structures
- Programming in Java
- Visual Programming
- Operating System
- DBMS
- Software Engineering
- Data Communication and Networking
- Software Testing
- Web Technology
- Computer Networks
- OOAD
- Multimedia Systems
- M.C.A
- M.Sc (CS)
- M.Sc (IT)
- Conduct Us
- Programming Language
- Programming Logic
- Computer Terms
- Job Selection Process
- Learn English Using Tamil
- Spoken English in Tamil
- Conversational Tamil
- English
- Interview