Constants, Variables and Keywords- part 5.
Contents
- 0.0.1 Constants, Variables, and Keywords – Part 5
- 0.0.2 1. Constants:
- 0.0.3 Examples:
- 0.0.4 2. Variables:
- 0.0.5 Declaration and Initialization:
- 0.0.6 3. Keywords:
- 0.0.7 Examples of Keywords:
- 0.0.8 Differences Summary:
- 0.0.9 Quick Exercise:
- 0.0.10 Constants, Variables and Keywords- part 5.
- 0.0.11 5. Variables and Constants
- 0.0.12 Introduction to C
- 1 Constants, Variables, and Keywords in C
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.
अगर आपको किसी और टॉपिक पर जानकारी चाहिए या और प्रैक्टिस करनी है, तो बताएं!
Constants, Variables and Keywords- part 5.
5. Variables and Constants
Introduction to C
Here is Part 5 of the “Getting Started with C Programming” series, focusing on:
Constants, Variables, and Keywords in C
1. What are Constants in C?
Constants are fixed values that do not change during the execution of a program.
Types of Constants:
Type | Example | Description |
---|---|---|
Integer Constant | 100 , -25 |
Whole numbers |
Floating Constant | 3.14 , -0.5 |
Decimal numbers |
Character Constant | 'A' , '9' |
Single characters in single quotes |
String Constant | "Hello" |
Group of characters in double quotes |
Example:
const
keyword makes a variable read-only (cannot be modified later).
2. What are Variables in C?
A variable is a named location in memory used to store data temporarily.
Syntax:
Example:
Rules for Naming Variables:
-
Must begin with a letter (A–Z or a–z) or underscore (_).
-
No spaces or special characters.
-
Case-sensitive (
Total
≠total
). -
Avoid using keywords as variable names.
3. What are Keywords in C?
Keywords are reserved words with special meaning. They cannot be used as variable names.
Examples of Keywords in C:
Example:
Quick Recap:
Concept | Purpose | Example |
---|---|---|
Constant | Fixed value | const int a = 10; |
Variable | Storage for changing data | float height = 5.7; |
Keyword | Reserved words in C language | if , int , while |
Practice Questions:
-
Which of the following is a valid variable name?
a)1value
b)value1
c)float
d)value#
-
What will happen if you try to change the value of a
const
variable?
Would you like a quiz, worksheet, or Part 6: Data Types in C next?