Skip to main content

Data Types in C-Programming Language

A program usually contains differnt types of data elements and need to store the values being used in program.
C-language has different data types for different types of data and can be broadly classified as :
1• Primary Data types
2• Secondary Data types

Primary Data Types

The primary data type is used for representing a single value only .It is also called simple or fundamental data type. As these are used at primary level in the high level language ,so these are called primary data type .Simple data types has some standard data types.

    These are subdivided into 4 categories:

1• Integer data type
2• Floating point data type
3• Character data type
4• Void data type

1• Integer Data Types

Generally and integer occupies 2Bytes memory space and its value range  Limited to - 32768 to + 32768 .A signed integer use 1 bit for storing sign and rest 15 bits for number.
Range of an unsigned integer is from 0 to 65535 .The long integers are used to declare a longer range of values and it occupies 4 bytes of storage space.

  The general syntax is:
   int <variable name>;

Like :  int num1;
Example: 5,6,100

2• Floating Point Types

These are further divided into 2 types:
(a) Float Data Type:
          Storage size         4 bytes
          Range                    3.4E-38 to 3.4E +38
          Precision              6 digits
  General Syntax is: float<variable name>;
        Like : float num1;
Example: 9.1 , 3.12

(b) Double Data Type:
    Storage size           8 bytes
    Range                      1.7E-308 to 1.7E+308
  General Syntax is: double<variable name>;
        Like : double num;
  Example: 9.125 , 3.1254

3• Character Data Types
    Storage size     1 byte for   both 
                                 signed and unsigned      
                                  chars.
     Range              0 to 255 for unsigned
                                chars
                              -128 to +127 for signed
                                chars

General Syntax is: char<variable name>;
Like : char ch ='a';
Example: a,h,l

4• Void Data Type
The void type has no values therefore we cannot declare it as variable as we did in case of integer and float.
       The void data type is usually used with function to specify its type.

Secondary Data Types

     Secondary data types are derived from the primary data type by adding some additional relationship with the various elements of the primary data types .As these data types have different structure depending on the C-coding these are also called structured data type these are also called Derived data type.

         These are further subdivided into four categories:
1. Array & String Data Types
2. Pointer Data Type
3. Structure & Union Data Type
4. User Defined Data Types

1• Array & String Data Types

  (a). Array Data Type: Array is  set of homogeneous data elements. It is a collection of same types of elements.
       An array is a group of related data items , which share common name.
   General Syntax is:
     data type   array name [size];
     Or
   data type array name[subscript1][subscript2];

Example:
int salary[10]; (integer is of 2 bytes.Size 10 integers means 2*10=20 bytes)

int matrix[2][2];

(b) String Data Type: Combination of characters is called string. String data type is used to store only character data.
   If the string is stored in variable then such type of variable should be of character type.

General Syntax is:
data type string_name[size];
Example:char city[10];
                 char city[10][20];

2• Pointer Data Type
    A pointer is a memory variable that stores memory address. Pointer can have any name that is legal for other variable and it is declared in the same fashion like other variables but it is always denoted by '*' operator.
General Syntax is:
     datatype      *pointer_variable;
Example: int *x;
                  float *f;

3• Structure & Union Data Type
   Structure and union data types are also called heterogeneous data types .They are used to store different types of data elements together using common name.

(a) Structure Data Type: A structured data type is a collection of data elements that are referenced under one name, providing the convenient means of keeping related information together.
General Syntax is:
struct      structure _tag
{
data-type-1       member-1;
data-type-2       member-2;
.
.
.
data-type-n       member-n;
  };

Example:
struct   student
{
char      grade;
int          roll_no;
float      fees;
double  marks;
}st;

Total size=char+int+float+double=
1+2+4+8=15 bytes

(b) Union Data Type: Union is a data type that declares a set of multiple data elements sharing the same name and memory area.
The compiler allocate sufficient memory to hold the largest variable of the union. All the members of union occupy the same memory locations called addresses.
General Syntax is:
union    union _tag
{
data-type-1       member-1;
data-type-2       member-2;
.
.
.
data-type-n       member-n;
  };

Example:
union   student
{
char      grade;
int          roll_no;
float      fees;
double  marks;
}st;

Total size=8 bytes

4• User Defined Type Declaration
  C language supports a feature where user can define an identifier that characterizes an existing data type .This user defined data type identifier can later be used to declare variables .Two types of user defined data types are:

(a) Typedef Data Type: User can define an identifier that represent an existing data type .The user defined data type identifier can later be used to declare variables.
General Syntax is:
typedef <type> <identifier>;
Like: typedef int number;

For example:
"int n1" or "number n1" both statements declaring an integer variable. We have just changed the default keyword "int" to "number" to declare integer variable.

(b) Enumerated Data Type: This is also used for type definition ,that is , it allows the users to define a variable or an identifier which is used for representation of existing data type . In other words ,it provides us a way to define our own data type .

General Syntax is:
enum identifier {v1,v2,v3.....,vn};
Or
enum identifier {v1,v2,v3....,vn}variable;

Here enum is the reserve  word and v1, v 2, v3 ...., vn all are the values which is called enumeration constants.

Example:
enum  month {jan,feb,march};
Or
enum  year {1999,2000,2001}y;

prev
next

Comments

Popular posts from this blog

THE BEST BRAIN TRAINING APPS FOR ANDROID

THE BEST BRAIN TRAINING APPS FOR ANDROID Elevate - Brain Training Elevate is a brain training program designed to improve attention, speaking skills, processing speed, memory, math skills, and more. Each person is provided with his or her own personalized training program that adjusts over time to maximize results. The more you train with Elevate, the more you’ll improve critical cognitive skills that are designed to boost productivity, earning power, and self-confidence. Users who train at least 3 times per week have reported dramatic gains and increased confidence. FEATURES * 35+ brain games for critical cognitive skills like focus, memory, processing, math, precision, and comprehension * Detailed performance tracking * Personalized daily workouts that include the skills you need most * Adaptive difficulty progression to ensure your experience is challenging * Workout calendar to help you track your streaks and stay motivated Peak - Brain Training P

Introduction to Programming language C

Dennis Ritchie ( US) designed C programming language in 1972 at "AT & T's Bell laboratories". C has been often termed as " M iddle Leve l Language " . Programs written in C are very efficient and fast. C is a general purpose structured powerful language. Features at a Glance: • C is highly portable language .This means that a C program written for one system can be run on another system with little or no modifications. • C's another striking feature is its ability to extend itself. We can add our own functions to the C library . • Writing a C program with user defined makes program more simple and easy to understand . • C - language has more data types ( except boolean operators ), operators and can take more variables than other languages. • C - language is a structured programming language that is  it has different modules and blocks . • C - language is used to develop graphics software . 2D and 3D graphics are also implemented using C.

Adding Dialogue Boxes IN HTML5 AND CSS3.

This post is about adding Dialogue Boxes in html. Here is the implementation of the logic. <!DOCTYPE html> <html> <head> <title>HTML dialog Tag</title> </head> <body> <!-- Simple pop-up dialog box, containing a form --> <dialog id="dialog"> <form method="dialog"> <h3> Hello</h3> <menu> <button id="close" type="reset">Close</button> </menu> </form> </dialog> <menu> <button id="click">Click Me</button> </menu> <script> (function() { var clickButton = document.getElementById('click'); var closeButton = document.getElementById('close'); var Dialog = document.getElementById('dialog'); // Update button opens a modal dialog clickButton.addEventListener('click', function() { Dialog.showModal(); }); // Form close button closes the dialog