Constants, Variables and Keywords- part 5.

Constants, Variables and Keywords- part 5.



play-rounded-fill play-rounded-outline play-sharp-fill play-sharp-outline
pause-sharp-outline pause-sharp-fill pause-rounded-outline pause-rounded-fill
00:00

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:

# Python example
age = 25 # Variable 'age' holding an integer value
name = "Alice" # Variable 'name' holding a string value
c
// C example
int age = 25; // Variable 'age' holding an integer value
char name[] = "Alice"; // Variable 'name' holding a string value

 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:

  1. Identify constants, variables, and keywords in the following line:
    count = 10
    while count > 0:
    print("Hello")
    count -= 1
  2. Write any 3 keywords of C language.

अगर आपको किसी और टॉपिक पर जानकारी चाहिए या और प्रैक्टिस करनी है, तो बताएं!

Constants, Variables and Keywords- part 5.

5. Variables and Constants

Introduction to C



Leave a Reply

Your email address will not be published. Required fields are marked *

error: