Data Types | Constants | Variables | Learn C-Language
Learn C-Language |
Constants
There are two types of contents :
1. Primary Constant
2. Secondary Constant
Primary Constants
- Character Constants
- Integer Constants
- Real Constants
Secondary Constants
- Array
- Pointer
- Structure
- Union
- Enum
The Primary Constants
The Primary constants are the basic constants to be used in a C-program as the Character Constants, Integer Constants and Real Constants.
The Secondary constants are made up from the primary constants. These are Array, Pointer, Structure, Union, Enum, etc.
Character Constants:
The character constants refer to the alphanumeric characters. A character constant may be any single alphabet (lower case or upper case), any single digit, any special symbol or a space enclosed in single quotes () always pointing to left.
For example : 'A'
'7'
'$'
'+'
Integer Constants :
The integer constant is a numeric data value which can be used for calculations It consists of the digits without decimal point. The integer constant may be either positive or negative.
An integer constant can be made by the combination of digits from 0 to 9.
If the constant is of two or more digits, first digit must not be zero. The integer constant without any sign is assumed to be positive. The integer constant cannot contain any space or punctuation marks. These integer constants may be decimal, octal and hexadecimal.
For example :
Several valid decimal Integer constants are like -
0, 2, 123, 5678, 3275, 9999, 32760
Several octal integer constants are like-
0, 02, 0123, 0777
The hexadecimal integer constants are like -
OX7, OX1, OX7FFF, OXabcd
Real Constants:
These are called as Floating Point Constants. It is a base-10 number in decimal point form (fractional form) and exponent form. Each real constant must have a decimal point_with positive or negative sign. But like integer constants, this is assumed positive if no sign is used.
The precision of floating point number constants (number of significant digits) are generally six in most of the C-versions. The exponential form of floating point constant is required for very small or very large real constant value.
The exponent form has 2 parts - mantissa and exponent. Both mantissa and exponent should be separated by an alphabet 'e' or 'E'. The mantiss part as well as exponent part may be positive or negative, The mantissa part may contain the decimal point but the exponent part can never.
Representation : mantissa E exponent.
For example :
The valid fractional forms of a Real constant are --
30.00, 0.2, -123.678, 0.1234, +12.0066
The valid exponent forms of Real constants are -
0.3E6m +30E4, -30.2E+4, 0.00502E-3
Identifiers
Identifier refers to the name of various program elements such as variables, functions and arrays etc. The identifiers are user defined because, these are defined by programmer as required in the program.
The identifiers may be in upper case or lower case but treated differently because C-language is a case sensitive language.
The identifier must start with an alphabet. It consists of alphabets and digits, but the spaces and the special symbols are not allowed within an identifier.
The underscore character (_) can be the part of identifier as the starting character or the middle character.
For example :
The valid identifiers are like -
n, num, name, num1, item_rate, CITY, _price
Variables and Data Types
Variable is an identifier, which is used to store a data value for processing. Sometimes, we can refer it as the memory space having specific name and storing data value. A variable can have different data values at different times during program execution.
Due to this behaviour, it is named "Variable". The naming conventions for variable are similar to that of identifiers Generally, the variable name consists of 1 to 8 characters. The characters may be alphabets, numbers or underscores, but may not be space or symbols.
Some C-compilers permit the length of variable name up to 40 characters. The first character of the variable name should be an alphabet strictly. Any keyword can never be used as the variable name. Variable is an identifier, which is used to store a data value for processing Sometimes.
For example :
simple_ints, age, work_hs etc. are valid variable names.
Data type refers to the constant type of the data used for processing. C-language is very rich in data-types, because it provides different data types to refer to the different data for processing.
These data types are classified as following 4 types -
(1) Primary data types / Predefined
(2) User defined data types
(3) Derived data types
(4) Empty data set
Basically, the fundamental data types supported by most of the C -compiles are dependent on the constants of C-language. These are the "Primary Data Types" of C-language.
These are described as follows:
(i) Integer data type
(ii) Character data type
(iii) Float data type
Learn Variable And Data Types |
Integer Data Type :
Integers are the whole numbers having different storage range supported by particular machine. Integer data types are used to store these whole numbers using different memory spaces or variables. The general integer data type uses 2 bytes of memory space and has the storage range between -32768 and +32767.
These 2 bytes (16 bits) of memory stores the sign of integer constant in the last bit (16th bit), as 1 for negative and 0 for positive sign. The integer data types are classified on the basis of sign of integer constant as signed Integer and unsigned integer.
Depending on the storage range, these ure classified as long integer and short integer. So, the integer data types can be broadly viewed as short signed integer, long signed integer, short unsigned integer and long unsigned integer.
The short integer data types (both signed and unsigned) use 2 bytes of memory. The short signed integers have the storage range from -32768 to +32767. These are most commonly used and default integer types for a C-program. The short unsigned integer data types stores only positive integer constants in between the range of 0 and 65535.
The long integer data types (both signed and unsigned) occupies 4 bytes of memary. The storage range of long signed integer ranges from -2147483648 to +2147483647. The long unsigned integer data type stores positive data in between the range of 0 and 4294967295. The default long integer is assumed to be signed long integer.
Character Data Type :
The character data types are used to store the alphanumeric characters that means the character constants. Onc character data type uses 1 byte (8 bits) of memory to store single character. These are classified as signed characters and unsigned characters.
The storage range of signed character data type is -128 to +127 and that of unsigned character data type is 0 to 255. By default we use character data type which is signed character data type.
Float Data Type :
The real constants are stored in the memory space of 4 bytes or 8 bytes. Each floating point constant has 6 digits of precisions by default. There are different data types provided by C-language for storing the real constants of different range as float, double and long double.
The float data type uses 4 bytes of memory space and provides the data range from -3.4e38 to +3.4e38. The memory requirement of double data type is 8 bytes with the storage range of -1.7e308 to +1.7e308. One another data type provided for the storage of real constants is long double.
It requires 10 bytes of memory and has the storage range from -1.74c4932 to +1.7c4932. The double data type provides 14 digits of precision for floating point constants.
__________________________________________________________________________________________