Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +917541905230, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Wednesday, June 17, 2020

Data types in C

Data type: is used to define the type of data that a variable can hold. For example: An integer variable can hold integer type data, etc.

Data types in C | welcome2protec.com


Data type: is used to define the type of data that a variable can hold. For example: An integer variable can hold integer type data, a character variable can hold character type data, a float variable can hold float type data etc.

For Example: int is a data type used to define integer type variables. int a here, a is a variable of int (integer) type. It can store numbers from -2,147,483,648 to +2,147,483,647. And the size of int is 4 bytes.

Note: every variable which is to be used in the program must be declared as what data type it is.


C language has some set of predefined data types to handle various kinds of data that we can use in our program. These data types have different storage capacities.

C language supports different types of data types:

  1. Primary or Primitive data types: These are fundamental data types in C namely integer (int), floating point (float), character (char), double and void. Primary is also known as built-in or pre-defined data types.
  2. Derived data types: Array, pointer, and function.
  3. User defined data type: This data types are nothing but primitive data types, but a little twisted or grouped together such as Structure, Union, Enum.

  4. Types of data types | welcome2protec

Built-in or Primitive data type:

Primitive types are the most basic data types in c programming language. such as int, char, float, double, void. Primitive data types are also known as predefined data type or basic data types.

Note: The memory size of basic data types may change according to 32 bit to 64 bit operating system.

Let's see the list of pre-defined or basic data type.


  1. Data typeSizeRangeDescription
    char1 byte-128 to +127A character
    int2 or 4 byte-32,768 to 32,767 or
    -2,147,483,648 to +2,147,483,647
    An integer
    float4 byte1.2E-38 to 3.4E+38Single precision floating point number
    void1 byteVoid type stores nothing

int (Integer type):

In C programming, int (stands for integer) is a keyword used to define integer type variables before to use in a program.

Size of int is 2 or 4 bytes (according to 32 bit or 64 bit operating system) Older system stored int as 2 bytes within a range of -32,768 to 32,767. But now it's takes up 4 bytes and can range from -2,147,483,648 to 2,147,483,67.

For Example: int is a data type used to define integer type variables. int a here, a is a variable of int (integer) type. It can store numbers from -2,147,483,648 to +2,147,483,647. And the size of int is 4 bytes.


char (character type):

Any character value in C stores a singal character and requires a singal byte (1 byte) of memory in almost all compilers within a range -128 to 127.

For Example: char grade = 'A' where grade is defined as character type variable it can store any value of char type within char range as mentioned above.


float double and long double type:

Real numbers are represented in C with keywords float, double and long double. float defines a singal precision floating point number that can store 1.2E-38 to 3.4E+38. Whereas double defines double precision floating point numbers that can store 2.3E-308 to 1.7E+308.

Precision: Number of digits after the decimal point is called precision. For example: 23.3456 has precision four and 23.34 has two precision. By default Float has 6 decimal digits of precision and double has 15 decimal digits of precision.

Example to define float type variables:

/*Float has 6 decimal digits of precision */
 float average = 89.330000
  
/*Float has 6 decimal digits of precision */
 double percentage = 93.330000000000000

void type:

In C programming, void means nothing, that means it does not store anything. It has different meaning in different places: When void is used as a function return type, it indicates that the function does not return a value. when void appears in a pointer declaration, it specifies that pointer is universal. When void is used in a function parameter list, it indicates that function takes no parameters.

For now you don't worry about void type, we will learn with example in later section of this programming tutorial.


User defined data type:

Those data types which are defined or created by the user using primitive data type as per our need are known as user defined data types. For example: Structure, Union, and Enumeration.

Let's understand with a simple example how to create a user defined data type:

struct student{
  char name[50];
  int roll;
  float marks;
};

In above example, student is a new data type created by user with the help of primitive data types char, int and float.











Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Help others by sharing this page.

Ahmad Irshad

Author & Editor

I love blogging, teaching, learning computer science and sharing it to others. I've written and develped this site so that students may learn computer science related tutorials eaisly. MCA / MCITP

0 Comments:

Post a Comment

Please don't enter any spam link in the comment box.


Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec
Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec
Contact Us