Time Management & Productivity - Best PracticesVit Horky
The six step guide to practical project managementMindGenius
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
Ad
LDP - Variables and Constants - Technology
1. int age = 21; const int age = 21;
VARIABLES CONSTANTS
VS
Presented to : XYZ
Presented by : Rishabh
2. Variables are like containers that store data values.
They can change during the program's execution.
In C, you must declare a variable before using it,
specifying its type (like int, float, char).
What are Variables?
3. Constants are fixed values that do not change
during the program's execution.
In C, you can define constants using the 'const'
keyword or by using preprocessor directives like
#define.
What are Constants?
4. Variables can change their
value, while constants
remain the same.
Variables require memory
allocation, whereas
constants do not.
Variables are declared with a
type, constants can be defined
in various ways such as
const int age = 21 or #define PI
3.14
Key Differences Between Variables and Constants
5. To declare a variable, you specify the type followed
by the variable name. For example:
int age;
float salary;
char grade;
Declaring Variables in C
6. You can define a constant like this:
const float PI = 3.14;
This means the value of PI will always hold the value
3.14 throughout the program.
Using Constants in C
7. Use constants for
values that should
remain unchanged,
like mathematical
constants.
When to Use Variables and Constants
Use variables when
you need to store
data that may
change.
8. Example for Variables
and Constants :
#include <stdio.h>
int main() {
int age = 18;
const float PI = 3.14;
printf('Age: %d, PI: %.2f', age, PI);
return 0;
}