Programming Articles - Page 575 of 3363

C++ Program to Convert int Type Variables into String

Arnab Chakraborty
Updated on 19-Oct-2022 11:11:18

737 Views

Integer type variables in C++ are able to store positive or negative integer values upto a predefined range. String variables can store a sequence of alphabets, numerals, and special characters. There are many use cases where the conversion from int to string is needed. We discuss 3 different methods to convert an integer variable into a string. If we discuss the algorithm, it is pretty straightforward. We take input in an integer variable and then convert it into a string variable. Using to_string function The easiest way in C++ to convert an integer value to a string is using the ... Read More

C++ Program to Convert String Type Variables into Boolean

Arnab Chakraborty
Updated on 19-Oct-2022 11:09:27

8K+ Views

In C++, Boolean variables consists of binary data true or false and string variables are a sequence of alphabets, numerals, and special characters. Conversion between string to Boolean isn’t possible natively by the compiler, but there are several ways to perform this conversion. We explore the various ways using which we can convert a string value into a Boolean. If we think about the algorithm , it is quite easy. We take a string value and convert into Boolean using various ways. Algorithm (generalized) Take input in a string variable. Convert the string value (true or false) into a ... Read More

C++ Program to convert Boolean Variables into String

Arnab Chakraborty
Updated on 19-Oct-2022 11:07:37

4K+ Views

Boolean variables in C++ can contain only two distinct values, ‘true’ or ‘false’. If we translate these values to string, ‘true’ will be mapped to ‘1’ and ‘false’ will be mapped to ‘0’. Boolean values are mainly used to check if a condition in a program has been met or not. There aren’t direct conversions from Boolean to string like we have seen in conversions from int to long and float to double. But there are needs to translate a Boolean value to string, and we explore different ways to convert a binary Boolean value to a string value. Using ... Read More

C++ Program to Convert int Type Variables to long

Arnab Chakraborty
Updated on 19-Oct-2022 11:01:52

10K+ Views

C++ is a statically typed language, and because of that all of its variables require the datatype to be declared beforehand. The datatypes are used to represent which type of value is contained inside a variable. In C++, the variables to contain numerical values are int, long, float, and double. int and long are used to represent integer values, whereas float and double are used to represent fractional values. Both int and long contains integer values with one difference which is, int is of size 4 bytes and long is of size 8 bytes. Conversion of int to long can ... Read More

C++ Program to Convert long Type Variables to int

Arnab Chakraborty
Updated on 19-Oct-2022 11:00:15

8K+ Views

C++ has support for various different datatypes to accommodate the different representations and sizes of data. The datatypes that can be used to represent numerical values in C++ are int, long, float, and double. int and long are used to represent integer values, whereas float and double are used to represent fractional values. Both int and long contains integer values with one difference which is, int is of size 4 bytes and long is of size 8 bytes. Conversion of long to int can be done in two different ways, one is through implicit conversion and the another one is ... Read More

C++ Program to Check if a String is Numeric

Arnab Chakraborty
Updated on 19-Oct-2022 10:58:28

12K+ Views

It can be quite helpful to use strings or characters while tackling logical programming difficulties. Characters in strings are 1-byte data types that can store symbols from ASCII values. Strings are collections of characters. The symbols could be special characters, numerals from the numeric system, or letters from the English alphabet. This article will teach you how to use C++ to determine whether a character is a numeric character or not. Checking string is numeric or not To check whether the given string is numeric or not, we need to check each character in it is a digit or not. ... Read More

C++ Program to Check Whether a Character is Alphabet or Not

Arnab Chakraborty
Updated on 19-Oct-2022 10:45:26

4K+ Views

Using strings or characters is sometimes very useful while solving some logical programming problems. Strings are a collection of characters and characters are 1-byte datatype to hold symbols from ASCII values. The symbols can be letters from English alphabets, numeric digits, or special characters. In this article, we shall learn how to check whether a character is a letter in English an alphabet or not using C++. Checking isalpha() function To check whether a number is an alphabet or not, we can use the isalpha() function from the ctype.h header file. This takes a character as input and returns true ... Read More

C++ Program to Check Whether a Number is Positive or Negative

Arnab Chakraborty
Updated on 19-Oct-2022 10:44:04

5K+ Views

In modern programming languages we work with signed numbers and unsigned numbers also. For signed numbers the numbers can be positive or negative or zero. To represent negative numbers, the systems store the numbers in 2’s complement method. In this article we shall discuss how to determine a given number is positive, or negative in C++. Checking using if-else conditions The basic sign checking can be done by using if else conditions. The syntax for the if-else conditions is like below − Syntax if { perform action when condition is true } else { ... Read More

C++ Program to convert the Binary number to Gray code using recursion

Arnab Chakraborty
Updated on 19-Oct-2022 10:42:21

936 Views

Gray codes or reflected binary codes are a special type of binary representation of numbers in which two successive values differ in only one bit. For example, the binary equivalent of 1 and 2 are 01 and 10, here two bits are changing. But in gray code, the 1 is 01 and 2 is 11, only one bit is changing. In this article, we will see how we can convert a given binary number into its gray code equivalent by using recursion in C++. Passing number as a decimal integer In the first example, we are providing the number in ... Read More

C++ Program to pass a string to the function

Arnab Chakraborty
Updated on 19-Oct-2022 12:42:32

23K+ Views

Any programming language that uses functions has code that is simpler, more modular, and simpler to change while being debugged. Functions are a remarkably beneficial component in a modular piece of code. A function can take arguments and perform certain operations on them. Like other primitive datatypes, we can also pass object types or arrays as an argument. In this article, we will see how to pass string-type data as a function argument in C++. Passing C++ like string argument to a function C++ supports stronger string objects which is actually a class with different member functions associated with them. ... Read More

Advertisements