0% found this document useful (0 votes)
8 views3 pages

C++ Variables Cheatsheet

This document provides an overview of basic C++ programming concepts, including variables, user input, and arithmetic operators. It explains different data types such as int, double, char, string, and bool, along with examples of how to declare and initialize them. The document also covers how to use std::cin for user input and std::cout for outputting values.

Uploaded by

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

C++ Variables Cheatsheet

This document provides an overview of basic C++ programming concepts, including variables, user input, and arithmetic operators. It explains different data types such as int, double, char, string, and bool, along with examples of how to declare and initialize them. The document also covers how to use std::cin for user input and std::cout for outputting values.

Uploaded by

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

Firefox about:srcdoc

Cheatsheets / Learn C++

Variables

User Input

std::cin , which stands for “character input”, reads user int tip = 0;
input from the keyboard.
Here, the user can enter a number, press enter , and
std::cout << "Enter amount: ";
that number will get stored in tip .
std::cin >> tip;

Variables

A variable refers to a storage location in the computer’s // Declare a variable


memory that one can set aside to save, retrieve, and
int score;
manipulate data.

// Initialize a variable
score = 0;

Arithmetic Operators

C++ supports di�erent types of arithmetic operators that int x = 0;


can perform common mathematical operations:
• + addition
• - subtraction x = 4 + 2; // x is now 6
• * multiplication x = 4 - 2; // x is now 2
• / division x = 4 * 2; // x is now 8
• % modulo (yields the remainder)
x = 4 / 2; // x is now 2
x = 4 % 2; // x is now 0

1 of 3 7/10/2025, 8:17 PM
Firefox about:srcdoc

double Type

double is a type for storing �oating point (decimal) double price = 8.99;
numbers. Double variables typically require 8 bytes of
double pi = 3.14159;
memory space.

Chaining the Output

std::cout can output multiple values by chaining them int age = 28;
using the output operator << .
Here, the output would be I'm 28.
std::cout << "I'm " << age << ".\n";

int Type

int is a type for storing integer (whole) numbers. An int year = 1991;
integer typically requires 4 bytes of memory space and
int age = 28;
ranges from -2³¹ to 2³¹-1.

char Type

char is a type for storing individual characters. char grade = 'A';


Characters are wrapped in single quotes ' . Characters
char punctuation = '?';
typically require 1 byte of memory space and range from
-128 to 127.

string Type

std::string is a type for storing text strings. Strings are std::string message = "good nite";
wrapped in double quotes " .
std::string user = "codey";

2 of 3 7/10/2025, 8:17 PM
Firefox about:srcdoc

bool Type

bool is a type for storing true or false boolean bool organ_donor = true;
values. Booleans typically require 1 byte of memory
bool late_to_work = false;
space.

Print Share

3 of 3 7/10/2025, 8:17 PM

You might also like