SlideShare a Scribd company logo
Lab 2
CS106 - Fundamentals of Computer Science
Presented by TA. Nada Kamel
Agenda
 Data types
 Variables declaration
 Character escapes
 Strings
 Literals
 Constants
Presented by TA. Nada Kamel
Data Types
Presented by TA. Nada Kamel
Data Types
Data Type C++ Keyword Byte(s) Typical range
Integer int 4 -2,147,483,648 to
2,147,483,647
Unsigned integer unsigned int 4 0 to 4,294,967,295
Long integer long 8 ~ -9 Billion to ~ 9 Billion
Floating point float 4 +/- 3.4e +/- 38 (~7 digits)
Double floating point double 8 +/- 1.7e +/- 308 (~15 digits)
Character char 1 128 to 127 or 0 to 255
String/Text string ∞ -
Presented by TA. Nada Kamel
Data Types (Cont.)
 Boolean  bool
 Void  void
Presented by TA. Nada Kamel
Variable Declaration
Presented by TA. Nada Kamel
Variable Declaration
 C++ requires every variable to be declared with its type BEFORE its first
use.
 Examples:
int height;
char letter;
float radius, diameter;
 In these examples, variables have an undetermined value.
Presented by TA. Nada Kamel
Variable Initialization
 Allows variable to have a specific value from the moment it is declared.
 Example:
int depth = 67;
(data type) (identifier) = initial_value;
Presented by TA. Nada Kamel
Character Escapes
Presented by TA. Nada Kamel
Character Escapes
Keyword Meaning
n or endl newline
r carriage return
t tab
v vertical tab
b backspace
a alert (beep sound)
’ single quote
” double quote
? question mark
 backslash
Presented by TA. Nada Kamel
Strings
Presented by TA. Nada Kamel
Strings
 Strings are able to store sequences of characters.
 To utilize strings we must include a directive
#include <string>
 Can be initialized with any of the three valid initialization formats:
string mystring = “Hello World!”;
string mystring(“Hello World!”);
string mystring {“Hello World!”};
Presented by TA. Nada Kamel
Strings (Cont.)
 To input a string you will need to use:
getline(cin, mystring);
 If the user will enter one word only, cin >> mystring can be used.
 Example:
#include <iostream>
#include <string>
void main()
{
string mystring;
getline(cin, mystring);
std:: cout << “The string entered is ” << mystring << endl;
}
Presented by TA. Nada Kamel
Literals
Presented by TA. Nada Kamel
Literals
 Used to express particular values.
 Literal constants can be classified into: integers, floating-point, character,
string, boolean.
 Examples:
707
-20589
3.14
1.6e-19
‘z’
“Hello World!”
true
Presented by TA. Nada Kamel
Typed Constants
Presented by TA. Nada Kamel
Constants
 Can be used to give names to constant values.
 Example:
const float pi = 3.14159;
 The value of the constant variable cannot be changed after being
initialized.
Presented by TA. Nada Kamel
Any Questions?
Presented by TA. Nada Kamel

More Related Content

What's hot

Strings IN C
Strings IN CStrings IN C
Strings IN C
yndaravind
 
String in c
String in cString in c
String in c
Suneel Dogra
 
Strings in C
Strings in CStrings in C
Strings in C
Kamal Acharya
 
C programming - String
C programming - StringC programming - String
C programming - String
Achyut Devkota
 
C# Strings
C# StringsC# Strings
C# Strings
Hock Leng PUAH
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
Neeru Mittal
 
Managing I/O & String function in C
Managing I/O & String function in CManaging I/O & String function in C
Managing I/O & String function in C
Abinaya B
 
String C Programming
String C ProgrammingString C Programming
String C Programming
Prionto Abdullah
 
String in c programming
String in c programmingString in c programming
String in c programming
Devan Thakur
 
Strings in c
Strings in cStrings in c
Strings in c
vampugani
 
Arrays and strings in c++
Arrays and strings in c++Arrays and strings in c++
Arrays and strings in c++
GC University Faisalabad
 
Strings
StringsStrings
Strings
Nilesh Dalvi
 
string in C
string in Cstring in C
String.ppt
String.pptString.ppt
String.ppt
ajeela mushtaq
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
Tasnima Hamid
 
String in programming language in c or c++
 String in programming language  in c or c++  String in programming language  in c or c++
String in programming language in c or c++
Samsil Arefin
 
Strings In OOP(Object oriented programming)
Strings In OOP(Object oriented programming)Strings In OOP(Object oriented programming)
Strings In OOP(Object oriented programming)
Danial Virk
 

What's hot (20)

Strings IN C
Strings IN CStrings IN C
Strings IN C
 
String in c
String in cString in c
String in c
 
Strings in C
Strings in CStrings in C
Strings in C
 
C programming - String
C programming - StringC programming - String
C programming - String
 
C# Strings
C# StringsC# Strings
C# Strings
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Strings
StringsStrings
Strings
 
Strings1
Strings1Strings1
Strings1
 
Managing I/O & String function in C
Managing I/O & String function in CManaging I/O & String function in C
Managing I/O & String function in C
 
String C Programming
String C ProgrammingString C Programming
String C Programming
 
String in c programming
String in c programmingString in c programming
String in c programming
 
Strings in c
Strings in cStrings in c
Strings in c
 
Arrays and strings in c++
Arrays and strings in c++Arrays and strings in c++
Arrays and strings in c++
 
Strings
StringsStrings
Strings
 
string in C
string in Cstring in C
string in C
 
String functions in C
String functions in CString functions in C
String functions in C
 
String.ppt
String.pptString.ppt
String.ppt
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
String in programming language in c or c++
 String in programming language  in c or c++  String in programming language  in c or c++
String in programming language in c or c++
 
Strings In OOP(Object oriented programming)
Strings In OOP(Object oriented programming)Strings In OOP(Object oriented programming)
Strings In OOP(Object oriented programming)
 

Similar to CS106 Lab 2 - Variables declaration

JAVA PROGRAMMING : Data types
JAVA PROGRAMMING : Data typesJAVA PROGRAMMING : Data types
JAVA PROGRAMMING : Data types
Kongu Engineering College, Perundurai, Erode
 
Chapter 4 (Part II) - Array and Strings.pdf
Chapter 4 (Part II) - Array and Strings.pdfChapter 4 (Part II) - Array and Strings.pdf
Chapter 4 (Part II) - Array and Strings.pdf
KirubelWondwoson1
 
Acm aleppo cpc training second session
Acm aleppo cpc training second sessionAcm aleppo cpc training second session
Acm aleppo cpc training second session
Ahmad Bashar Eter
 
U4.ppt
U4.pptU4.ppt
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
Sowmya Jyothi
 
9 character string &amp; string library
9  character string &amp; string library9  character string &amp; string library
9 character string &amp; string library
MomenMostafa
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
Vikram Nandini
 
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
introduction to strings in c programming
introduction to strings in c programmingintroduction to strings in c programming
introduction to strings in c programming
mikeymanjiro2090
 
Java Object Orientend Programming 1.pptx
Java Object Orientend Programming 1.pptxJava Object Orientend Programming 1.pptx
Java Object Orientend Programming 1.pptx
OmarBinkasimSefat
 
Unit 2
Unit 2Unit 2
Unit 2
TPLatchoumi
 
STRINGS_IN_PYTHON 9-12 (1).pptx
STRINGS_IN_PYTHON 9-12 (1).pptxSTRINGS_IN_PYTHON 9-12 (1).pptx
STRINGS_IN_PYTHON 9-12 (1).pptx
Tinku91
 
Data type in c
Data type in cData type in c
Data type in c
thirumalaikumar3
 
Lecture 3: Strings and Dynamic Memory Allocation
Lecture 3: Strings and Dynamic Memory AllocationLecture 3: Strings and Dynamic Memory Allocation
Lecture 3: Strings and Dynamic Memory Allocation
Vivek Bhargav
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
Mohammed Khan
 

Similar to CS106 Lab 2 - Variables declaration (20)

JAVA PROGRAMMING : Data types
JAVA PROGRAMMING : Data typesJAVA PROGRAMMING : Data types
JAVA PROGRAMMING : Data types
 
Chapter 4 (Part II) - Array and Strings.pdf
Chapter 4 (Part II) - Array and Strings.pdfChapter 4 (Part II) - Array and Strings.pdf
Chapter 4 (Part II) - Array and Strings.pdf
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Acm aleppo cpc training second session
Acm aleppo cpc training second sessionAcm aleppo cpc training second session
Acm aleppo cpc training second session
 
U4.ppt
U4.pptU4.ppt
U4.ppt
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
 
9 character string &amp; string library
9  character string &amp; string library9  character string &amp; string library
9 character string &amp; string library
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
 
Strings
StringsStrings
Strings
 
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
 
introduction to strings in c programming
introduction to strings in c programmingintroduction to strings in c programming
introduction to strings in c programming
 
Java Object Orientend Programming 1.pptx
Java Object Orientend Programming 1.pptxJava Object Orientend Programming 1.pptx
Java Object Orientend Programming 1.pptx
 
Unit 2
Unit 2Unit 2
Unit 2
 
Strings
StringsStrings
Strings
 
Strings
StringsStrings
Strings
 
Strings
StringsStrings
Strings
 
STRINGS_IN_PYTHON 9-12 (1).pptx
STRINGS_IN_PYTHON 9-12 (1).pptxSTRINGS_IN_PYTHON 9-12 (1).pptx
STRINGS_IN_PYTHON 9-12 (1).pptx
 
Data type in c
Data type in cData type in c
Data type in c
 
Lecture 3: Strings and Dynamic Memory Allocation
Lecture 3: Strings and Dynamic Memory AllocationLecture 3: Strings and Dynamic Memory Allocation
Lecture 3: Strings and Dynamic Memory Allocation
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 

More from Nada Kamel

CS106 Lab 8 - Nested loops
CS106 Lab 8 - Nested loopsCS106 Lab 8 - Nested loops
CS106 Lab 8 - Nested loops
Nada Kamel
 
CS106 Lab 7 - For loop
CS106 Lab 7 - For loopCS106 Lab 7 - For loop
CS106 Lab 7 - For loop
Nada Kamel
 
CS106 Lab 9 - 1D array
CS106 Lab 9 - 1D arrayCS106 Lab 9 - 1D array
CS106 Lab 9 - 1D array
Nada Kamel
 
CS106 Lab 10 - Functions (passing by value)
CS106 Lab 10 - Functions (passing by value)CS106 Lab 10 - Functions (passing by value)
CS106 Lab 10 - Functions (passing by value)
Nada Kamel
 
CS106 Lab 6 - While and Do..While loop
CS106 Lab 6 - While and Do..While loopCS106 Lab 6 - While and Do..While loop
CS106 Lab 6 - While and Do..While loop
Nada Kamel
 
CS106 Lab 4 - If statement
CS106 Lab 4 - If statementCS106 Lab 4 - If statement
CS106 Lab 4 - If statement
Nada Kamel
 
CS106 Lab 5 - Switch case
CS106 Lab 5 - Switch caseCS106 Lab 5 - Switch case
CS106 Lab 5 - Switch case
Nada Kamel
 
CS106 Lab 11 - Functions (passing by reference)
CS106 Lab 11 - Functions (passing by reference)CS106 Lab 11 - Functions (passing by reference)
CS106 Lab 11 - Functions (passing by reference)
Nada Kamel
 
CS106 Lab 3 - Modulus
CS106 Lab 3 - ModulusCS106 Lab 3 - Modulus
CS106 Lab 3 - Modulus
Nada Kamel
 
CS106 Lab 1 - Introduction
CS106 Lab 1 - IntroductionCS106 Lab 1 - Introduction
CS106 Lab 1 - Introduction
Nada Kamel
 

More from Nada Kamel (10)

CS106 Lab 8 - Nested loops
CS106 Lab 8 - Nested loopsCS106 Lab 8 - Nested loops
CS106 Lab 8 - Nested loops
 
CS106 Lab 7 - For loop
CS106 Lab 7 - For loopCS106 Lab 7 - For loop
CS106 Lab 7 - For loop
 
CS106 Lab 9 - 1D array
CS106 Lab 9 - 1D arrayCS106 Lab 9 - 1D array
CS106 Lab 9 - 1D array
 
CS106 Lab 10 - Functions (passing by value)
CS106 Lab 10 - Functions (passing by value)CS106 Lab 10 - Functions (passing by value)
CS106 Lab 10 - Functions (passing by value)
 
CS106 Lab 6 - While and Do..While loop
CS106 Lab 6 - While and Do..While loopCS106 Lab 6 - While and Do..While loop
CS106 Lab 6 - While and Do..While loop
 
CS106 Lab 4 - If statement
CS106 Lab 4 - If statementCS106 Lab 4 - If statement
CS106 Lab 4 - If statement
 
CS106 Lab 5 - Switch case
CS106 Lab 5 - Switch caseCS106 Lab 5 - Switch case
CS106 Lab 5 - Switch case
 
CS106 Lab 11 - Functions (passing by reference)
CS106 Lab 11 - Functions (passing by reference)CS106 Lab 11 - Functions (passing by reference)
CS106 Lab 11 - Functions (passing by reference)
 
CS106 Lab 3 - Modulus
CS106 Lab 3 - ModulusCS106 Lab 3 - Modulus
CS106 Lab 3 - Modulus
 
CS106 Lab 1 - Introduction
CS106 Lab 1 - IntroductionCS106 Lab 1 - Introduction
CS106 Lab 1 - Introduction
 

Recently uploaded

Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 

Recently uploaded (20)

Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 

CS106 Lab 2 - Variables declaration

  • 1. Lab 2 CS106 - Fundamentals of Computer Science Presented by TA. Nada Kamel
  • 2. Agenda  Data types  Variables declaration  Character escapes  Strings  Literals  Constants Presented by TA. Nada Kamel
  • 3. Data Types Presented by TA. Nada Kamel
  • 4. Data Types Data Type C++ Keyword Byte(s) Typical range Integer int 4 -2,147,483,648 to 2,147,483,647 Unsigned integer unsigned int 4 0 to 4,294,967,295 Long integer long 8 ~ -9 Billion to ~ 9 Billion Floating point float 4 +/- 3.4e +/- 38 (~7 digits) Double floating point double 8 +/- 1.7e +/- 308 (~15 digits) Character char 1 128 to 127 or 0 to 255 String/Text string ∞ - Presented by TA. Nada Kamel
  • 5. Data Types (Cont.)  Boolean  bool  Void  void Presented by TA. Nada Kamel
  • 7. Variable Declaration  C++ requires every variable to be declared with its type BEFORE its first use.  Examples: int height; char letter; float radius, diameter;  In these examples, variables have an undetermined value. Presented by TA. Nada Kamel
  • 8. Variable Initialization  Allows variable to have a specific value from the moment it is declared.  Example: int depth = 67; (data type) (identifier) = initial_value; Presented by TA. Nada Kamel
  • 10. Character Escapes Keyword Meaning n or endl newline r carriage return t tab v vertical tab b backspace a alert (beep sound) ’ single quote ” double quote ? question mark backslash Presented by TA. Nada Kamel
  • 12. Strings  Strings are able to store sequences of characters.  To utilize strings we must include a directive #include <string>  Can be initialized with any of the three valid initialization formats: string mystring = “Hello World!”; string mystring(“Hello World!”); string mystring {“Hello World!”}; Presented by TA. Nada Kamel
  • 13. Strings (Cont.)  To input a string you will need to use: getline(cin, mystring);  If the user will enter one word only, cin >> mystring can be used.  Example: #include <iostream> #include <string> void main() { string mystring; getline(cin, mystring); std:: cout << “The string entered is ” << mystring << endl; } Presented by TA. Nada Kamel
  • 15. Literals  Used to express particular values.  Literal constants can be classified into: integers, floating-point, character, string, boolean.  Examples: 707 -20589 3.14 1.6e-19 ‘z’ “Hello World!” true Presented by TA. Nada Kamel
  • 17. Constants  Can be used to give names to constant values.  Example: const float pi = 3.14159;  The value of the constant variable cannot be changed after being initialized. Presented by TA. Nada Kamel
  • 18. Any Questions? Presented by TA. Nada Kamel