Tapas Kumar Ghosh

Tapas Kumar Ghosh

185 Articles Published

Articles by Tapas Kumar Ghosh

Page 7 of 19

How to convert a single character to string in C++?

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 05-May-2025 474 Views

In C++, a single character is represented using a single quotation (' ') while a string is represented using a double quotation (" "). To change the single character into a string, use approaches like string_constructor, push_back(), etc., that solve the conversion. Example Input: ch = 'A' Output: str = A // "A" So, character A is converted to a string. C++ provides various approaches to convert single character into string as follows: Using string constructor Using push_back() Using stringstream ...

Read More

Difference Between int and long

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 05-May-2025 8K+ Views

In programming, int and long are the part of primitive data type. The int stores the integer value while long stores the larger range of values like a whole number. In this article, we will see the differences between int and long data types. int (Integer) Data Type The keyword int representing the integer value. It store the both positive and negative values such as -1, 45, -78, 85, etc., but not fractional and decimal values. The value ranges from –2, 147, 483, 648 to 2, 147, 483, 647. Behavior of int in Different Languages Following is the list of ...

Read More

How to calculate Execution Time of a Code Snippet in C++?

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 02-May-2025 3K+ Views

To calculate the execution time of a program, use the std::chrono library, which was introduced in C++11. This library has two distinct objects: time_point and duration. The time_point represents the variable names that store the start and end times of specific algorithms, functions, or loops used in the program. While duration represents the interval between two different times. The chrono library allows us to subtract these time intervals. Here, we use the high_resolution_clock::now() function, which provides accurate units of time. Calculate the Execution Time of a C++ Program To get the execution time of a program use the chrono header ...

Read More

Why are global variables bad in C/C++?

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 02-May-2025 3K+ Views

Global variables are declared and defined outside any function in the program. They hold their values throughout the lifetime of the program and are accessible throughout its execution. When we use our non-constant global variable in our programs, it becomes harder to manage. So, it is better to use local variables because of specific functions and easier understanding. You can use the prefix g_ for global variable names to avoid naming conflicts and to indicate that the variable is global. There is another way to encapsulate the global variable by defining the variable static. Therefore, these are the reasons behind ...

Read More

C++ Program to Add Complex Numbers by Passing Structure to a Function

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 02-May-2025 1K+ Views

Complex numbers are numbers that are expressed as a+bi, where i is an imaginary number and a and b, are real numbers. Some of the example of complex numbers are 2 + 5i, 3 - 9i, 8 + 2i, etc. How to add complex number? Here, we will explain how to add two complex numbers. Let us assume we have two complex numbers, Z1 and Z2. // a and b are the real and imaginary parts of Z1 Z1 = a + bi // c and d are the real and imaginary parts of Z2 Z2 = c + ...

Read More

C++ Program to Perform Addition Operation Using Bitwise Operators

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 30-Apr-2025 2K+ Views

Bitwise operators are used for representing binary integers, where the operator directly performs operations on the individual bits of integer values. To perform an addition operation using bitwise operators, use operators like AND, XOR, and NOT. The OR operator cannot perform addition on its own because, 1 | 1 results in 1, but we need 2 as the output. Therefore, you can use the other three operators to implement the logic of addition. You can see the tabular representation of biwise operators by taking binary bits as 0 and 1. ...

Read More

Variable initialization in C++

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 22-Apr-2025 9K+ Views

In C++, variables are name given by the user to store data. While datatype is used to declare and initialize a variable that allocates memory to that variable. There are various ways to initialize the data types such as int, char, float, etc. to allocate the memory to that variable. Syntax Following is the syntax of variable initialization in C++: datatype variable_name = value; Here, datatype : The datatype of variables like int, char, float, etc. variable_name : This is the name of variable given by user. value : Any value to initialize the variable. By default, it ...

Read More

What is the proper declaration of main in C++?

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 21-Apr-2025 213 Views

The main() function is the entry point of every C++ program where execution begins. It is invoked automatically when the program is executed. The main() function returns the execution status to the operating system (indicating whether the program executed successfully or not). You can also use optional command-line arguments, argc and argv, to pass values to the program. Declaration /Prototype of main() The standard prototype of main() function is as follows: int main() { body } Or, int main(int argc, char *argv[]) { body } Here, argc : Number of arguments passed to the program from the environment ...

Read More

How to call a parent class function from derived class function in C++?

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 21-Apr-2025 11K+ Views

In the OOPs concept of C++, the parent class represents the root of the hierarchy while the derived class is inherited from the parent class. The derived class is presented using the scope resolution operator (::). The derived class is also known as the child class or subclass. What is Parent Class? The parent class is also called a base class used to design the structure of variable and function initialization based on access specifiers (private, public, and protected). Syntax Following is the syntax of parent class in C++: class ParentClass { // Access specifiers: ...

Read More

C++ Program to Find Factorial of Large Numbers

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 21-Apr-2025 2K+ Views

A factorial of a number defines the non-negative integer say n that calculate the product of a number by every positive integer until it reaches 1. The symbol of factorial is (!). Mathematically, it is represented by: n! = n x (n-1) x (n-2) x ... x 1 For eg. factorial of an integer 30! = 265252859812191058636308480000000. 30! = 30x29x28x27x26x25x24x23x22x21x20x19x18x17x16x15x14x13x12x11x10x9x8x7x6x5x4x3x2x1 A non-negative integer is defined by any whole number that is 0 or positive (not a fraction or decimal). What is Large Number? In context of calculating the factorial number, the large number denotes the n value ...

Read More
Showing 61–70 of 185 articles
« Prev 1 5 6 7 8 9 19 Next »
Advertisements