Constants, Variables and Keywords- part 5.
Constants, Variables and Keywords- part 5.
Contents [hide]
Constants, Variables, and Keywords – Part 5
1. Constants:
Constants are fixed values that do not change during the execution of a program. They can be of various types, like integer constants, floating-point constants, character constants, and string constants.
Examples:
- Integer Constant:
5, -10, 100
- Floating-point Constant:
3.14, -0.99, 2.5e3
- Character Constant:
'A', 'b', '$'
- String Constant:
"Hello"
,"12345"
2. Variables:
Variables are memory locations that hold data and whose value can change during program execution.
- They should have meaningful names.
- The value stored in a variable can be updated.
Declaration and Initialization:
3. Keywords:
Keywords are reserved words that have special meanings in programming languages. They cannot be used as variable names.
Examples of Keywords:
- In Python:
if
,else
,while
,for
,def
,return
,break
- In C/C++:
int
,float
,char
,if
,else
,while
,return
,void
- In Java:
class
,static
,public
,void
,new
,try
,catch
Differences Summary:
Feature | Constants | Variables | Keywords |
---|---|---|---|
Definition | Fixed values | Changeable data | Reserved words |
Changeable | No | Yes | No |
Example | 3.14 , "Hello" |
age = 25 , name = "Bob" |
int , for , while |
Quick Exercise:
- Identify constants, variables, and keywords in the following line:
- Write any 3 keywords of C language.
अगर आपको किसी और टॉपिक पर जानकारी चाहिए या और प्रैक्टिस करनी है, तो बताएं!