0% found this document useful (0 votes)
9 views2 pages

C++ Basics: Variables, I/O, and Operators

This document covers the basics of C++ programming, including variables, constants, input/output operations, and various types of operators. It explains how to declare variables and constants, as well as how to use cin and cout for user input and output. Additionally, it provides a breakdown of arithmetic, relational, logical, and assignment operators with examples.

Uploaded by

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

C++ Basics: Variables, I/O, and Operators

This document covers the basics of C++ programming, including variables, constants, input/output operations, and various types of operators. It explains how to declare variables and constants, as well as how to use cin and cout for user input and output. Additionally, it provides a breakdown of arithmetic, relational, logical, and assignment operators with examples.

Uploaded by

ethanmerchant41
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

C++ Basics Notes

🔹 Variables & Constants

Variables

 A variable is a container for storing data.


 Declaration Syntax:
data_type variable_name;
Example: int age;

Common Data Types:

Data Type Description Example


int Integer (whole numbers) int count = 10;
float Floating point numbers float temp = 36.6;
double Double-precision float double pi = 3.14159;
char Single character char grade = 'A';
bool Boolean (true or false) bool isPassed = true;

Constants

 A constant is a fixed value that cannot be changed during the program.


 Declaration Syntax:
const data_type name = value;
Example: const float PI = 3.14;

🔹 Input & Output in C++

Input: cin

 Used to get input from the user.


 Syntax: cin >> variable;
Example:
 int age;
 cin >> age;

Output: cout

 Used to display output.


 Syntax: cout << message;
Example:
 cout << "Hello, World!";

Note: Include the header file

#include <iostream>
using namespace std;

🔹 Operators in C++

1. Arithmetic Operators

Operator Meaning Example


+ Addition a + b
- Subtraction a - b
* Multiplication a * b
/ Division a / b
% Modulus (remainder) a % b

2. Relational Operators

Operator Meaning Example


== Equal to a == b
!= Not equal to a != b
< Less than a < b
> Greater than a > b
<= Less than or equal to a <= b
>= Greater than or equal to a >= b

3. Logical Operators

Operator Meaning Example


&& Logical AND (a > 0 && b > 0)
` `
! Logical NOT !(a > 0)

4. Assignment Operators

Operator Meaning Example


= Assign value a = 5
+= Add and assign a += 2 (a = a + 2)
-= Subtract and assign a -= 3
*= Multiply and assign a *= 4
/= Divide and assign a /= 2
%= Modulus and assign a %= 2

You might also like