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

PPTX
Computer programming 2 Lesson 10
PPTX
Introduction to c programming
PPTX
PPTX
Strings
PDF
PPT
Introduction to Laws
PPT
Operation on string presentation
PDF
Write the definition of a function named countDigits that takes one argument,...
Computer programming 2 Lesson 10
Introduction to c programming
Strings
Introduction to Laws
Operation on string presentation
Write the definition of a function named countDigits that takes one argument,...

What's hot (20)

PDF
Strings IN C
DOC
String in c
PPTX
Strings in C
PPTX
C programming - String
PPTX
C# Strings
PPTX
Strings in c++
PPT
Strings
PDF
Strings1
PPTX
Managing I/O & String function in C
PPTX
String C Programming
PPTX
String in c programming
PPT
Strings in c
PDF
Arrays and strings in c++
PPT
Strings
PDF
String.ppt
PDF
Character Array and String
PPTX
String in programming language in c or c++
PPT
Strings In OOP(Object oriented programming)
Strings IN C
String in c
Strings in C
C programming - String
C# Strings
Strings in c++
Strings
Strings1
Managing I/O & String function in C
String C Programming
String in c programming
Strings in c
Arrays and strings in c++
Strings
String.ppt
Character Array and String
String in programming language in c or c++
Strings In OOP(Object oriented programming)
Ad

Similar to CS106 Lab 2 - Variables declaration (20)

PPT
JAVA PROGRAMMING : Data types
PDF
Chapter 4 (Part II) - Array and Strings.pdf
PDF
Acm aleppo cpc training second session
PDF
Chapter 3 - Characters and Strings - Student.pdf
PDF
Strings in c mrs.sowmya jyothi
PDF
9 character string &amp; string library
PPTX
C Programming Unit-3
PPT
Strings
PDF
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
PPTX
introduction to strings in c programming
PPTX
Java Object Orientend Programming 1.pptx
PDF
Unit 2
PPTX
Opject Oriented Brogramming - WHat is that?
PPTX
ARRAY's in C Programming Language PPTX.
PPT
Strings
PPT
Strings
PPT
Strings
PPTX
STRINGS_IN_PYTHON 9-12 (1).pptx
JAVA PROGRAMMING : Data types
Chapter 4 (Part II) - Array and Strings.pdf
Acm aleppo cpc training second session
Chapter 3 - Characters and Strings - Student.pdf
Strings in c mrs.sowmya jyothi
9 character string &amp; string library
C Programming Unit-3
Strings
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
introduction to strings in c programming
Java Object Orientend Programming 1.pptx
Unit 2
Opject Oriented Brogramming - WHat is that?
ARRAY's in C Programming Language PPTX.
Strings
Strings
Strings
STRINGS_IN_PYTHON 9-12 (1).pptx
Ad

More from Nada Kamel (10)

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

Recently uploaded (20)

PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
master seminar digital applications in india
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Cell Types and Its function , kingdom of life
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Classroom Observation Tools for Teachers
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
Institutional Correction lecture only . . .
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Cell Structure & Organelles in detailed.
PPTX
Presentation on HIE in infants and its manifestations
PDF
RMMM.pdf make it easy to upload and study
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Pharmacology of Heart Failure /Pharmacotherapy of CHF
master seminar digital applications in india
Microbial disease of the cardiovascular and lymphatic systems
Cell Types and Its function , kingdom of life
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
O5-L3 Freight Transport Ops (International) V1.pdf
Classroom Observation Tools for Teachers
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Institutional Correction lecture only . . .
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Cell Structure & Organelles in detailed.
Presentation on HIE in infants and its manifestations
RMMM.pdf make it easy to upload and study
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
102 student loan defaulters named and shamed – Is someone you know on the list?

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