Data types
Main article: C variable types and declarations
C has a static weak typing type system that shares some similarities with that of other ALGOL descendants such as Pascal. There are built-in types for integers of various sizes, both signed and unsigned, floating-point numbers, characters, and enumerated types (
enum
). C99 added a boolean datatype. There are also derived types including arrays, pointers, records(struct
), and untagged unions (union
).
C is often used in low-level systems programming where escapes from the type system may be necessary. The compiler attempts to ensure type correctness of most expressions, but the programmer can override the checks in various ways, either by using a type cast to explicitly convert a value from one type to another, or by using pointers or unions to reinterpret the underlying bits of a value in some other way.
OR
Data Types in C :
"Data type can be defined as the type of data of variable or constant store."
When we use a variable in a program then we have to mention the type of data. This can be handled using data type in C.
Followings are the most commonly used data types in C.
Keyword | Format Specifier | Size | Data Range |
---|---|---|---|
char | %c | 1 Byte | -128 to +127 |
unsigned char | <-- -- > | 8 Bytes | 0 to 255 |
int | %d | 2 Bytes | -32768 to +32767 |
long int | %ld | 4 Bytes | -231 to +231 |
unsigned int | %u | 2 Bytes | 0 to 65535 |
float | %f | 4 Bytes | -3.4e38 to +3.4e38 |
double | %lf | 8 Bytes | -1.7e38 to +1.7e38 |
long double | %Lf | 12-16 Bytes | -3.4e38 to +3.4e38 |
* QUALIFIER :
When qualifier is applied to the data type then it changes its size or its size.
Size qualifiers : short, long
Sign qualifiers : signed, unsigned
* ENUM DATA TYPE :
This is an user defined data type having finite set of enumeration constants. The keyword 'enum' is used to create enumerated data type.
Syntax:
enum [data_type] {const1, const2, ...., const n};
Example:
enum mca(software, web, seo);
* TYPEDEF :
It is used to create new data type. But it is commonly used to change existing data type with another name.
Syntax:
typedef [data_type] synonym;
typedef [data_type] new_data_type;
Example:
typedef int integer;
integer rno;
integer rno;
VARIABLES and KEY WORDS
Character Set :
A character refers to the digit, alphabet or special symbol used to data represetation.
- Alphabets : A-Z, a-z
- Digits : 0-9
- Special Characters : ~ ! @ # $ % ^ & * ( ) _ + { } [ ] - < > , . / ? \ | : ; " '
- White Spaces : Horizontal tab, Carriage return, New line, form feed
Identifier :
Identifier is the name of a variable that is made up from combination of alphabets, digits and underscore.
Variable :
It is a data name which is used to store data and may change during program execution. It is opposite to constant. Variable name is a name given to memory cells location of a computer where data is stored.
* Rules for varibales:- First character should be letter or alphabet.
- Keywords are not allowed to use as a variable name.
- White space is not allowed.
- C is case sensitive i.e. UPPER and lower case are significant.
- Only underscore, special symbol is allowed between two characters.
- The length of indentifier may be upto 31 characters but only only the first 8 characters are significant by compiler.
- (Note: Some compilers allow variable names whose length may be upto 247 characters. But, it is recommended to use maximum 31 characters in variable name. Large variable name leads to occur errors.)
Keywords :
Keywords are the system defined identifiers.
All keywords have fixed meanings that do not change.
White spaces are not allowed in keywords.
Keyword may not be used as an indentifier.
It is strongly recommended that keywords should be in lower case letters.
All keywords have fixed meanings that do not change.
White spaces are not allowed in keywords.
Keyword may not be used as an indentifier.
It is strongly recommended that keywords should be in lower case letters.
There are totally 32(Thirty Two) keywords used in a C programming.
int | float | double | long |
short | signed | unsigned | const |
if | else | switch | break |
default | do | while | for |
register | extern | static | struct |
typedef | enum | return | sizeof |
goto | union | auto | case |
void | char | continue | volatile |
Escape Sequence Characters (Backslash Character Constants) in C:
C supports some special escape sequence characters that are used to do special tasks.
These are also called as 'Backslash characters'.
Some of the escape sequence characters are as follow:
Character Constant | Meaning |
---|---|
\n | New line (Line break) |
\b | Backspace |
\t | Horizontal Tab |
\f | Form feed |
\a | Alert (alerts a bell) |
\r | Carriage Return |
\v | Vertical Tab |
\? | Question Mark |
\' | Single Quote |
\'' | Double Quote |
\\ | Backslash |
\0 | Null |
No comments:
Post a Comment