Python Data Science Jobs & Interviews
20.4K subscribers
188 photos
4 videos
25 files
326 links
Your go-to hub for Python and Data Science—featuring questions, answers, quizzes, and interview tips to sharpen your skills and boost your career in the data-driven world.

Admin: @Hussein_Sheikho
Download Telegram
#23. do-while
Similar to a while loop, but the code block is executed at least once before the condition is tested.

#include <iostream>

int main() {
int i = 5;
do {
std::cout << "This will run once.";
i++;
} while (i < 5);
return 0;
}

This will run once.


#24. Range-based for loop
Iterates over all elements in a range, such as an array or vector, without using an index.

#include <iostream>
#include <vector>

int main() {
int numbers[] = {10, 20, 30};
for (int num : numbers) {
std::cout << num << " ";
}
return 0;
}

10 20 30


#25. continue
Skips the current iteration of a loop and continues with the next iteration.

#include <iostream>

int main() {
for (int i = 0; i < 5; ++i) {
if (i == 2) {
continue; // Skip printing 2
}
std::cout << i << " ";
}
return 0;
}

0 1 3 4

---
#CPP #Functions

#26. Function Declaration (Prototype)
Declares a function's name, return type, and parameters, allowing it to be used before it's defined.

#include <iostream>

void sayHello(); // Function declaration

int main() {
sayHello(); // Call the function
return 0;
}

void sayHello() { // Function definition
std::cout << "Hello from function!";
}

Hello from function!


#27. void
A keyword specifying that a function does not return any value.

#include <iostream>

void printMessage(std::string message) {
std::cout << message;
}

int main() {
printMessage("This function returns nothing.");
return 0;
}

This function returns nothing.


#28. return
Terminates a function and can return a value to the caller.

#include <iostream>

int add(int a, int b) {
return a + b; // Return the sum
}

int main() {
int result = add(5, 3);
std::cout << "Result: " << result;
return 0;
}

Result: 8


#29. #include <cmath>
Includes the C++ math library for complex mathematical operations.

#include <iostream>
#include <cmath> // Include for sqrt()

int main() {
double number = 25.0;
std::cout << "Square root is: " << sqrt(number);
return 0;
}

Square root is: 5


#30. pow()
A function from <cmath> that returns the base raised to the power of the exponent.

#include <iostream>
#include <cmath>

int main() {
double result = pow(2, 3); // 2 to the power of 3
std::cout << "2^3 is: " << result;
return 0;
}

2^3 is: 8

---
#CPP #STL #Vector

#31. #include <vector>
Includes the library for std::vector, a dynamic array.

#include <iostream>
#include <vector>

int main() {
std::vector<int> myVector;
myVector.push_back(1);
std::cout << "Vector is ready.";
return 0;
}

Vector is ready.


#32. std::vector
A sequence container that encapsulates dynamic size arrays.

#include <iostream>
#include <vector>

int main() {
std::vector<int> numbers = {10, 20, 30};
std::cout << "First element: " << numbers[0];
return 0;
}

First element: 10


#33. .push_back()
Member function of std::vector that adds an element to the end.