c language basics telugu
Data types in C
- Fundamental Data Types
- Integer types
- Floating Type
- Character types
- Derived Data Types
Syntax for declaration of a variable
Integer data types
Keyword int is used for declaring the variable with integer type. For example:
Here, var1 is a variable of type integer.
The size of int is either 2 bytes(In older PC’s) or 4 bytes. If you consider an integer having size of 4 byte( equal to 32 bits), it can take 232 distinct states as: -231,-231+1, …,-2, -1, 0, 1, 2, …, 231-2, 231-1
Similarly, int of 2 bytes, it can take 216 distinct states from -215 to 215-1. If you try to store larger number than 231-1, i.e,+2147483647 and smaller number than -231, i.e, -2147483648, program will not run correctly.
Variables of floating types can hold real values(numbers) such as: 2.34, -9.382 etc. Keywords either float or double is used for declaring floating type variable. For example:
float var2; double var3;
Here, both var2 and var3 are floating type variables.
In C, floating values can be represented in exponential form as well. For example:
Difference between float and double
Generally the size of float(Single precision float data type) is 4 bytes and that of double(Double precision float data type) is 8 bytes. Floating point variables has a precision of 6 digits whereas the the precision of double is 14 digits.
Note: Precision describes the number of significant decimal places that a floating values carries.
Keyword char is used for declaring the variable of character type. For example:
Here, var4 is a variable of type character which is storing a character ‘h’.
The size of char is 1 byte. The character data type consists of ASCII characters. Each character is given a specific value. For example:
For, 'a', value =97 For, 'b', value=98 For, 'A', value=65 For, '&', value=33 For, '2', value=49
Following table tell which data type how much allocate memory?
Data Type Memory Allocation
int 2 byte
long 4 byte
float 4 byte
double 8 byte
long double 10 byte
char 1 byte