0% found this document useful (0 votes)
31 views1 page

Variables

The document discusses key concepts related to variables in programming, including initialization, declaration, and expressions. It emphasizes the importance of validating user input and outlines best practices for naming variables. Specific syntax and examples are provided to illustrate these concepts.

Uploaded by

Neha Makhija
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views1 page

Variables

The document discusses key concepts related to variables in programming, including initialization, declaration, and expressions. It emphasizes the importance of validating user input and outlines best practices for naming variables. Specific syntax and examples are provided to illustrate these concepts.

Uploaded by

Neha Makhija
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Variables in Real Life

1.) Process of assigning value to a variable before it is being used is called:


Answer: Initialization
Reason: Initialization is the process of assigning a value to a variable.

2.) int k1, k2 = 23 is an example of:


Answer: Variable declaration
Reason: A variable can be declared using the below syntax:
Datatype Variable Name = Value;

3.) What is an expression?


Answer: An expression is a combination of literals, operators, variables, and parentheses used to
calculate a value.
Reason: An expression is a combination of values, variables, operators, and calls to functions.
Expressions need to be evaluated.

4.) What is the value of the following expression?


(2 – 6) / 2 + 9
Answer: 7
Reason: First we solve the brackets and then divide it by 2 and then add
9 and result is 7.

5.) What is variable initialization?


Answer: The process of assigning values in a variable at the time of declaration is called variable
initialization. = symbol is used to initialize a variable. A single variable name must appear on the left
side of the = symbol. All variables should be initialized to avoid any problem.

6.) What is the syntax to initialize a variable in programming?


Answer: A variable can be initialized using the below syntax:
Datatype Variable_Name = Value;
Example of declaring a variable in python
A = 34
B = “hello”
Here A is the variable name and 34 is the value assigned to that variable.

7.) Why do you think validating user input is important in programming?


Answer: Whenever we create a variable in with a specific data type we expect user to input a
certain value in the data type but sometimes it could throw some error if the user enters a
value of different data type and to avoid any error during program execution, we need to
validate user input first.

8.) What are your opinions on naming convention of variables declared in programming?
Write down five best practices that you think one should follow while declaring variables.
Answer: Naming conventions of variables are really important because while naming
conventions provide us a set of rules for choosing a sequence of characters to identify
variables. It helps us improve the clarity of the code and it looks more systematic.
Five best practices that you should follow:
 There shouldn’t be any black space used in a variable.
 The first character of a variable must be a letter or underscore.
 Variables may not begin with a digit.
 The max length of a variable should be up to 31 characters.
 Both uppercase and lowercase letters can be used for naming variables.

You might also like