Character Set of C: Alphabets
Character Set of C: Alphabets
Character Set of C: Alphabets
character:- It denotes any alphabet, digit or special symbol used to represent information.
Use:- These characters can be combined to form variables. C uses constants, variables, operators, keywords and expressions as building blocks to form a
basic C program.
Character set:- The character set is the fundamental raw material of any language and they are used to represent information. Like natural languages, computer
language will also have well defined character set, which is useful to build the programs.
ALPHABETS
Uppercase letters A-Z
Lowercase letters a-z
DIGITS 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
SPECIAL CHARACTERS
~ tilde % percent sign | vertical bar @ at symbol + plus sign < less than
_ underscore - minus sign > greater than ^ caret # number sign = equal to
& ampersand $ dollar sign / slash ( left parenthesis * asterisk \ back slash
) right parenthesis ′ apostrophe : colon [ left bracket " quotation mark ; semicolon
] right bracket ! exclamation mark , comma { left flower brace ? Question mark . dot operator
WHITESPACE CHARACTERS
\b blank space \t horizontal tab \v vertical tab \r carriage return \f form feed \n new line
\\ Back slash \’ Single quote \" Double quote \? Question mark \0 Null \a Alarm (bell)
Certain ASCII characters are unprintable, which means they are not displayed on the screen or printer. Those characters perform other functions aside from displaying text. Examples
are backspacing, moving to a newline, or ringing a bell.
They are used in output statements. Escape sequence usually consists of a backslash and a letter or a combination of digits. An escape sequence is considered as a single character but
a valid character constant.
These are employed at the time of execution of the program. Execution characters set are always represented by a backslash (\) followed by a character. Note that each one of character
constants represents one character, although they consist of two characters. These characters combinations are called as escape sequence.
Hexadecimal number \x
Tokens
A token is the smallest element of a program that is meaningful to the compiler. Tokens can be classified as follows:
1. Keywords
2. Identifiers
3. Constants
4. Strings
5. Special Symbols
6. Operators
Keywords: Keywords are pre-defined or reserved words in a programming language. Each keyword is meant to perform a specific function
in a program. Since keywords are referred names for a compiler, they can’t be used as variable names because by doing so, we are trying
to assign a new meaning to the keyword which is not allowed. You cannot redefine keywords. However, you can specify the text to be
substituted for keywords before compilation by using C/C++ preprocessor directives. C language supports 32 keywords which are given
below:
auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while
While in C++ there are 31 additional keywords other than C Keywords they are:
asm bool catch class
const_cast delete dynamic_cast explicit
export false friend inline
mutable namespace new operator
private protected public reinterpret_cast
static_cast template this throw
true try typeid typename
using virtual wchar_t
1. Identifiers: Identifiers are used as the general terminology for the naming of variables, functions and arrays. These are user-
defined names consisting of an arbitrarily long sequence of letters and digits with either a letter or the underscore(_) as a first
character. Identifier names must differ in spelling and case from any keywords. You cannot use keywords as identifiers; they are
reserved for special use. Once declared, you can use the identifier in later program statements to refer to the associated value. A
special kind of identifier, called a statement label, can be used in goto statements.
Identifiers are used for the naming of variables, functions, and arrays. It is a string of alphanumeric characters that begins with an
alphabet, or an underscore( _ ) that are used for variables, functions, arrays, structures, unions, and so on. It is also known as
the user-defined word. Identifier names must differ in spelling and case from any keywords. We cannot use keywords as
identifiers; they are reserved for special use. Once an identifier is declared, we can use the identifier anywhere in the program to
refer to the associated value.
There are certain rules that should be followed while naming c identifiers:
They must begin with a letter or underscore(_).
They must consist of only letters, digits, or underscore. No other special character is allowed.
It should not be a keyword.
It must not contain white space.
It should be up to 31 characters long as only the first 31 characters are significant.
main: method name.
a: variable name.
2. Constants: Constants are also like normal variables. But, the only difference is, their values can not be modified by the program
once they are defined. Constants refer to fixed values. They are also called literals.
Constants may belong to any of the data type.
3. Syntax:
const data_type variable_name; (or) const data_type *variable_name;
Types of Constants:
Integer constants – Example: 0, 1, 1218, 12482
Real or Floating-point constants – Example: 0.0, 1203.03, 30486.184
Octal & Hexadecimal constants – Example: octal: (013 ) = (11) Hexadecimal: (013) = (19)
8 10, 16 10
Data types
All variables use data-type during declaration to restrict the type of data to be stored. Therefore, we can say that data types are used to tell
the variables the type of data it can store. Whenever a variable is defined in C++, the compiler allocates some memory for that variable
based on the data-type with which it is declared. Every data type requires a different amount of memory.
Data types in C++ is mainly divided into three types:
1. Primitive Data Types: These data types are built-in or predefined data types and can be used directly by the user to declare
variables. example: int, char , float, bool etc. Primitive data types available in C++ are:
Integer
Character
Boolean
Floating Point
Double Floating Point
Valueless or Void
Wide Character
2. Derived Data Types: The data-types that are derived from the primitive or built-in datatypes are referred to as Derived Data
Types. These can be of four types namely:
Function
Array
Pointer
Reference
3. Abstract or User-Defined Data Types: These data types are defined by user itself. Like, defining a class in C++ or a structure.
C++ provides the following user-defined datatypes:
Class
Structure
Union
Enumeration
Typedef defined DataType
This article discusses primitive data types available in C++.
Integer: Keyword used for integer data types is int. Integers typically requires 4 bytes of memory space and ranges from -
2147483648 to 2147483647.
Character: Character data type is used for storing characters. Keyword used for character data type is char. Characters typically
requires 1 byte of memory space and ranges from -128 to 127 or 0 to 255.
Boolean: Boolean data type is used for storing boolean or logical values. A boolean variable can store either true or false.
Keyword used for boolean data type is bool.
Floating Point: Floating Point data type is used for storing single precision floating point values or decimal values. Keyword used
for floating point data type is float. Float variables typically requires 4 byte of memory space.
Double Floating Point: Double Floating Point data type is used for storing double precision floating point values or decimal
values. Keyword used for double floating point data type is double. Double variables typically requires 8 byte of memory space.
void: Void means without any value. void datatype represents a valueless entity. Void data type is used for those function which
does not returns a value.
Wide Character: Wide character data type is also a character data type but this data type has size greater than the normal 8-bit
datatype. Represented by wchar_t. It is generally 2 or 4 bytes long.
All variables use data-type during declaration to restrict the type of data to be stored. Therefore, we can say that data types are used to tell
the variables the type of data it can store. Whenever a variable is defined in C++, the compiler allocates some memory for that variable
based on the data-type with which it is declared. Every data type requires a different amount of memory.
Data types in C++ is mainly divided into three types:
1. Primitive Data Types: These data types are built-in or predefined data types and can be used directly by the user to declare
variables. example: int, char , float, bool etc. Primitive data types available in C++ are:
Integer
Character
Boolean
Floating Point
Double Floating Point
Valueless or Void
Wide Character
2. Derived Data Types: The data-types that are derived from the primitive or built-in datatypes are referred to as Derived Data
Types. These can be of four types namely:
Function
Array
Pointer
Reference
3. Abstract or User-Defined Data Types: These data types are defined by user itself. Like, defining a class in C++ or a structure.
C++ provides the following user-defined datatypes:
Class
Structure
Union
Enumeration
Typedef defined DataType
This article discusses primitive data types available in C++.
Integer: Keyword used for integer data types is int. Integers typically requires 4 bytes of memory space and ranges from -
2147483648 to 2147483647.
Character: Character data type is used for storing characters. Keyword used for character data type is char. Characters typically
requires 1 byte of memory space and ranges from -128 to 127 or 0 to 255.
Boolean: Boolean data type is used for storing boolean or logical values. A boolean variable can store either true or false.
Keyword used for boolean data type is bool.
Floating Point: Floating Point data type is used for storing single precision floating point values or decimal values. Keyword used
for floating point data type is float. Float variables typically requires 4 byte of memory space.
Double Floating Point: Double Floating Point data type is used for storing double precision floating point values or decimal
values. Keyword used for double floating point data type is double. Double variables typically requires 8 byte of memory space.
void: Void means without any value. void datatype represents a valueless entity. Void data type is used for those function which
does not returns a value.
Wide Character: Wide character data type is also a character data type but this data type has size greater than the normal 8-bit
datatype. Represented by wchar_t. It is generally 2 or 4 bytes long.
All variables use data-type during declaration to restrict the type of data to be stored. Therefore, we can say that data types are used to tell
the variables the type of data it can store. Whenever a variable is defined in C++, the compiler allocates some memory for that variable
based on the data-type with which it is declared. Every data type requires a different amount of memory.
Data types in C++ is mainly divided into three types:
1. Primitive Data Types: These data types are built-in or predefined data types and can be used directly by the user to declare
variables. example: int, char , float, bool etc. Primitive data types available in C++ are:
Integer
Character
Boolean
Floating Point
Double Floating Point
Valueless or Void
Wide Character
2. Derived Data Types: The data-types that are derived from the primitive or built-in datatypes are referred to as Derived Data
Types. These can be of four types namely:
Function
Array
Pointer
Reference
3. Abstract or User-Defined Data Types: These data types are defined by user itself. Like, defining a class in C++ or a structure.
C++ provides the following user-defined datatypes:
Class
Structure
Union
Enumeration
Typedef defined DataType
This article discusses primitive data types available in C++.
Integer: Keyword used for integer data types is int. Integers typically requires 4 bytes of memory space and ranges from -
2147483648 to 2147483647.
Character: Character data type is used for storing characters. Keyword used for character data type is char. Characters typically
requires 1 byte of memory space and ranges from -128 to 127 or 0 to 255.
Boolean: Boolean data type is used for storing boolean or logical values. A boolean variable can store either true or false.
Keyword used for boolean data type is bool.
Floating Point: Floating Point data type is used for storing single precision floating point values or decimal values. Keyword used
for floating point data type is float. Float variables typically requires 4 byte of memory space.
Double Floating Point: Double Floating Point data type is used for storing double precision floating point values or decimal
values. Keyword used for double floating point data type is double. Double variables typically requires 8 byte of memory space.
void: Void means without any value. void datatype represents a valueless entity. Void data type is used for those function which
does not returns a value.
Wide Character: Wide character data type is also a character data type but this data type has size greater than the normal 8-bit
datatype. Represented by wchar_t. It is generally 2 or 4 bytes long.
All variables use data-type during declaration to restrict the type of data to be stored. Therefore, we can say that data types are used to tell
the variables the type of data it can store. Whenever a variable is defined in C++, the compiler allocates some memory for that variable
based on the data-type with which it is declared. Every data type requires a different amount of memory.
Constants refer to fixed values that the program may not alter during its execution. These fixed values are also called literals.
Constants can be of any of the basic data types like an integer constant, a floating constant, a character constant, or a string literal.
There are enumeration constants as well.
Constants are treated just like regular variables except that their values cannot be modified after their definition.
Integer Literals
An integer literal can be a decimal, octal, or hexadecimal constant. A prefix specifies the base or radix: 0x or 0X for hexadecimal, 0 for
octal, and nothing for decimal.
An integer literal can also have a suffix that is a combination of U and L, for unsigned and long, respectively. The suffix can be
uppercase or lowercase and can be in any order.
Floating-point Literals
A floating-point literal has an integer part, a decimal point, a fractional part, and an exponent part. You can represent floating point
literals either in decimal form or exponential form.
While representing decimal form, you must include the decimal point, the exponent, or both; and while representing exponential form,
you must include the integer part, the fractional part, or both. The signed exponent is introduced by e or E.
A character literal can be a plain character (e.g., 'x'), an escape sequence (e.g., '\t'), or a universal character (e.g., '\u02C0').
There are certain characters in C that represent special meaning when preceded by a backslash for example, newline (\n) or tab (\t).
Live Demo
#include <stdio.h>
int main() {
printf("Hello\tWorld\n\n");
return 0;
}
When the above code is compiled and executed, it produces the following result −
Hello World
String Literals
String literals or constants are enclosed in double quotes "". A string contains characters that are similar to character literals: plain
characters, escape sequences, and universal characters.
You can break a long line into multiple lines using string literals and separating them using white spaces.
Here are some examples of string literals. All the three forms are identical strings.
"hello, dear"
"hello, \
dear"
Defining Constants
There are two simple ways in C to define constants −
Live Demo
#include <stdio.h>
#define LENGTH 10
#define WIDTH 5
#define NEWLINE '\n'
int main() {
int area;
return 0;
}
When the above code is compiled and executed, it produces the following result −
value of area : 50
The const Keyword
You can use const prefix to declare constants with a specific type as follows −
const type variable = value;
Live Demo
#include <stdio.h>
int main() {
const int LENGTH = 10;
const int WIDTH = 5;
const char NEWLINE = '\n';
int area;
return 0;
}
When the above code is compiled and executed, it produces the following result −
value of area : 50
Data types in C++ is mainly divided into three types:
1. Primitive Data Types: These data types are built-in or predefined data types and can be used directly by the user to declare
variables. example: int, char , float, bool etc. Primitive data types available in C++ are:
Integer
Character
Boolean
Floating Point
Double Floating Point
Valueless or Void
Wide Character
2. Derived Data Types: The data-types that are derived from the primitive or built-in datatypes are referred to as Derived Data
Types. These can be of four types namely:
Function
Array
Pointer
Reference
3. Abstract or User-Defined Data Types: These data types are defined by user itself. Like, defining a class in C++ or a structure.
C++ provides the following user-defined datatypes:
Class
Structure
Union
Enumeration
Typedef defined DataType
This article discusses primitive data types available in C++.
Integer: Keyword used for integer data types is int. Integers typically requires 4 bytes of memory space and ranges from -
2147483648 to 2147483647.
Character: Character data type is used for storing characters. Keyword used for character data type is char. Characters typically
requires 1 byte of memory space and ranges from -128 to 127 or 0 to 255.
Boolean: Boolean data type is used for storing boolean or logical values. A boolean variable can store either true or false.
Keyword used for boolean data type is bool.
Floating Point: Floating Point data type is used for storing single precision floating point values or decimal values. Keyword used
for floating point data type is float. Float variables typically requires 4 byte of memory space.
Double Floating Point: Double Floating Point data type is used for storing double precision floating point values or decimal
values. Keyword used for double floating point data type is double. Double variables typically requires 8 byte of memory space.
void: Void means without any value. void datatype represents a valueless entity. Void data type is used for those function which
does not returns a value.
Wide Character: Wide character data type is also a character data type but this data type has size greater than the normal 8-bit
datatype. Represented by wchar_t. It is generally 2 or 4 bytes long.