+ All Categories
Home > Documents > Data Types Presentation 1

Data Types Presentation 1

Date post: 06-Apr-2018
Category:
Upload: syed-muhammad-zaidi
View: 225 times
Download: 0 times
Share this document with a friend

of 25

Transcript
  • 8/2/2019 Data Types Presentation 1

    1/25

    Enge:SajidaIntroduction to computing

    Identifier

    The identifiers are the names used torepresent variable ,constants, types

    functions in the program

    Types of identifiers

    Standard identifiers

    User defined identifiers

  • 8/2/2019 Data Types Presentation 1

    2/25

    Enge:SajidaIntroduction to computing

    Standard identifier

    A type of identifier that has the special meaning

    in the c++

    cout and cin are example of standard identifiers

    User-defined IdentifierThe type of Identifier that is defined by the

    Programmer to access memory location known

    as user-defined Identifier.

  • 8/2/2019 Data Types Presentation 1

    3/25

    Enge:SajidaIntroduction to computing

    The user-defined identifiers are used to store

    data and program results.

    Some examples of user-defined identifiers are,

    marks and age etc.

  • 8/2/2019 Data Types Presentation 1

    4/25

    Enge:SajidaIntroduction to computing

    Keywords

    Keywords is a word in C++ language that has a

    predefined and purpose.

    The meaning and purpose of a keyword is

    defined by the developer of the language.

    It can not be changed or redefined by user.

    Keyword can be used for the same purpose for

    which it is defined.

    Keyword can be used for the same purpose for

    which it is defined.

  • 8/2/2019 Data Types Presentation 1

    5/25

    Enge:SajidaIntroduction to computing

    Keywords are also known as reserved words.

    These are different types of keywords in C++

    language.

    The total number of keywords is 63.

    Char, do, If struct float

  • 8/2/2019 Data Types Presentation 1

    6/25

    Enge:SajidaIntroduction to computing

    Data types

    Data type defines a set of values and a set of operations

    of those values

    The data is given to the program as input

    The data is processed according to the program

    instruction and output is returned

    A C++ program may need to process different types of

    data

    Each data type require different amount of memory

  • 8/2/2019 Data Types Presentation 1

    7/25

    Enge:SajidaIntroduction to computing

    Types of data type

    Integer data typeFloat data type

    Double data type

    Char data type

  • 8/2/2019 Data Types Presentation 1

    8/25

    Enge:SajidaIntroduction to computing

    Integer data type

    A numeric value that has no decimal point or fraction

    It includes both positive and negative valueTypes of integers

    C++ provides different types of integer data

    Int

    Short intLong int

    Unsigned int

    Unsigned long int

  • 8/2/2019 Data Types Presentation 1

    9/25

    Enge:SajidaIntroduction to computing

    Int data type

    Is used to store integer values

    It takes two or four bytes in memoryIt takes two bytes and its range is from -32768 to 32767

    Unsigned int data type

    Is used to store the positive integer values

    It takes two bytes in memoryIts range is from 0 to 65,535

  • 8/2/2019 Data Types Presentation 1

    10/25

    Enge:SajidaIntroduction to computing

    Unsigned long integer data type

    Is used to store positive integer values

    It takes four bytes in memory its range is from 0 to4,294967295

    Long integer data type

    Long integer data type is used to store large integer

    valueIt takes 4 bytes in memory

    Its range is from2,147,483648 to 2,147,483,647

    Short int data type

    Is used to store integer value

    It takes two bytes in memory

    Its range is from o to 65,535

  • 8/2/2019 Data Types Presentation 1

    11/25

    Enge:SajidaIntroduction to computing

    Real data type

    Real data type is numeric value with decimal point or

    fraction

    It is also called floating point number

    It includes both positive number and negative number

    Example are 10.5,-10.91

    Types

    Float

    Long float

    Double

    long double

  • 8/2/2019 Data Types Presentation 1

    12/25

    Enge:SajidaIntroduction to computing

    Float data type

    Float data type is used to store real values

    It takes four bytes in memoryIts range is from 3.4*1038 to 3.4*10-38

    Double data type

    Double data type is used to store large real values

    It takes 8 bytes in memory

    Its range is from 1.7*10-308 to 1.7*10308

    It provides accuracy of 15 decimal places

  • 8/2/2019 Data Types Presentation 1

    13/25

    Enge:SajidaIntroduction to computing

    Long double data type

    Long double data type is used to store very large

    real values

    It takes 10 bytes in memory

    its range is from 1.7*10-4932 to 1.7*10 4932

    it provides accuracy of 19 decimal places

  • 8/2/2019 Data Types Presentation 1

    14/25

    Enge:SajidaIntroduction to computing

    Character data type

    Char data type is used to store char value

    It takes one byte in memoryIt is used to represent a letter, number, or punctuation mark and a

    few other symbols

    Character values is normally given in single quotes

    It can represent individually characters such as a,x,5

    Character 5 is treated differently than integer 5

    The key word signed and unsigned can be used char data type

    The signed character can represent number from 127 to -128

    The unsigned characters can represent number from 0 to 255

  • 8/2/2019 Data Types Presentation 1

    15/25

    Enge:SajidaIntroduction to computing

    Integer over flow and under flow

    Integer overflow occurs when the value assignedto an integer variable is more than its

    maximum possible value

    Integer underflow occurs when the value is

    assigned to an integer is less than possible

    minimum value

  • 8/2/2019 Data Types Presentation 1

    16/25

    Enge:SajidaIntroduction to computing

    Variables

    A variable is a named memory location or memory cell

    It is used to store programs input data and itscomputational results during execution

    The value of a variable is changed during the executionof program

    The value stored in a variable is referred by variable

    nameThe variables are created in RAM

    Data stored in variable is temporary

    It can be used and processed during the execution of theprogram

    The data stored in the variables is automaticallyremoved when program ends

  • 8/2/2019 Data Types Presentation 1

    17/25

    Enge:SajidaIntroduction to computing

    The value of a variable is changed during

    program execution but its name will remain

    same

    Marks

    10

    Name of variable

    Location of variable

    Computer memory

  • 8/2/2019 Data Types Presentation 1

    18/25

    Enge:SajidaIntroduction to computing

    Variables declaration

    The process of specifying the variable name and its typeis called variable declaration

    All variable must be declared before they are used in theprogram

    Compiler uses the declaration to determine how muchmemory is needed for each variable

    Different type of variables require different amount ofmemory

    The required number of bytes are allocated when avariable is declared

  • 8/2/2019 Data Types Presentation 1

    19/25

    Enge:SajidaIntroduction to computing

    Syntax

    The syntax of declaring variable is as follows

    Data- type variable-name ;Data type it indicates type of data that can be stored in

    variable

    Variable name refers to memory location of the variable

    Int marks;

    float avg;

    Double salary;

  • 8/2/2019 Data Types Presentation 1

    20/25

    Enge:SajidaIntroduction to computing

    Variable initialization

    The process of assigning a value to a variable at the time ofdeclaration

    The equal sign is used to initialize a variableSyntax

    Typename variable = value ;

    Type name indicates the data type of the variable to be initialized

    Variable name of the variable to be initialized= assignment operator

    Value it is the value to initialize a variable

    Int n =100;

  • 8/2/2019 Data Types Presentation 1

    21/25

    Enge:SajidaIntroduction to computing

    Constant

    Constant is the quantity that cannot be change duringthe program execution

    Types

    Literal constant

    Symbolic constant

    Literal constant is a value that is typed directly in theprogram

    It appears in the program where it is needed

    Hello world is string literal constant

  • 8/2/2019 Data Types Presentation 1

    22/25

    Enge:SajidaIntroduction to computing

    Types of literal constants

    Integer constantFloating point constant

    Character constant

    String constant

  • 8/2/2019 Data Types Presentation 1

    23/25

    Enge:SajidaIntroduction to computing

    Symbolic constant

    A symbolic constant is a name given to the values that

    can no be changed

    Symbolic constants are used to represent a value that is

    frequently used in the program

    Types of symbolic constantConst qualifier

    Define Directive

  • 8/2/2019 Data Types Presentation 1

    24/25

    Enge:SajidaIntroduction to computing

    Const Qualifier

    Const qualifier is used to define a constant

    Const is declared by its name and its data type

    The const must be initialized with some value theinitialized value can not be changed during the

    program executionSyntax

    Const data type identifier=value;

    Const int N=100;

  • 8/2/2019 Data Types Presentation 1

    25/25

    Enge:SajidaIntroduction to computing

    Define directive

    Also used to define a constant

    It does not specify the data type of the constant

    Define directive starts with # symbol

    It is not terminated with semicolon

    Syntax

    #define identifier value

    # starts of preprocessor directive

    Define used to define a constant

    Identifier it is the name of constant

    Value it represents the value associated with theidentifier

    #define PI3.141593


Recommended