Why do we at all use integers in C?
#include<stdio.h>
int main()
{
char c=10;
printf("%d",c);
return 0;
}
Is same as:
#include<stdio.h>
int main()
{
int c=10;
printf("%d",c);
return 0;
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Technically all datatypes are represented with 0’s and 1’s. So, if they are all the same in the back end, why do we need different types?
Well, a type is a combination of data, and the operations you can perform on the data.
We have
intsfor representing numbers. They have operations like+for computing the sum of two numbers, or-to compute the difference.When you think of a character, in the usual sense, it represents one letter or symbol in a human readable format. Being able to sum
'A' + 'h'doesn’t make sense. (Even though c lets you do it.)So, we have different types in different languages to make programming easier. They essentially encapsulate data and the functions/operations that are legal to perform on them.
Wikipedia has a good article on Type Systems.