Variables_Quiz.md - brainchildservices/curriculum GitHub Wiki
- What is a variable?
- A variable can be compared to a storage room, and is essential for the programmer.
- How we can define a variable?
data type
name
;
- How we can declare a value to a variable?
data type
name
=value
;
-
Point out different types of variables in C#
- Local variables
- Instance variables or Non โ Static Variables
- Static Variables or Class Variables
- Constant Variables
- Read only Variables
-
characteristics for defining a variable
- A variable can have alphabets, digits, and underscore.
- A variable name can start with the alphabet, and underscore only. It canโt start with a digit.
- No whitespace is allowed within the variable name.
- A variable name must not be any reserved word or keyword, e.g. int, goto , etc.
-
Point out Categories of datatypes:
- Value type
- Reference type
- Pointer type
-
Define Value type.
- A data type is a value type if it holds a data value within its own memory space. It means the variables of these data types directly contain values.
- Point out some value type datatype
- bool
- byte
- char
- decimal
- double
- enum
- float
- int
- Define Reference type
- A reference type doesn't store its value directly. Instead, it stores the address where the value is being stored. In other words, a reference type contains a pointer to another memory location that holds the data.
- What is a pointer?
- A pointer is a variable that stores a memory address. Pointers are used to store the addresses of other variables or memory items.
- Some example for Reference datatype.
- String
- Arrays
- Class
- Delegate
- Differences between local and global variables
Local Variables
- Local Variables are declared within a function block.
- The scope is limited and remains within the function only in which they are declared.
- If the local variable is not initialized, it takes the garbage value by default.
- We can declare various variables with the same name but in other functions.
Global Variables
- Global variables are declared outside all the function blocks.
- The scope remains throughout the program.
- If the global variable is not initialized, it takes zero by default.
- We cannot declare many variables with the same name.