Special Topics CP 772 Lecture 2 1 - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Special Topics CP 772 Lecture 2 1

Description:

Must start with a letter or underscore. letters, digits, underscore only ... Have meaning in context with appropriate arguments. Has all of the C operators ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 23
Provided by: serv385
Category:

less

Transcript and Presenter's Notes

Title: Special Topics CP 772 Lecture 2 1


1
Special TopicsCP 772Lecture 2 - 1
2
Session Objectives
3
Comments
  • / Multi line comment /
  • // Single line comment

4
Keywords
  • 62 C keywords
  • Includes all 32 C keywords

5
Identifiers
  • Same rules as C
  • no keywords
  • Must start with a letter or underscore
  • letters, digits, underscore only
  • Double underscore __ for system use only
  • Underscore capital _Y for system use only

6
Literals
  • Constant values
  • 5
  • 5u
  • 05
  • 5
  • true
  • A

7
Operators
  • Have meaning in context with appropriate
    arguments
  • Has all of the C operators
  • Has some of its own.

8
Native Types
  • char
  • unsigned char
  • signed char
  • short
  • int
  • long

9
Native Types(2)
  • unsigned short
  • unsigned
  • unsigned long
  • float
  • double
  • long double

10
Native Types specific to C
  • wchar-t
  • bool

11
Sizes
  • Requirement is that each longer type be at least
    as large as its predecessor type.
  • Range of integral values representable on out
    system contained in limits.h
  • Range of floating point values contained in
    float.h

12
Program Structure
  • Collection of functions and definitions.
  • Block structured

13
Expressions
  • Like C, basic unit of execution
  • each expression has a value
  • each expression has a type
  • coercion required for mixed expressions
  • expression terminated by a semi colon () is a
    statement

14
Automatic Expression Conversions
  • 1/ Any bool, char, short or enum is promoted to
    int. If unrepresentable as int then promoted to
    unsigned.
  • 2/ then
  • int lt unsigned lt long lt unsigned long lt float
  • lt double lt long double

15
Conversions with Assignment expressions
  • D I // int promoted to double. Expression of
    type double
  • I D // d narrowed to int - info lost.
    Expression of type int.

16
Precedence
  • If two or more operators involved in one
    expression then we need to know which operator
    will be invoked first
  • Precedence rules help establish this

17
Associativity
  • When operands have equal precedence then
    associativity rules must be invoked

18
Casting
  • Programmer can explicitly force an expression to
    have a certain type
  • (type) expression //C cast
  • type (expression) //C cast

19
Ansi C casting
  • static_cast ltdoublegt (i)
  • reinterpret_cast ltintgt (x)
  • const_cast ltintgt (c_var)
  • dynamic_cast ltintgt (c_var)

20
Examples
  • int p, q
  • p new int(5)//allocation and initialisation
  • q new int 10 //Array of 10 integers
  • delete p // Deallocate p
  • delete q // necessary for deallocating
    arrays

21
Other concepts
  • volatile
  • enum

22
Const
  • Indicates that a variable or a function
    parameter has a non-modifiable value.
  • const int hours_in_day 24
  • const int p x
  • int const ptr y
Write a Comment
User Comments (0)
About PowerShow.com