0% found this document useful (0 votes)
40 views11 pages

3 Lec 3

The document discusses different input and assignment operators in C++ including: 1) The cin operator is used to take input from the keyboard during program execution. It is part of the iostream header file. 2) The extraction operator ">>" is used to extract input from cin and assign it to a variable. 3) Compound assignment operators like +=, -=, *=, /= can be used to assign the result of an expression to a variable.

Uploaded by

MishaalKhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views11 pages

3 Lec 3

The document discusses different input and assignment operators in C++ including: 1) The cin operator is used to take input from the keyboard during program execution. It is part of the iostream header file. 2) The extraction operator ">>" is used to extract input from cin and assign it to a variable. 3) Compound assignment operators like +=, -=, *=, /= can be used to assign the result of an expression to a variable.

Uploaded by

MishaalKhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 11

LEC 3 Input in c++

• input statement to get input from keyboard during execution of the program
is cin, pronounced as see in.
• Its part of the iostream header file.
• General syntax:
cin>>var1;
OR cin>>var1>>var2>>var3;
• >> is called extraction operator or get from operator.
• During execution of program, when a cin command encounters, the
computer waits to receive an input from keyboard. When a value is
typed and the ENTER key is pressed , a value is assigned to a
variable and control shifts to the next statement
assigment
• Write a program that takes marks of three
subjects as an input from user and
displays the total and average of these
subjects.
Compound assignment statement

• x=y=z=10;
• Compound assignment expression:
var operator= expression;
where expression is any expression whose value is assigned to variable. It can
be a single variable or constant
Operator is +, _, *, /
• Examples:
xy=xy+10; can be written as xy+=10;
x -= 2;
y *= 4;
n /=7;
Increment operator
• The operator that is used to add 1 to the
value of a variable.
• xy++;
• Prefix increment ++xy;
• Postfix increment xy++;
Decrement operator
• Subtracts 1 from the value of a variable.
• Postfix increment xy--;
• Prefix increment --xy;
assignment
• Write a program that takes a no as input
from user and displays the square and
cube of that number.
• Write a program that takes a no1 and a
no2 as input from user and display
quotient and remainder of the two.

You might also like