Lecture1s 2
Lecture1s 2
n to
Programmi
ng
Contents
• C++
• Escape Sequence & Comments
• Variables
• Constants
• User Input
• Data Types
• Operators
• Strings & String Concatenation
• Append
• User Input Strings
• Math’s
What is C++
New Line--To insert a new line, you can use the \n character or endl.
Horizontal tab-- \t
Backslash character (\)--\\
Double quote character-- \”……\”
int x = 2, y = 4, z int x, y, z;
= 4; x = y = z = 10;
cout << x + y + z; cout << x + y + z;
Constants
1. Arithmetic operators
2. Assignment operators
3. Comparison operators
4. Logical operators
Arithmetic operators
Arithmetic operators are used to perform common mathematical operations.
/= x /= 3 x=x/3
%= x %= 3 x=x%3
Comparison Operators
• Comparison operators are used to compare two values.
• The return value of a comparison is either true (1) or false (0).
string fullName;
However, cin considers a space (whitespace, tabs, etc)
cout << “Enter Your Full Name: ";
as a terminating character, which means that it can only
cin >> fullName;
display a single word (even if you type many words):
cout << "Your Name is: " << fullName;
string fullName;
cout << “Enter Your Full Name: "; when working with strings, we often use the getline()
getline (cin, fullName); function to read a line of text. It takes cin as the first
cout << "Your Name is: " << fullName; parameter, and the string variable as second
Math's
Precedence of Operators
b/a+c
Precedence
!, ++, --, (type)
*, /, %
+, -
=