C++

22
RAFIYA SIRIN XI-B C++ INTRODUCTION AND TOKENS MADE BY:

description

 

Transcript of C++

Page 1: C++

RAFIYA

SIRIN XI-B

C++ INTRODUCTION AND TOKENS

MADE BY:

Page 2: C++

C++ INTRODUCTIONC++ was developed by Bjarne Stroustrup of AT&T

Bell Laboratories in the early 1980's, and is based on the C language. The name is a pun - "++" is a syntactic construct used in C and C++ is intended as an incremental improvement of C. Most of C is subset of C++, so that most C programs can be compiled (i.e. converted into a series of low-level instructions that the computer can execute directly) using a C++ compiler.

The name C++ was coined by Rick Mascitti. Ever since it’s birth it has coped up with problems encountered by users, and through discussions at AT&T. however the maturation of the C++ language is attested to by two recent events:

(i) the formation of American National Standard Institute) C++ committee

(ii) the publication of The Annotated C++ Reference Manual by Ellis and Stroustrup.

Page 3: C++

Because C++ retains C as a subset, it gains many of the attractive features of the C language, such as efficiency, closeness to the machine, and a variety of built-in types. A number of new features were added to C++ to make the language even more robust, many of which are not used by novice programmers. By introducing these new features here, we hope that you will begin to use them in your own programs early on and gain their benefits. Some of the features we will look at are the role of constants, inline expansion, references, declaration statements, user defined types, overloading, and the free store.

Page 4: C++

THE SMALLEST INDIVIDUAL UNIT IN A PROGRAM IS KNOWN AS A TOKEN OR A

LEXICAL UNIT

TOKENS

Page 5: C++

TOKENS

KEYWORDS

IDENTIFIERS

LITERALS

PUNCTUATORS

OPERATORS

Page 6: C++

KEYWORDSIn computer programming, a keyword is a

word or identifier that has a particular meaning to the programming language. The meaning of keywords — and, indeed, the meaning of the notion of keyword — differs widely from language to language.

 In many languages, such as C and similar

environments like C++, a keyword is a reserved word which identifies a syntactic form. Words used in control flow constructs, such as if, then, and else are keywords. In these languages, keywords can also be used as the names of variables or functions.

Page 7: C++

C++ KEYWORDSasm continue float new signed try

auto default for operator sizeof typedef

break delete friend private static union

case do goto protected struct unsigned

catch double if public switch virtual

char Else Inline register template void

class enum int return this volatile

const extern long short throw while

Page 8: C++

IDENTIFIERSIn computer science, Identifiers (IDs) are lexical tokens

that name entities. The concept is analogous to that of a "name." Identifiers are used extensively in virtually all information processing systems. Naming entities makes it possible to refer to them, which is essential for any kind of symbolic processing.

Computer languages usually place restrictions on what characters may appear in an identifier. For example, in early versions the C and C++ language, identifiers are restricted to being a sequence of one or more ASCII letters, digits (these may not appear as the first character), and underscores. Later versions of these languages, along with many other modern languages support almost all Unicode characters in an identifier (a common restriction is not to permit white space characters and language operators).

Page 9: C++

RULES FOR DETERMING AN IDENTIFIER

First character must be a letterAfter that any combination of letters and

digits can be taken.Only underscore can be included and must be

treated as a letter.Keywords cannot be used as identifiers.

Page 10: C++

SOME VALID AND INVALID IDENTIFIERS

VALID:- My file DATE9_7_77 Z2T0Z9 MYFILE _DS _HJI3_JK _CHK FILE13 INVALID:- DATA-REC contains special

character 29CLCT starting with a

digit break reserved keyword My.file contains special

character

Page 11: C++

LITERALSIn computer science, a literal is a notation for representing a fixed value in source code. Almost all programming languages have notations for atomic values such as integers, floating-point numbers, strings, and Booleans; some also have notations for elements of enumerated types and compound values such as arrays, records, and objects.

Literals are divided into four types:(i) integer-constant(ii) character- constant(iii)Floating constant(iv)String-literal

Page 12: C++

INTEGER CONSTANTS They are whole numbers without any fractional

parts. the method of writing integer constants has been specified in following rule:-

an integer constant must have at least one digit and must not contain any decimal point. It may contain either + or – sign. A number with no sign is assumed to be positive. Commas cannot appear in an integer constant. This again has three types: (i)decimal(base 10)

(ii)octal(base 8)(iii)hexadecimal(base 16)

Page 13: C++

CHARACTER CONSTANT

A character constant is one character enclosed in single quotes, as in ‘z’. The rule for writing character constant is given below:-

a character constant is C++must contain one character and must be enclosed in single quotation marks.

C++ allows us to have certain non-graphic characters. These cannot be typed directly from keyboard. E.g., backspace, tabs, carriage, return etc.

Page 14: C++

ESCAPE SEQUENCEESCAPE SEQUENCE NONGRAPHIC CHARACTER

\a Audible bell(alert)

\b backspace

\f formfeed

\n Newline or linefeed

\r Carriage return

\t Horizontal tab

\v Vertical tab

\\ backslash

\’ Single quote

\” Double quote

\? Question mark

\On Octal number(On represents the number in octal)

\xHn Hexadecimal number

\0 null

Page 15: C++

FLOATING CONSTANTS

Floating constants are also called real constants.

Real constants are functions having fractional parts. These may be written in one of the two forms called fractional form or the exponent form. It consists of signed or unsigned digits including a decimal point between digits. The rule for writing a real constant is:-

A real constant in fractional form must have at least one digit after the decimal point. It may also have either + or – sign preceding it. A real constant with no sign is assumed to be positive.

Page 16: C++

STRING LITERALS:-

Multiple character constants are treated as string- literals. The rule for writing string-literal is given below:-

A string literal is a sequence of characters surrounded by double quotes.

Specifically, most string literals can be specified using:

 declarative notation; whitespace delimiters (indentation); bracketed delimiters (quoting); escape characters; or a combination of some or all of the above

Page 17: C++

PUNCTUATORS

A punctuator is a token that has syntactic and semantic meaning to the compiler, but the exact significance depends on the context. A punctuator can also be a token that is used in the syntax of the preprocessor.

Page 18: C++

BRACKETS[ ] Opening and closing brackets indicate single and multidimensional array subscripts.

Parentheses( ) Opening and closing parentheses indicate function calls and function parameters. Parentheses also group expressions and isolate conditional expressions.

Braces{ } Opening and closing of braces indicate the start and end of a compound statement .

Comma , It is used as a separator in a function argument list

Semicolon ; It is used as a statement terminator. Every executable statement is terminated by a semicolon (;).

Colon : It indicates a labeled statement.

Asterisk * The asterisk is a variable declaration denotes the creation of a pointer to a data type. the asterisk is also used as an operator to either pointer or as the multiplication operator

Ellipsis … They are used in formal argument lists of function prototypes to indicate a variable number of argument.

Equal to sign = It is used for variable initialization and as an assignment operator in expressions.

Pound sign# The pound sign is used for preprocessor directive and double pound sign is uses to perform token replacement and merging.

Page 19: C++

OPERATORS Operators are tokens that trigger

some computation when applied to variables and other objects in an expression. The following list gives a brief description of the operators and their functions.

Unary operators require one operand to operate upon.

Binary operators require two operands to operate upon.

Page 20: C++

SYMBOL UNARY OPERATOR

& Address operator

* Indirection operator

+ Unary plus

- Unary minus

~ Bitwise complement

++ Increment operator

-- decrement operator

! Logical negation

SYMBOL BINARY OPERATOR

+,-,*,/,% ARITHMETIC OPERATORS

<< Shift left

>> Shift right

& Bitwise AND

^ Bitwise exclusive OR

&& Logical AND

II Logical OR

Page 21: C++

ORDER OF PRECEDENCE

( ) [ ] ! ~ + - ++ -- & *(typeset) * / % + - << >> < <= != & ^ I && II ?: = *= / %= += -= &= ^= I= < <= > >=

Page 22: C++

THANK YOU