Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

The C Character Set

To develop a program what fundament components are required those are called characteristics of C

The classical method of learning English is to first learn the alphabets used in the language, then learn to
combine these alphabets to form words, which in turn are combined to form sentences and sentences are
combined to form paragraphs. Learning C is similar and easier.

Character set of C Language

 Letters : A to Z and a to z
 Digits : 0 to 9
 Special characters : *, @, # ......etc.
 White space characters: Enter key(\n), tab space key(\t), space key (
−), back space key (‘\b’)....etc.

Token
Smallest individual unit of a program is known as token.

 Keywords
 Identifiers
 Constants

Keywords/ reserved words

Keywords, also known as reserved words, are a type of predefined words in C language that have
special meanings and purposes. There is a set of 32 keywords in C language,

auto double int struct


break else long switch
case enum register typedef

1
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while

Identifiers:
Identifier refers to the names of the variables, functions and arrays.

Rules to name a particular identifier:


1. It must start with either alphabet or underscore.
2. Remaining letters may be alphabet, digit, underscore.
3. Identifier would not allow any special symbol except underscore.
4. An identifier can be of any length while most compilers of ‘C’ language
recognize only the first 8 characters.
5. Do not use keywords as an identifier.

Here are some examples of invalid identifiers in C:


1. 123var
2. my$var
3. for

Difference Between Keywords and Identifiers in C Language

Here are some of the key differences between keywords and identifiers:

Keywords Identifiers

1. These are predefined and can not be used or defined These are user-defined for several
according to the user. operations.

2. Lowercase letters only Either lowercase or uppercase

3. Alphabetic characters Alphanumeric characters

4. Identifies a value that is already in the compiler Identifies a value that is user-
defined.

5. Examples: int, char, if, do Examples: count1, Test,


high_speed, etc.

6. Identify the whole class of entity Identifies a particular entity

Data types

A data type specifies the values a variable may assume. Variable should be
associated with a single data type The C language provides the four basic
arithmetic type specifiers char, int, float and double,

1. Integer – We use these for storing various whole numbers, such as 5, 8, 67, 2390, etc.

2
2. Character – It refers to all ASCII character sets as well as the single alphabets, such as
‘x’, ‘Y’, etc.

3. Double – These include all large types of numeric values that do not come under either
floating-point data type or integer data type. Visit Double Data Type in C to know more.

4. Floating-point – These refer to all the real number values or decimal points, such as
40.1, 820.673, 5.9, etc.

5. Void – This term refers to no values at all. We mostly use this data type when defining
the functions in a program.

Various keywords are used in a program for specifying the data types mentioned above.
Here are the keywords that we use:

Keyword Used Data Type

int Integer

float Floating-point

void Void

char Character

double Double

Range of Values of C Data Type


The range of all the C language data types are present in the table given below:

Data Type Format Minimal Range Typical Bit


Specifier Size

unsigned char %c 0 to 255 8

char %c -127 to 127 8

signed char %c -127 to 127 8

int %d, %i -32,767 to 32,767 16 or 32

unsigned int %u 0 to 65,535 16 or 32

signed int %d, %i Same as int Same as int

16 or 32

3
short int %hd -32,767 to 32,767 16
unsigned short %hu 0 to 65,535 16
int
signed short int %hd Same as short int 16
long int %ld, %li -2,147,483,647 to 2,147,483,647 32
long long int %lld, %lli -(263 – 1) to 263 – 1 (It will be added by the C99 64
standard)
signed long int %ld, %li Same as long int 32
unsigned long int %lu 0 to 4,294,967,295 32
unsigned long %llu 264 – 1 (It will be added by the C99 standard) 64
long int
float %f 1E-37 to 1E+37 along with six digits of the precisions 32
here
double %lf 1E-37 to 1E+37 along with six digits of the precisions 64
here
long double %Lf 1E-37 to 1E+37 along with six digits of the precisions 80
here

When the value of the Data Type happens to be out of


Range
Whenever we try to assign any value to a given data type in a program that is more than the
allowed value range, then the compiler in C language will generate an error.

Let us look at an example to understand this better.

#include <stdio.h>

int main() {

// the maximum value allowed in the signed short int is 32767

signed short int x = 34767;

return 0;

Use of C Data Types


The use of C data type is to define the type of data that we use in a program. Let us take a
look at each of these in detail.

The char Data Type


This data type basically refers to all the character values that get enclosed in single quotes.
Also, this data type ranges from -127 to 127.

4
As we can see, we can use any of the smaller integer values in a char data type.

For instance,

char status = ‘X’

The float Data Type


We use the float data type for storing all the real numbers. These may have both, the
exponential part as well as the decimal part (or the fraction part). It is basically a single-
precision type of number.

For instance,

float y = 127.675;

// by using the suffix f or F

float x = 1000.5454F;

Just like the data type int, we can also use the float data type along with various modifiers.

The double Data Type


We store such numbers in a double data type that the float data type can’t store in a
program (bigger than the maximum capacity of the float data type). The double data type is
basically a double-precision type of number. It is capable of holding about 15 to 17 values,
both after and before a decimal point.

For instance,

double y = 424455236424564.24663224663322;

A person will utilise the double data type in a program only when it is needed to store any
such large numbers. Otherwise, we don’t use it as it will make the program very slow.

The int Data Type


We use the int data type for storing the whole numbers that might be values that have no
exponential part or decimal part in the number.

We can store the octal (or base 8), hexadecimal (or base 16), and decimal (or base 10) in
the data types.

For instance,

// a simple int data value

5
int z = 310;

// a negative data value

z = -4260;

// an unsigned int data value that has a suffix of u or U

int z = 90U;

// a long int data value that has a suffix of l or L

long int long_val = 87500L;

Character constants

A character constant contains only a single character enclosed within a


single quote (”). We can also represent character constant by providing
ASCII value of it.

Example, 'A', '9'


Above are the examples of valid character constants.

String constants

A string constant contains a sequence of characters enclosed within double


quotes (“”).

Example, "Hello", "Programming"

You might also like