2. Identifiers
In C programming, identifiers are name given to C entities, such as
variables, functions, structures etc.
An identifier can be composed of letters such as uppercase,
lowercase letters, underscore, digits, but the starting letter should
be either an alphabet or an underscore.
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:
Total, sum_1, average, _money
3. Keywords
Keywords are the words whose meaning has already been
explained to the C compiler. We cannot use it as a variable
name, constant name, etc. We can also call as reserved
words in C. There are only 32 reserved words (keywords) in
the C language.
auto break case char const continue default do
double else enum extern float for goto if
int long register return short signed sizeof static
struct switch typedef union unsigned void volatile while
4. Data Types
A data type specifies the type of data/value we want to store in
a variable.
Data
Types
Primitive
int, float,
char,double
Derived
Array
pointer
User defined
struct,
union, enum
Void
Empty value
5. Data type and Sizes
Type
name
32-bit size Format
specifier
Range
char 1 byte %c (-128 to 127) or (0 to 255)
int 2 or 4
bytes
%d -32768 to 32767 or
-2147483648 to -2147483647
float 4 bytes %f 1.2E-38 to 3.4E+38
double 8 bytes %lf 1.7E-308 to 1.7E+308
Each data type requires different amount of memory. Different
data types also have different ranges up to which they can store
numbers. These ranges may vary from compiler to compiler.
6. Constants
Constants refer to fixed values that the program may not alter
during its execution. These fixed values are also called literals.
Types of
Literals
Integer
Literal
Eg 23, -37
Float
Literal
E.g.10.5,-1.2
Character
Literal
E.g. ‘F’ ‘4’
String
Literal
e.g. “hello”
7. Constants
If we want to define a variable whose value cannot be changed, we
can use the const keyword.
const double PI=3.14;
We can also define a constant using #define preprocessor directive.
#define PI 3.14
8. Variables
A variable is a name of the memory location. It is used to store
data. Its value can be changed, and it can be reused many times.
It is a way to represent memory location through symbol so that it
can be easily identified.
Syntax to declare variable
Data type variable_name
Example:
int a;
char b;
float c;
Here, a, b, c are variables. The int, char, float are the data types.
We can also provide values while declaring the variables
int a=10;
char b='A';
float c=20.8;
9. Rules for variable name
1. A variable can have alphabets, digits, and underscore.
2. A variable name can start with the alphabet, and
underscore only. It can't start with a digit and blank
spaces.
3. No whitespace is allowed within the variable name.
4. A variable name must not be any reserved word or
keyword, e.g., int, float, etc.