Constants, Variables,& Keywords

download Constants, Variables,& Keywords

of 17

Transcript of Constants, Variables,& Keywords

  • 8/8/2019 Constants, Variables,& Keywords

    1/17

    Learning steps

    Constants and Variable

    Types of constants and Variables How to Identify Types

    Rules for creating Variables

    Keywords

  • 8/8/2019 Constants, Variables,& Keywords

    2/17

    Learning Stepsy Learning C# language is similar to learning English

    y It begin with Alphabets and digits.

    yAlphabets to form words, words to form sentencesand sentences to form paragraph and the processcontinues

    y Digits forms different numbers.

  • 8/8/2019 Constants, Variables,& Keywords

    3/17

    The following help in building C# language

    Alphabets, Digits and Special Symbols.

    Constants & Variables Data Types.

    Keywords

  • 8/8/2019 Constants, Variables,& Keywords

    4/17

    Alphabets, Digits and Special

    Symbolsy C# allows all alphabet irrespective of they are capital

    letter i.e A-Z or small case letters .i.e a-z.

    y Digit ranging from 0-9.y 32 special symbol in the keyboard.

  • 8/8/2019 Constants, Variables,& Keywords

    5/17

    Constants&VariablesyAlphabets, digits and special symbols are combined to

    form constants and variables.

    y For example 3x+2y where 3and 2 are constants astheir values does not change ,they are also called asliterals.

    y variables are x and y as their values changes ,they are

    also called as identifiers.

  • 8/8/2019 Constants, Variables,& Keywords

    6/17

    ConstantsThere are three types of Constants.

    y Integer Constants

    y Real Constantsy Character Constants

  • 8/8/2019 Constants, Variables,& Keywords

    7/17

    Integer Constantsy Example of Integer constants are 23, 56, 678 etc.

    Rules for creating Integer Constant

    It should not have decimal point. It can be either +ve or-ve The default is +ve.

    Within integer constant their should not be commaand space.

    The valid range of integers constants is -2147483648 to+2147483647.

  • 8/8/2019 Constants, Variables,& Keywords

    8/17

    RealConstantsy It must have decimal point present.

    y It can be +ve or-ve. The default is +ve.

    y There should not be a comma or space within realconstant.

    yValid range of real constants is -3.4*1038 to +3.4*1038

    y For example 427.62, -0.00254 can be expressed in the

    form 4.2762E2,-2.54e-3 etc.

    y The first form is fractional form and second form isknown as exponential form.

  • 8/8/2019 Constants, Variables,& Keywords

    9/17

    Character ConstantsyWhen a character, digit or special symbol is written

    within a pair of single inverted commas form a

    character constant.y It can be capital letter, small case letter, a digit or

    special symbol within single inverted commas.

    y For example

    y Zy Nagpur is not a character constant it is string

    constants

  • 8/8/2019 Constants, Variables,& Keywords

    10/17

    String Constantsy String constants are enclosed in double quotes

    string message = Hello;

    y for example Nagpur.

  • 8/8/2019 Constants, Variables,& Keywords

    11/17

    Types ofConstants

    11

    Character constants char c = z

    Numeric constants int a = 10;

    Hexadecimal constants int hex = 0xFF;

    Octal constants int oct = 011;

    String constants char greetings = Hello;

    Backslash constants \b, \f, \n, \r, \t, \, \, \0, \\,

    \v, \a, \?, \OCTAL, \xHEX

  • 8/8/2019 Constants, Variables,& Keywords

    12/17

    C# Data Types-PrimitivesData Types Ranges sizes

    char 0 t0 65535 2

    sbyte -128 to +127 1

    short -32768 to +32767 2

    int -2147483648 to+2147483647

    4

    long -9223372036854775808 to+92233720368547758087

    8

    float -3.4e38 to +3.4e38 4

    double -1.7e308 to + 1.7e308 8

    bool True/false 1

  • 8/8/2019 Constants, Variables,& Keywords

    13/17

    VariablesyA name given to memory location whose value

    changes is called as variable.

    yNo of variables are equal to no of constants.

    y for example

    y x=3,y=4

    y Z=x+y

  • 8/8/2019 Constants, Variables,& Keywords

    14/17

    How to identify Typesy 3 Integer Constant

    y 3.0 Real Constant

    y 3 Character Constant

    y int a float b char c

    y a=3 b=3.0 c=3

    y int ,float ,char data types /primitives

    y a,b,c variables

    y 3,3.0,3 constants/literals

  • 8/8/2019 Constants, Variables,& Keywords

    15/17

    Rules for Building var. Namesy Cannot begin with a digit

    y Rest can be alphabets,digits,underscores or $

    y Ex pop98 , si_intyAny length.

    y No commas or spaces.

    yVariable names are case sensitives

    y for example the following are consider differentvariables

    y abc ABC Abc aBc AbC

  • 8/8/2019 Constants, Variables,& Keywords

    16/17

    C# keywordsyWords whose meaning already stands explained to

    machines are called as Keywords.

    y77 keywords available in c#.

    y int,float and char are keywords

    y Reserved are same as keywords.

    y Following declaration of variable will not work

    y integer a

    y real b

    y character c

  • 8/8/2019 Constants, Variables,& Keywords

    17/17

    y Proper declaration of variable which machineunderstands is

    yint a

    y float b

    y char c