Variables and Data Types Questions

1.) What is a collection of Tokens in C#?                                                                        
There are five types of token in c#.
  • Keywords
  • Identifier
  • Operators
  • Literals
  • Punctuators

2.) What is Literal?                                                                                                              
 Literals are the way in which the values that are stored in variables are represented.
3.) What are the types of literal in C#?                                                                           
  • Integer Literals
  • Real Literals
  • Boolean Literals
  • Single Character Literals
  • String Literals
  • Backslash character Literals

4.) What is a Constant in C#?                                                                                             
A Constant variable is those variable ,Whose value does not change during the execution of a Program.

5.) What is an Identifier in C#?                                                                                        
 Identifiers are the programmer-designed tokens that are used for Naming classes,Methods & Namespace etc.

6.) What is a variable in C#?                                                                                               
A variable is an Identifier that indicate a storage location used to a store data.

7.) What is a  Local variable in C#?                                                                                  
 A Local variable is variable, that scope is defined within the curly braces.
Class student
public static void Main()
int a=25;
Console.WriteLine(a);     //error occurs
More Details...

8.) What are the difference between Value Type and Reference Type   in C#?       
 Value Type:-
 A Value Type is stored on the stack memory.When an assignment between two value type variable occurs,the value is actually copied,this means that two identical copies of the values available in the stack memory.
Reference Type:-
A reference Type is stored in heap memory.Only one copy of the value is available in heap memory.It means ,Here reference is copied, not value.
More Details...
 9.) Which types of variable is used for assignment of default value?                      
  • Static variables
  • Instance variables
  • Array elements
10.) What is Boxing and Unboxing  in C#?                                                                      
A Boxing is the process through which any type,value or reference can be assigned to an object without any explicit Conversion.
Ex .
int a = 20;
object b = a; //Create a Box to hold b
Note:- Here a is stored in stack memory but b stored in a heap memory.Both are independent to each other.
class student
{public Static void Main()
int a = 10;
object b = a;
Unboxing:- An Unboxing is the process of converting the object type  to value type.It is totally reverse of Boxing process.
int a = 20;
object b = a;
int c=(int)b;  //Unboxing object b to the int c 
In above example ,if we store the  b  into a byte type variable c,then it will give error.Because
variable c is  less size to hold the value of b.
byte c = (byte) b ;             //error


Post a Comment

Powered by Blogger.