06-06-2013, 03:59 PM
Literals, Variables and Data Types
Literals.pptx (Size: 91.34 KB / Downloads: 19)
Introduction
C# program is collection of classes
Classes are collection of methods and some statements
That statements contains tokens
C# includes five types of tokens
Identifiers
Keywords
Literals
Operators
Punctuators
Identifiers
That are programmer designed tokens (like variable name)
They are used to naming classes, methods, variables, labels, namespaces etc..
Rules for Identifiers are as follows:-
They can have alphabets, digits and underscore characters
They must not begins with digit
Uppercase and lowercase letters are distinct
Keywords in standalone can not be use as identifier
Keywords
That are the reserved words, and whose meaning is already explained to the C# compiler
They can not be used as identifiers except when they are prefaced by @ character
Some Examples of keywords are
Literals
Literals are the way in which values that are stored in variables are represented
So it is the value constants assigned to variables, or it is a result of expression in program
Integer literals
That is sequence of digit
There are two type of integer
Decimal (digit between 0 to 9 with optional minus sign)
Hexadecimal (sequence preceded by 0x )
Spaces, commas and non-digit characters are not permitted between digits
Variable
A variable is an identifier that is used to give name of storage location
Constant remain unchanged during the program execution ,
A variable can change value during program execution
Variable name can be chosen by programmer in a meaningful way, so as to reflect what it represent in program
Variable name can be of any length
Data Type
It specifies size and type of values can be stored
Data types are divide in two categories:
Value type
Reference type
These two types differ to each other by
Where they are stored in memory
How they behave in context of assignment statement
Value type stored on stack, and when a value of variable assigned to another variable it actually copies the value, so two identical copies of the value are available in memory
Reference type stored on heap of memory , when an assignment between two reference variable occurs, it copies only reference , actual value remains in same memory location