
cin / cout)break, continue, return (and goto note)C++ is a general-purpose programming language that supports:
Why C++ is widely used:
A simple C++ program generally contains:
#include <iostream>) for I/O.{ }.Example (understand meaning, not just memorise):
#include <iostream>: brings cin and cout.using namespace std;: allows using cout instead of std::cout.return 0;: indicates successful completion.Tokens are the smallest meaningful units in a program.
Main token types:
int, if, return).10, 3.14, 'A', "Hello").+, ==, &&).;, {}, (), ,).Rules:
_.totalMarks, price).Keywords have fixed meaning in C++. Examples: int, float, if, else, for, while, return.
Common literals:
10, -253.14'A'"BTech"true, falseA data type tells the compiler what kind of data a variable will store and how much memory it needs.
Common basic types:
int (integer)float, double (decimal)char (single character)bool (true/false)void (no value)Type modifiers (change range/size):
short, longsigned, unsignedImportant exam line: “The range of a type depends on the system/compiler, but conceptually modifiers increase/decrease storage capacity.”
A variable is a named memory location whose value can change.
Example: int age = 18;
A constant is a fixed value. In C++ we commonly use:
const int max = 100;Access the complete note and unlock all topic-wise content
It's free and takes just 5 seconds
Get instant access to notes, practice questions, and more benefits with our mobile app.
Download this note as PDF at no cost
If any AD appears on download click please wait for 30sec till it gets completed and then close it, you will be redirected to pdf/ppt notes page.
cin / cout)break, continue, return (and goto note)C++ is a general-purpose programming language that supports:
Why C++ is widely used:
A simple C++ program generally contains:
#include <iostream>) for I/O.{ }.Example (understand meaning, not just memorise):
#include <iostream>: brings cin and cout.using namespace std;: allows using cout instead of std::cout.return 0;: indicates successful completion.Tokens are the smallest meaningful units in a program.
Main token types:
int, if, return).10, 3.14, 'A', "Hello").+, ==, &&).;, {}, (), ,).Rules:
_.totalMarks, price).Keywords have fixed meaning in C++. Examples: int, float, if, else, for, while, return.
Common literals:
10, -253.14'A'"BTech"true, falseA data type tells the compiler what kind of data a variable will store and how much memory it needs.
Common basic types:
int (integer)float, double (decimal)char (single character)bool (true/false)void (no value)Type modifiers (change range/size):
short, longsigned, unsignedImportant exam line: “The range of a type depends on the system/compiler, but conceptually modifiers increase/decrease storage capacity.”
A variable is a named memory location whose value can change.
Example: int age = 18;
A constant is a fixed value. In C++ we commonly use:
const int max = 100;Scope means where a variable is accessible:
We will study scope deeply with functions later, but understand the basic meaning now.
cin / cout)C++ uses stream I/O from <iostream>:
cout for outputcin for inputKey points:
<< is insertion operator used with cout.>> is extraction operator used with cin.Example idea:
cout << "Enter x"; cin >> x;Operators are symbols that perform operations.
Main categories:
+ - * / %== != < > <= >=&& || != += -= *= /= %=++ --?:If an expression has multiple operators, C++ follows operator precedence.
Example: 2 + 3 * 4 gives 14 because * has higher precedence than +.
Good practice: use parentheses to avoid confusion.
An expression is a combination of variables, constants and operators.
C++ may automatically convert smaller type to larger type.
Example: int to double in double x = 5;
We force conversion.
Example: int avg = (total / (double)n); (so division becomes floating)
Decision statements choose one path based on a condition.
ifif-elseelse-if ladderswitchif / if-else ideaCondition must be true/false. Example use cases: pass/fail, max of two numbers.
switch ideaUsed when there are multiple choices based on an integer/char expression. Key points:
break to avoid fall-through.default runs when no case matches.Loops repeat statements until a condition changes.
for loop: when number of iterations is known.while loop: condition checked first (entry-controlled).do-while loop: executes at least once (exit-controlled).Try to remember:
while: “check then run”do-while: “run then check”break, continue, return (and goto note)break: exits loop/switch.continue: skips current iteration and goes to next.return: exits from function (and optionally returns a value).goto exists but is generally avoided in modern structured programming.
= with == in conditions.;.{} in multi-line if/loops (leads to logic bugs).switch without break.Start → Read input → Process (operators/expressions) → Decision/Loop → Output → End
main() + statements.if/switch), loops (for/while/do-while), jumps (break/continue/return).From this topic
Tokens are the basic building blocks of a C++ program. Examples:
int, if, returntotalMarks, age10, 3.14, 'A', "Hello"+, ==, &&;, {}, ()These tokens combine to form statements and expressions.
A data type defines the kind of data and memory size. Any three:
true/false (e.g., isPass).Choosing correct type avoids memory waste and improves correctness.
A basic C++ program is organized so that the compiler and user both can understand the flow.
Main parts:
#include <iostream> to use cin/cout.using namespace std; to avoid writing std:: repeatedly.return 0; indicates successful termination.Include → main() starts → input → processing → output → return
So, the program structure provides a clear execution path from start to end.