#13.
A keyword that lets the compiler automatically deduce the data type of a variable at compile-time.
#14.
Returns the memory address of a variable.
#15.
Accesses the value stored at a memory address held by a pointer.
---
#CPP #ControlFlow #Conditional
#16.
Executes a block of code if a specified condition is true.
#17.
Executes a block of code if the condition in the
#18.
Specifies a new condition to test, if the first
#19.
Selects one of many code blocks to be executed.
#20.
Used to exit a
---
#CPP #Loops
#21.
Executes a block of code a specified number of times.
#22.
Loops through a block of code as long as a specified condition is true.
autoA keyword that lets the compiler automatically deduce the data type of a variable at compile-time.
#include <iostream>
int main() {
auto number = 10; // Compiler deduces int
auto pi = 3.14; // Compiler deduces double
std::cout << "Type of 'number' is deduced.";
return 0;
}
Type of 'number' is deduced.
#14.
& (Address-of Operator)Returns the memory address of a variable.
#include <iostream>
int main() {
int var = 20;
std::cout << "Memory address of var: " << &var;
return 0;
}
Memory address of var: 0x61ff08
(Note: Address will vary)
#15.
* (Dereference Operator)Accesses the value stored at a memory address held by a pointer.
#include <iostream>
int main() {
int var = 50;
int* ptr = &var; // ptr holds the address of var
std::cout << "Value at address " << ptr << " is " << *ptr;
return 0;
}
Value at address 0x61ff04 is 50
(Note: Address will vary)
---
#CPP #ControlFlow #Conditional
#16.
ifExecutes a block of code if a specified condition is true.
#include <iostream>
int main() {
int age = 18;
if (age >= 18) {
std::cout << "You are an adult.";
}
return 0;
}
You are an adult.
#17.
elseExecutes a block of code if the condition in the
if statement is false.#include <iostream>
int main() {
int age = 16;
if (age >= 18) {
std::cout << "You are an adult.";
} else {
std::cout << "You are not an adult.";
}
return 0;
}
You are not an adult.
#18.
else ifSpecifies a new condition to test, if the first
if condition is false.#include <iostream>
int main() {
int score = 85;
if (score >= 90) {
std::cout << "Grade: A";
} else if (score >= 80) {
std::cout << "Grade: B";
} else {
std::cout << "Grade: C";
}
return 0;
}
Grade: B
#19.
switch / caseSelects one of many code blocks to be executed.
#include <iostream>
int main() {
int day = 3;
switch (day) {
case 1:
std::cout << "Monday";
break;
case 2:
std::cout << "Tuesday";
break;
case 3:
std::cout << "Wednesday";
break;
}
return 0;
}
Wednesday
#20.
breakUsed to exit a
switch statement or a loop.#include <iostream>
int main() {
for (int i = 0; i < 10; ++i) {
if (i == 5) {
break; // Exit the loop when i is 5
}
std::cout << i << " ";
}
return 0;
}
0 1 2 3 4
---
#CPP #Loops
#21.
forExecutes a block of code a specified number of times.
#include <iostream>
int main() {
for (int i = 0; i < 5; ++i) {
std::cout << i << " ";
}
return 0;
}
0 1 2 3 4
#22.
whileLoops through a block of code as long as a specified condition is true.
#include <iostream>
int main() {
int i = 0;
while (i < 5) {
std::cout << i << " ";
i++;
}
return 0;
}
0 1 2 3 4