Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

what is data type

+37 votes
asked Feb 6 by himanshu kumar (230 points)

3 Answers

+1 vote
answered Feb 6 by Peter Minarik (82,920 points)
edited Feb 8 by Peter Minarik

Data type tells you what sort of information is stored in your variable. I'll use C language examples below. Every language has its own data types, but the basic data types are very similar across languages.

Let's assume you would like to store some kind of a number, let's say, someone's age. You could store it in an int data type, that represents integral numbers. This data type can only handle whole numbers, no fractions.

If you'd like to store someone's salary, you'd probably use a floating point data type, so fractions could be used. Such a type would be float or double.

If you'd like to store a name, then you would use a string that can store text. In C, you can store a string in a char * data type.

You can also create your own data types as structures (or classes in object-oriented languages).

Here's an example below:

#include <stdio.h>

typedef struct
{
    char * name;
    int age;
    float salary;
} Employee;

int main()
{
    Employee employeeOfTheMonth = { "Joe Smith", 32, 67458.95 };
    printf("Employee of the month is called %s.\n", employeeOfTheMonth.name);
    printf("Employee of the month is %d years old.\n", employeeOfTheMonth.age);
    printf("Employee of the month earns $%.2f.\n", employeeOfTheMonth.salary);

    return 0;
}
0 votes
answered Feb 19 by Elavarasan Mohan (140 points)
Data Type:

In the C programming language, Data types tells to the compiler what kind of data's we are going to use in our program. Generally , in the C programming language data types are classified into four categories , these are 1.Basic data type  2. Derived data type 3. User defined data type 4. void data type.

1) Basic data types: coming to the basic data types has different types based on data's. these are

Int data type - Its described about integer's value  (Eg: 1,2,3,....456....n)

char data type - its described about characters (Eg; a,A,b,B....z,Z)

float data type - its described about floating point numbers (Eg: 1.1,2.2,3.3.....n.n)

double data type - its also described floating point number but after point it can consider 2 digits (Eg:1.11,2.22..n.nn)

2) Derived data types

Array , functions , pointers , reference these are all the derived data types.

3) user-defined data types :

structure, union, enumeration, typedef these are all the user defined data types.

4) void data types

it is associated with zero which means void means nothing .

These are all the different data types in the c programming language. these data types used to we can declare the data , define the data and initialize the data in the c programming language .

C programming compilers only understand or identified through the data types what type of data's we are used in our program.

Note: one more thing , these data types reserved words in the c programming language because the data types has specific roles in the c programming language . so, these type data types we cant able to use another roles. If we are try to use we will get compiler error.
0 votes
answered Feb 23 by PRATHEEP PARAMASIVAM DCGP (140 points)
There are different types of data, In the world every information is the data.

In the programing the data are three major types Number, Characters

Number is classified into two types integer (Positive and negatives of whole numbers ) and float (Pointing integers)
Characters (Char) which include the special characters, alphabets and numbers
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...