Variables_Quiz.md - brainchildservices/curriculum GitHub Wiki

  1. What is a variable?
  • A variable can be compared to a storage room, and is essential for the programmer.
  1. How we can define a variable?
  • data type name;
  1. How we can declare a value to a variable?
  • data type name = value;
  1. 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
  2. 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.
  3. Point out Categories of datatypes:

    • Value type
    • Reference type
    • Pointer type
  4. 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.
  1. Point out some value type datatype
  • bool
  • byte
  • char
  • decimal
  • double
  • enum
  • float
  • int
  1. 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.
  1. 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.
  1. Some example for Reference datatype.
    • String
    • Arrays
    • Class
    • Delegate
  2. 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.