c++ session 2
DESCRIPTION
TRANSCRIPT
![Page 1: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/1.jpg)
Session 2
![Page 2: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/2.jpg)
Session Objectives
• Identify the C++ character set
• Discuss the identifiers and keywords
• Explain various data types and qualifiers
• Identify the C++ variables
![Page 3: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/3.jpg)
Introduction
Identifier
![Page 4: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/4.jpg)
C++ Character set
![Page 5: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/5.jpg)
Special characters[ ] ( ) . -> ++ -- &
* + - ~ ! \ /
% << >> < > <= >=
== != ^ && | || ?:
= *= /= %= += -= <<=
>>= &= ^= |= , # ##
![Page 6: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/6.jpg)
Escape sequences (1)
Back space
New line
Tab
![Page 7: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/7.jpg)
Escape sequences (2)
Carriage returnForm feed
Single quote
![Page 8: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/8.jpg)
Escape sequences (3) Back slash
BellOctal number given by oooHexadecimal
number given by hh
![Page 9: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/9.jpg)
Escape sequences (4)#include <iostream.h>
#include <conio.h> void main(void){clrscr();//This function is used to clear the screencout << "Using the newline escape sequence.\n" ;cout<<"To use backspace escape sequence,press enter" ;getch() ;//This function is used to pause for user entrycout << "\b\b\b\b\b\b\b\b\b\b\bUsed backspace" ;cout << "\nUsing the tab sequence\t\t\t\t tab here" ;getch() ;}
To use backspace escape sequence, press enterTo use backspace escape sequence, Used backspaceUsing the tab sequence tab here
![Page 10: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/10.jpg)
Identifiers (1)
Variables
functions
labels
User defined objects
![Page 11: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/11.jpg)
Identifiers (2)
First character = alphabet
Subsequent =characters
or underscore
alphabetsnumbersor underscore
s
![Page 12: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/12.jpg)
Identifiers (3)
Follow Standardnaming convention
Name should definethe purpose of existence
Use prefixes and suffixesReferring is
easierAvoid using
u,i,j…Leads to confusion
![Page 13: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/13.jpg)
Identifiers (4)
Of an identifier is the part of the program where the identifier is recognized
![Page 14: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/14.jpg)
Keywords
New in C++
![Page 15: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/15.jpg)
Data Types and Variables
![Page 16: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/16.jpg)
Pre-defined Data TypesType Description Length
char Single letter character entries only 8 bits
int (short) Integer values only 16 bits
long Accepts higher range of integer values than the int data type
32 bits
float Supports decimal point notation 32 bits
double Supports decimal point notation with greater precision than Float data type
64 bits
double float
Similar to a float, with greater precision to the right of the decimal point
128 bits
void Does not return any value. N/A
![Page 17: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/17.jpg)
Declaring variables
data_type variable name = initial value
optional
int num ;
int num1 = 3;char alpha = ‘G’ ;float float_no ;float floa = 33.33;double d_no ;double doub = 1234.121212121 ;
![Page 18: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/18.jpg)
Character strings
char str_string[6] ;
char str_string[30]= “ Nice Day “ ;
![Page 19: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/19.jpg)
Variable qualifiers
![Page 20: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/20.jpg)
Type modifiers
longsignedunsignedshort….
long int var1 ;
Unsigned short int var2 ;
![Page 21: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/21.jpg)
Access modifiers
const float pi = 3.146 ;const char three = ‘3’;const int number = 5 ;const double d_number = 8738478.9898 ;
![Page 22: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/22.jpg)
Constants (1)
![Page 23: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/23.jpg)
Constants (2)
const int a = 41 ; // decimal const int b = 0345 ;// octal begin with 0const int c = 0x9f ;// hexadecimal begin // with 0x
![Page 24: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/24.jpg)
Constants (3)
//Defining a standard decimal valueconst float f_number = 12.5766 ;
Either the whole part of the number or the decimal part can be omitted …
but not both
![Page 25: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/25.jpg)
Constants (4)
Const double d_const_val =9.43E-99 ;
Mantissa in decimal notationFollowed by letter ‘ e ’ or ‘ E ‘
![Page 26: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/26.jpg)
Constants (5)
const char c_alpha = ‘A’ ;
![Page 27: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/27.jpg)
Constants (6)
![Page 28: C++ Session 2](https://reader033.vdocument.in/reader033/viewer/2022061121/546ed5bbaf795967298b58f5/html5/thumbnails/28.jpg)
Constants (7)
#include <iostream.h> void main(void){// Defining a string constant const char str_message[ ] = “All done“;cout << str_message ;}
“All done“