Programming Articles - Page 2658 of 3366

Print Single and Multiple variable in Python?

AmitDiwan
Updated on 26-Oct-2023 03:30:56

27K+ Views

To easily display single and multiple variables in Python, use the print() statement. For multiple variables, use the comma operators. Variables are reserved memory locations to store values. It means that when you create a variable, you reserve some space in the memory. Based on the data type of a variable, the interpreter allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to the variables, you can store integers, decimals or characters in these variables. Print Single Variable in Python To display a single variable, simply use the print() method − ... Read More

When are Constructors Called in C++?

Samual Sam
Updated on 30-Jul-2019 22:30:26

668 Views

Here we will see, when constructors are called. Here constructors are of different types. Global, local, static local, dynamic.For the global object, the constructors are called before entering into the main function.Example#include using namespace std; class MyClass {    public:       MyClass() {          cout

Swap two variables in one line in using Python?

AmitDiwan
Updated on 11-Aug-2022 11:50:04

3K+ Views

We will learn how to swap two variables in one line. Let’s say the following is our input − a = 10 b = 5 The following is our output after swap − a = 5 b = 10 Swap two variables in one line using comma operator Using the comma operator, you can create multiple variables in a single line. The same concept is considered here and the variable values are swapped − Example a = 5; b = 10; print("Variable1 = ", a); print("Variable2 = ", b); # Swap two variables in one line ... Read More

Rule Of Three in C++

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

348 Views

The Rule of three is a rule of thumb when using C++. This is kind of a good practice rule that says that If your class needs any ofa copy constructor, an assignment operator, or a destructor, defined explicitly, then it is likely to need all three of them.Why is this? It’s because, if your class requires any of the above, it is managing dynamically allocated resources and would likely be needing the other to successfully achieve that. For example, if you require an assignment operator, you would be creating copies of objects currently being copied by reference, hence allocating ... Read More

What happen when we exceed valid range of built-in data types in C++?

Samual Sam
Updated on 30-Jul-2019 22:30:26

429 Views

Here we will see what will be the results, if we exceed the range of built-in datatypes in C++. So let us see some examples.First one is the character type data. Here we are using a loop from 0 to 300, so it should print from 0 to 300, then stop. But it will generate one infinite loop. The character type data holds from -128 to 127. So after increasing from 127, it will be -128 again. So it will never reach at the point 300.Example#include using namespace std; int main() {    for (char x = 0; x ... Read More

When to use yield instead of return in Python?

Chandu yadav
Updated on 30-Jul-2019 22:30:26

1K+ Views

In short, whenever control reach the return statement in your program, the execution of the program is terminated and the remaining statements will not executed.However, in case of yield, whenever control reach the yield statement in your program, the execution of your program is paused and later we can continue other statements in function.Let’s understand both the statements in detail.YieldUsing yield statement in a function makes the function a generator function which can be used in a loop. When the function is running and the yield statement exeucutes, the value after the yield is passed back to the loop that ... Read More

Difference between set, multiset, unordered_set, unordered_multiset in C++

Anvi Jain
Updated on 30-Jul-2019 22:30:26

358 Views

Here we will see what are the differences for set, multiset, unordered_set and unordered_multiset in C++. Let us see the properties of them using some example.SetThe properties of set are like belowStores data in sorted orderStores only unique valuesWe can insert or delete data, but cannot change the dataWe can remove more than one element using start and end iteratorWe can traverse using iteratorsSets are implemented using Binary Search TreeNow let us see an exampleExample#include #include using namespace std; main() {    int data[15] = {11, 55, 22, 66, 33, 22, 11, 44, 77, 88, 66, 99, 66, 23, 41};    set my_set;    for(int i = 0; i

Factorial of Large Number Using boost multiprecision Library

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

172 Views

To find the factorial of a large number, we can use the boost library. This library provides high precision numbers. Using boost multiprecision library we can get more precision than 64 bits.Example#include #include using boost::multiprecision::cpp_int; using namespace std; cpp_int Large_Fact(int number) {    cpp_int fact = 1;    for (int i = 1; i > fact >> endl; }Output9332621544394415268169923885626670049071596826438162146859296389521759999322 9915608941463976156518286253697920827223758251185210916864000000000000000000 000000

override Keyword in C++

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

4K+ Views

The function overriding is the most common feature of C++. Basically function overriding means redefine a function which is present in the base class, also be defined in the derived class. So the function signatures are the same but the behavior will be different.But there may be a situation when a programmer makes a mistake while overriding that function. Like if the signature is not the same, then that will be treated as another function, but not the overridden method or that. In that case, we can use the override keyword. This keyword is introduced in C+ +11. When the ... Read More

Anything written in sizeof() is never executed in C

Smita Kapse
Updated on 30-Jul-2019 22:30:26

176 Views

The sizeof function (Sometimes called operator) is used to calculate the size of the given argument. If some other functions are given as argument, then that will not be executed in the sizeof.In the following example we will put one printf() statement inside the loop. Then we will see the output.Example#include double my_function() {    printf("This is a test function");    return 123456789; } main() {    int x;    x = sizeof(printf("Hello World"));    printf("The size: %d", x);    x = sizeof(my_function());    printf("The size: %d", x); }OutputThe size: 4 The size: 8The printf() is not executed which is ... Read More

Advertisements