Before moving into the depth of c programming language let's have a look at the different elements of c .
These elements are necessary for making the structure of a c program .
If you want to know more about c programming language then read this post "Introduction to C Programming Language - Introduction , Basic and History ".
Character Set in C :-
It combines small alphabets, capital alphabets, digits and special symbols to write a program.
· a-z(ASCII code->97-122)
· A-Z(ASCII code->65-90)
· 0-9(ASCII code->48-57)
·
Special Symbols
Constants in c :-
Constants are the fixed quantity whose
value can never be change throughout the program execution.
Types:-
1.
Integer constant-
-may be +ve or –ve.
-range is -32768 to
+32767
-size is 2 bytes
-examples are 9,-346
2. Float/real constant-
-may be +ve or _ve
-range is -3.4x1038 to _3.4x1038
-size is 4 bytes
-examples are 1/3,-4.89
3.
Character/string constant
-if it is a character constant then it must be enclosed within
a pair of single quote and size is one byte. ex-‘s’(1 byte)
-if it is a string constant then it must
be enclosed within a pair of double
quote and size is not fixed. ex-“anil”(no range)
Q. As per constant definition a=2 then a
can replace 2 and 2 can replace a in the program. The why we need a we can
directly write 2 any where it will save 2 bytes of memory.
Ans: Suppose we have
create an application which take rate of interest while starting.
Today return of investment (roi ) is
2% tomorrow it can be 3% if we write 2% directly into the program then we have
change the code regularly and compile it again & again.
Variables :-
These are the temporary named
memory locations where the constant values are stored.
Every constant value
must be associated with a variable inside the memory.
Rules for constructing a
variable:-
1. variable name
must starts with an alphabet or an underscore(_).
2. It cannot
starts with a digit.
3. But digits
can be placed after first place.
4. No blank space is allowed while declaring a variable.
5. Variable name length
must not be more n 38 characters.
6. No
special symbols except
underscore is allowed
while declaring a variable.
Tokens :-
These are the combinations of constants, operators, strings, special symbols, keywords and identifiers.
Commenting Lines :-
These are used to deactivate line of
code(s) which are present but not used inside the program.
Types:
1.
single
line comment:-used to deactivate a single line using the symbol (//).
ex-//printf(“hello”);
2.
multiline
comment:-used to deactivate more than one line at a time.(/* */)
ex-/* int a;
a=5;
printf(“%d”,a); */
Although comments are not necessary to use in a program but it increases the readibility of program and it also provided your program a professional look .
Identifiers:-
These are the user-defined
words specially used for constructing variable, function or array. The length
of identifiers must not be more than 31 characters.
Also , you cannot use some terms as identifier like c or microsoft as these terms are reserved for an special purpose .
Identifiers in c are one of the most important thing.
Delimeters/literals:-
These are the special symbols which are
used for specific purposes for the programming like * is used for pointer and
& is used for address.
Keywords:-
These are also called
as reserve words.
These are the pre-defined words which carry a special meaning for
the compiler and we cannot change the name of these keywords.
There are 32
keywords available in c language.
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 |
Datatypes:-
Datatypes decides
which type of dada a variable can take.
It always used as
a suffix for the variable. There are different types datatypes used in c programming language.
1. Primary datatype:- It is
also called predefined/built-in/primitive datatype.
example:-
Datatype Bytes RANGE FS
short int | 2 | -32,768 to 32,767 | %hd |
unsigned short int | 2 | 0 to 65,535 | %hu |
unsigned int | 4 | 0 to 4,294,967,295 | %u |
int | 4 | -2,147,483,648 to 2,147,483,647 | %d |
long int | 4 | -2,147,483,648 to 2,147,483,647 | %ld |
unsigned long int | 4 | 0 to 4,294,967,295 | %lu |
long long int | 8 | -(2^63) to (2^63)-1 | %lld |
unsigned long long int | 8 | 0 to 18,446,744,073,709,551,615 | %llu |
signed char | 1 | -128 to 127 | %c |
unsigned char | 1 | 0 to 255 | %c |
float | 4 | %f | |
double | 8 | %lf | |
long double | 12 | %Lf |
2.
Secondary datatype:- It is categorized into two types.
i. derived datatype:-
ex:-array, function, pointer
ii.
user-defined datatype:- ex-struct, union, enum
Pre-Processor directives :-
A pre-processor directive will always start with a special symbol (#) and is generally known as headerfile in the code .
It main usage is found in the process of compilation it tells the compiler to do a specific task and finally on the basis of that compiler process the code .
If you want to know about best C or C++ compiler then read this post "Top Ide for C and C++ Developers - 2019 ".
You can comments us if you find anything inappropriate or you want to give more information for the topic described above .
Elements of C
Reviewed by Digital Roy
on
January 04, 2020
Rating:
No comments: