Unit IV: C Fundamentals (6)
Character set of C, Variables, Constants, Identifiers, Rules for Declaring an Identifier, Key
words, Data types, Enumerated Data type, typedef, typecasting, Delimiters, Operator in C
(Arithmetic, Assignment, Comma, Increment, Decrement, Relational, Logical, address of, sizeof,
ternary operator), Hierarchy- Precedence and Associatively of Operators
Statements( Executable and Non- Executable Statements), Comments
Basic Structure of a C Program, Pre- processor Directive, Input/ Output Functions, Format
Specifiers, Field width Speci
fiers, Escape Sequences
Programming Examples
What is C language?
C programming is a general-purpose, procedural, very important computer programming
language developed in 1972 by Dennis M. Ritchie at the Bell Laboratory to develop the UNIX
operating system. Every functions of C are made by its own set of library functions and every
library functions are accompanied (along with) by their header file.
Character set of C: As every language contains a set of characters used to construct words,
statements, etc., C language also has a set of characters which include alphabets, digits,
and special symbols. C language supports a total of 256 characters.
Every C program contains statements. These statements are constructed using words and these
words are constructed using characters from C character set. C language character set contains
the following set of characters...
1. Alphabets
2. Digits
3. Special Symbols
Alphabets
C language supports all the alphabets from the English language. Lower and upper case letters
together support 52 alphabets.
Lower case letters - a to z
Upper case letters - A to Z
Digits
C language supports 10 digits which are used to construct numerical values in C language.
Digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Special Symbols
C language supports a rich set of special symbols that include symbols to perform mathematical
operations, to check conditions, white spaces, backspaces, and other special symbols.
Special Symbols - ~ @ # $ % ^ & * ( ) _ - + = { } [ ] ; : ' " / ? . > , < \ etc.
Variables: A variable is a container (storage area) to hold data. To indicate the storage area,
each variable should be given a unique name (identifier). Variable names are just the symbolic
representation of a memory location.
Rules for naming a variable
A variable name can only have letters (both uppercase and lowercase letters), digits and
underscore.
The first letter of a variable should be either a letter or an underscore.
There is no rule on how long a variable name (identifier) can be. However, you may run into
problems in some compilers if the variable name is longer than 31 characters.
C variable type cannot be changed once it is declared.
For example:
int number = 5; // integer variable
number = 5.5; // error
float number; // error
Constants: 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. Constants are treated just like regular variables except
that their values cannot be modified after their definition.
If we want to define a variable whose value cannot be changed, you can use the const keyword.
This will create a constant. For example,
const double PI = 3.14; // Notice, we have added keyword const.
Here, PI is a symbolic constant; its value cannot be changed.
const double PI = 3.14;
PI = 2.9; //Error
We can also define a constant using the #define preprocessor directive.
Identifiers: Identifier refers to name given to entities such as variables, functions, structures etc.
Identifiers must be unique. They are created to give a unique name to an entity to identify it
during the execution of the program.
For example:
int money;
double accountBalance;
Here, money and accountBalance are identifiers.
Also remember, identifier names must be different from keywords. You cannot use int as an
identifier because int is a keyword.
Rules for constructing C identifiers
The first character of an identifier should be either an alphabet or an underscore, and then it
can be followed by any of the character, digit, or underscore.
It should not begin with any numerical digit.
In identifiers, both uppercase and lowercase letters are distinct. Therefore, we can say that
identifiers are case sensitive.
Commas or blank spaces cannot be specified within an identifier.
Keywords cannot be represented as an identifier.
The length of the identifiers should not be more than 31 characters.
Identifiers should be written in such a way that it is meaningful, short, and easy to read.
For example,
int student;
float marks;
Here, student and marks are identifiers.
We have to remember that the identifier names must be different from keywords. We cannot use
int as an identifier, because int is a keyword.
Consider another example for identifier.
int var1, var2;
float Avg;
function sum();
Here,
int, float, function are all keywords.
var1, var2, Sum, Avg, are the identifiers.
Keywords are used along with identifiers to define them. Keywords explain the functionality of
the identifiers to the compiler.
Keywords: Keywords are reserved words that have special meaning in the C language. The
meaning of C language keywords has already been described in the C compiler. These meanings
cannot be changed. Thus, keywords cannot be used as Variable name because that would try to
change the existing meaning of the keyword, which is not allowed. There are a total of 32
keywords in the C
auto double int struct
break else long switch
case enum register typedef
const extern return union
char float short unsigned
continue for signed volatile
default goto sizeof void
do if static while