Elements of C Language
Let us discuss about elements of C language. The first one is Character Set.
To view the Video session on Elements of C Language , Play the video
The C Character Set
The basic programming elements like variables, constants, keywords, operators, expressions, statements etc. can be created using characters, numbers and special characters are commonly called character set in C Language. Which are as under-
Alphabets : a to z (lowercase letters)
A to Z (uppercase letters)
Digits: 0 1 2 3 4 5 6 7 8 9
Special Characters : + – * / % = & | ^ ! # $ ~ { } [ ] ( ) ” ‘ , . < > > _ : ; \ (blank space)
When these above mentioned special characters are used in certain combination, resulting in some special meaning. e.g ++ — << >> += -= *= /= %= |= != == [] () etc
Escape Sequence : \n \a \b \” \’ \\ \f \t \v etc.
The next elements of C Language is Identifiers
Identifiers
An identifier in c language is a name given to an element which is used to identify a variable, constant, function, array, structure or any other user-defined element
Rules to name an identifier
1) The name must begin with either a letter or an underscore.
2) It should not be much longer.
3) Name can’t contain any special character other than ‘_’.
4) It can have digits after first character or underscore.
5) No blank space is allowed in an identifier name.
6) Identifier name should be self explanatory. which means if you are writing an identifier for a student name then it can be like, studentname, sname etc.
7) There are some reserved words in C language which can’t be used for user defined identifiers.
8) C is case sensitive so ‘Name’ and ‘name’ are two different identifiers.
Examples of some valid identifier names –
place, total_salary, Age, _username, b2b, a12 etc
Examples of some invalid identifier names –
2nd, student name, default, name’s etc
The next elements of C Language is keywords
Keywords
C has 32 reserved words, which have special meaning in c. These words can’t be used to name any variable, constant or any other identifier.
auto | else | long | switch |
break | enum | register | typedef |
case | extern | return | union |
char | float | short | unsigned |
const | for | signed | void |
continue | goto | sizeof | volatile |
default | if | static | while |
do | int | struct | double |
These keywords will be discussed in details as we progress in c.
Next Elements of C Language is data types
Data Types in C Language
Data types of an object determine the set of values it can take and the operations that can be performed on it.
The types in C can be classified as follows −
- Basic Data Types
- Derived Data Types
Basic Data Types:
Basic data types are of 5 types as discussed below-
The following table provides the details of standard char, integer and double date types with their storage sizes and value ranges −
S.No |
Type of Data |
Declarator |
Typical Size |
Range |
1 |
Character Data Type |
char |
1 byte |
-128 to 127 |
2 |
Integer Data |
Int |
2 bytes |
-32768 to 32767 |
3 |
Real or Floating point data |
Float |
4 bytes |
3.4×10-38to 3.4×1038 with 6 digits of percision |
4 |
Double data type |
Double |
8 bytes |
1.7×10-308 to 1.7×10308 with 10 digits of precision |
5 |
Void |
Void |
– |
– |
To get the exact size of a type or a variable on a particular platform, you can use the sizeof operator.
Derived Data Types
Derived data types can be Pointers, Arrays, Structures, Unions and functions types.
Type Modifiers
Basic data types can be modified except void and float to accommodate to specific needs. So to accommodate the need a keyword precedes the basic data type to represent the storage requirements. This keyword is called Type Modifier.
Type |
Storage size |
Value range |
char |
1 byte |
-128 to 127 or 0 to 255 |
unsigned char |
1 byte |
0 to 255 |
signed char |
1 byte |
-128 to 127 |
int |
2 bytes |
-32,768 to 32,767 |
unsigned int |
2 bytes |
0 to 65,535 |
short |
2 bytes |
-32,768 to 32,767 |
unsigned short |
2 bytes |
0 to 65,535 |
Long or long int |
4 bytes |
-2,14,74,83,648 to 2,14,74,83,647 |
unsigned long int |
4 bytes |
0 to 4,29,49,67,295 |
Long double |
10 bytes |
3.4×10-4932 to 1.1×104932 |
Next Elements of C Language is format specifiers
Format Specifiers
Format specifiers are used to specify the type of data a variable can take during input/output or read/write operations. The list of format specifiers is as under –
To Read or Write a |
Format specifier |
Signed char |
%c |
Signed decimal integer |
%d |
Unsigned decimal integer |
%u |
Unsigned octal integer |
%o |
Unsigned hexadecimal integer |
%x |
Floating pointing number |
%f |
Scientific floating point number |
%e |
Character String |
%c |
Long Integer |
%ld |
Double Precision Integer |
%lf |
Next Elements of C Language is constants
Constants
A constant is just a fixed value or a value found in an expression that a program may not change. A constant can be of any data type except void in C language. Constants are also called literals.
Constants don’t have memory locations but many compilers place string constants in the memory.
Types of constants in C Language-
1) Numeric constants
Numeric constants are further divided into two types – integer constants and floating point constants
i) Integer Constants -Integer constants are the constants without fractional part. These can be
ii) Decimal Integers – Decimal numbers have 10 basic numbers from 0-9, e.g. 0,1,2,9 etc. It does not start with 0 unless the number itself is 0.
iii) Octal Integer – Octal numbers consists of numbers in the range of 0-7, starting with prefix 0 eg 0123,0456 etc. It always starts with 0.
iv) Hexadecimal Integers – These numbers have 16 basic numbers 0-9,a-f. and starts with 0x e.g. 0x199a and 0xaf42.
2) Floating Point numbers – These numbers contain decimal point or letter e or both. e.g. 3.14, 123.234e3
2) Character Constants
When a single character is enclosed in single quotes then it is called character constant.
e.g. ‘A’,’a’, ‘.’ etc.
The numeric value of character constants is fixed and is as per ASCII (American Standard Code for Information Interchange) table, which is 97 for ‘a’ and 65 for ‘A’.
3) String Constants
This is a sequence of zero or more characters enclosed in double quotes e.g. “abc”, “Ram”, “baby” etc. C compiler always terminates a string with an extra null byte (‘\0’) so storage space required for a string is always one more than the no. of characters.
“Ram” string contains 3 characters but it’s memory layout would be-
R | A | M | \0 |
Hence it would occupy 4 bytes of storage space.
4) Escape Sequences
Within character and string constants the backslash (‘\’) is a special character which is used to represent non printable characters or hard to print characters. When backslash is used in conjunction with one or more characters to create a sequence of characters then it is called escape sequence.
Escape Sequence |
Meaning |
\a |
Alert |
\b |
Backspace |
\t |
Horizontal tab |
\v |
Vertical tab |
\n |
New line |
\f |
Form feed |
\r |
Carriage return |
\\ |
Backslash |
\’ |
Single quotes |
\” |
Double quotes |
\? |
Question mark |
5) Named Constants
Enumerators are the named constants that are used to give names to elements of finite set. Set of these named constants are called enumeration.
Enumeration types are internally treated as integers by the compilers.
Declaration of enumeration types-
enum fruit{apple,banana,mango,guava};
by default, enumerators starts from 0,1 and so on. Here apple will take value 0, banana 1, mango 2 and guava 3.
6) Symbolic Constants
Symbolic constant is the name that substitutes for a constant. The constants can be numeric constant, character constant, string constant.
The pre-processor directive #define is used to define symbolic constants.
e.g. #define pi 3.14
#define false 0
This chapter about elements of C language covered a brief description about elements of C Language. More on the same would be published in the coming Chapters.
Similar Topic : C Language Introduction
You May Also Like : How to Activate GST in Tally.ERP9 ? Let us Learn JavaScript from Step By Step HTML Introduction
To download TurboC IDE cum Compiler Click here.
What are decimal integers ?
Decimal integers are whole numbers consisting of basic numbers (0-9). Decimal integers don’t starts with 0 unless the number itself is 0. Can be written as (123)10 or 123, 560, 203 etc.
What are Octal Numbers?
Octal numbers comprises of numbers from 0-7. These numbers always start with 0. Can be written as (123)8 or 0123,0456 etc
What are hexadecimal numbers ?
Hexadecimal numbers can have numbers from 0-9, a-f , in total 16 basic numbers. These numbers precedes with 0x e.g. 0x234f , 0x23dd etc. also we can write a hexadecimal number as (345a)16
Nice topic
Thank you chhaya
Very nice topic
Helpful
Nice topic
Very nice
[…] Topics : Elements of C Language C Language […]
[…] Language Introduction Elements of C Language Variables in […]
[…] May Also Like: How to create and run java Program Elements of C Language […]