float type and its usage in C++
Monday, July 01, 2024 in C++
Categories:
5 minute read
The provided C++ code is a demonstration of how to use and display floating point numbers in different formats using the iostream and iomanip libraries. #include <iostream> #include <iomanip> using namespace std; int main() { float f = …
Comment types in C++
Sunday, June 30, 2024 in C++
Categories:
less than a minute
We are demontrating single line and multi line comments in C++ #include <iostream> using namespace std; // we will demonstrate the use of comments in this program int main() { // This is a single line comment cout << "Hello, …
What are the keywords in C++
Sunday, June 30, 2024 in C++
Categories:
less than a minute
C++ has a set of reserved keywords that have special meanings to the compiler. These keywords cannot be used as identifiers (names for variables, functions, classes, etc.). Here is a list of C++ keywords: alignas alignof and and_eq asm auto bitand …
Common data types in C++
Sunday, June 30, 2024 in C++
Categories:
less than a minute
C++ supports several different data types. Here are some of the most common ones: Integer types (int): These are used to store whole numbers. The size of an int is usually 4 bytes (32 bits), and it can store numbers from -2,147,483,648 to …
Create variables and assign values to them in C++
Sunday, June 30, 2024 in C++
Categories:
2 minute read
In C++, you can create variables and assign values to them in the following way: Declare a variable by specifying its type followed by the variable name. For example, int myVariable; declares a variable named myVariable of type int. Assign a value to …
Correct and incorrect variable naming conventions in C++
Sunday, June 30, 2024 in C++
Categories:
3 minute read
This program example demonstrates the correct and incorrect variable naming conventions in C++ /** * @file main.cpp * @brief This program demonstrates the correct and incorrect variable naming conventions in C++. */ #include <iostream> using …
The use of octal, binary and hexadecimal literals in C++
Sunday, June 30, 2024 in C++
Categories:
3 minute read
This function defines three integer variables, each initialized with a different type of literal (hexadecimal, octal, binary). It then prints the values of these variables to the console. /** * @file main.cpp * @author ibrahim * @date 30-06-2024 * …
C++ int variable with different defining ways
Sunday, June 30, 2024 in C++
Categories:
2 minute read
We are explaining the use of int variables with different defining ways // Creator: ibrahim (30.06.2024 00:00) /** * @file main.cpp * @brief Demonstrates the use of int with different defining ways in C++ */ #include <iostream> /** * @brief …
C++ Hello World with explanaition
Sunday, June 30, 2024 in C++
Categories:
2 minute read
We tried to explain the most simple C++ program for beginners. #include <iostream> int main() { std::cout << "Hello, World!" << std::endl; return 0; } The provided code is a simple C++ program that prints “Hello, …
C++ Defining a Pointer and changing its value
Friday, June 28, 2024 in C++
Categories:
2 minute read
In this example, we define a pointer and show how to view and change its value. /** * @brief Main function that demonstrates pointer manipulation. * * This function initializes an integer variable `value` with the value 10. * It then creates a …
Factorial calculation with C++ do-while loop
Friday, June 28, 2024 in C++
Categories:
less than a minute
In this example, we show how to calculate factorial using the do while loop. #include <iostream> using namespace std; int calculateFactorial(int number) { int result = 1; for (int i = 1; i <= number; i++) { result *= i; } return result; } …
C++ Example calculating the factorial of the entered number
Friday, June 28, 2024 in C++
Categories:
less than a minute
In this example, we show how to calculate the factorial of the entered number with the help of a function. #include <iostream> using namespace std; int factorial(int num) { int result = 1; for (int i = 2; i <= num; i++) { result *= i; } …
C++ adding int and float variables
Friday, June 28, 2024 in C++
Categories:
less than a minute
In this example, we show how to find the sum of 2 variables of type int and float. #include <iostream> int main() { int firstNumber = 11; float secondNumber = 12.8; float sum = firstNumber + secondNumber; std::cout << "Sum: " …
C++ Code example to convert Fahrenheit temperature to Celsius
Friday, June 28, 2024 in C++
Categories:
less than a minute
In this example, the entered Fahrenheit temperature value is converted to Celsius value with the help of a function. #include <iostream> #include <iomanip> #include <limits> float temperatureConversion(const float …
Printing int, float and string values with printf in C++
Friday, June 28, 2024 in C++
Categories:
less than a minute
This code defines a main function where the int and float variables are constants and the text variable is not. Prints the values number, realNumber, and text and then returns 0. #include <iostream> #include <cstdio> #include …
C++ 2 string variable concatenation
Thursday, June 27, 2024 in C++
Categories:
less than a minute
In this article, we show an example of combining 2 string variables. #include <iostream> #include <string> int main() { std::string firstString = "prs"; std::string secondString = "def"; std::string result; result = …
Combining 2 variables of type char in C++
Thursday, June 27, 2024 in C++
Categories:
less than a minute
In this example, you can see how to combine 2 char variables with a length of 50 characters using the strcat method. #include <iostream> #include <cstring> using namespace std; int main() { constexpr size_t bufferSize = 50; char …
Finding whether a number is positive or negative with C++
Thursday, June 27, 2024 in C++
Categories:
less than a minute
In this example, we check whether the number entered from the keyboard is positive, negative or zero by using if-else if. #include <iostream> using namespace std; int main() { int number; cout << "Please enter a number: "; cin …
C++ Nested if statement
Saturday, June 22, 2024 in C++
Categories:
less than a minute
In this article, we share an example showing C++ nested if statement. #include <iostream> using namespace std; int main() { /* nested if else statement */ int a; cout << "Enter a positive integer number: "; cin >> a; if (a …
C++ Cascade if else statement
Saturday, June 22, 2024 in C++
Categories:
less than a minute
You can see the usage of cascade if-else statement example below. #include <iostream> using namespace std; int main() { /* cascade if else statement */ int a; cout << "Enter a positive integer number: "; cin >> a; if (a < …