Chapter 2 - Basic of c - Variable Data Types
Chapter 2 - Basic of c - Variable Data Types
D ATA S T R U C T U R E a n d A L G O R I T H M S
• 2.1.1 Variables in C:
⚬ A variable in C is a memory location with some name that helps
store some form of data and retrieves it when required.
⚬ The syntax to declare a variable in C:
data_type Name;
or data_type Name = Value;
• 2.1.1 Variables in C:
⚬ Example:
// C Program
#include <stdio.h>
int main()
{
// variable declaration:
int x1; // integer variable
fl oat x2; // fl oat variable
return 0;
}
2 . 1 VA R I A B L E S a n d D ATA T Y P E S :
• 2.1.1 Variables in C:
⚬ C Variable Types: The C variables can be classified into the
following types:
⚬ Local Variables: is a variable that is declared inside a function
or a block of code. Its scope is limited to the block or
function in which it is declared.
⚬ Global Variables: is a variable that is declared outside the
function or a block of code. We can access the global
variable anywhere in the C program after it is declared.
⚬ Static Variables: is a variable that is defined using
the static keyword. It can be defined only once in a C program
2 . 1 VA R I A B L E S a n d D ATA T Y P E S ?
• 2.1.1 Variables in C:
⚬ Example:
// C Program
#include <stdio.h>
int x1; // global variable
int main()
{
int x1; // local variable
fl oat x2; // fl oat variable
return 0;
}
2 . 1 VA R I A B L E S a n d D ATA T Y P E S :
return 0;
}
2 . 1 VA R I A B L E S a n d D ATA T Y P E S :
• 2.2 Operator:
⚬ An operator in C can be defined as the symbol that helps us to perform
some specific mathematical, or logical computations on values and variables.
⚬ The values and variables used with operators are called operands.
⚬ In C language, operators can be classified into 6 types:
⚬ Arithmetic Operators
⚬ Assignment Operators
⚬ Relational Operators
⚬ Logical Operators
⚬ Bitwise Operators
⚬ Other Operators
2 . 2 O P E R AT O R I N C :