DIZNR INTERNATIONAL

Constants, Variables and Keywords- part 5.

Constants, Variables and Keywords- part 5.

https://www.gyanodhan.com/video/7A2.%20Computer%20Science/Let%20Us%20C%20Programming/185.%20Let%20Us%20C%20by%20Yashavant%20P.%20Kanetkar%20-%20Constants%2C%20Variables%20and%20Keywords-%20part%205.mp4

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:

 2. Variables:

Variables are memory locations that hold data and whose value can change during program execution.

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:

 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

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:

c
const int age = 18;
printf("Age = %d", age); // Age = 18

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:

c
data_type variable_name;

Example:

c
int marks = 95;
float pi = 3.14;
char grade = 'A';

Rules for Naming Variables:


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:

cpp
int, float, return, if, else, while, for, break, continue, const, void, char, double

Example:

c
int return = 5; // Error! "return" is a keyword

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:

  1. Which of the following is a valid variable name?
    a) 1value
    b) value1
    c) float
    d) value#

Correct Answer: b) value1

  1. What will happen if you try to change the value of a const variable?

It will give a compile-time error.


Would you like a quiz, worksheet, or Part 6: Data Types in C next?

unit-2 – constant,variable & data types

Constants, Variables and Keywords- part 5.

Variables and Constants – Pearson Higher Education