Variable Initialization in C++

Tapas Kumar Ghosh
Updated on 22-Apr-2025 15:17:33

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

When to Use extern in C/C++

Tapas Kumar Ghosh
Updated on 22-Apr-2025 15:15:40

11K+ Views

In C/C++, the extern keyword is used to declare a variable that is defined in another file or scope. It allows the program to access a variable or function that is defined outside the file. There are two main reason of using extern in C/C++ programs which is listed below: The extern is used when the compiler needs to be informed about the existence of a variable that is declared in another file. ... Read More

Swap All Odd and Even Bits in C++

AYUSH MISHRA
Updated on 22-Apr-2025 15:11:28

4K+ Views

We can swap all odd and even bits in a given integer. Swapping of odd and even bits means changing the bits present at odd positions with the bits at even positions in a binary representation of a number. One real-life application is optimizing data storage or modifying data patterns in memory. In this article, we are going to learn how we can swap all odd and even bits of a number in C++ using different approaches. Formula for Swapping Odd and Even Bits Extract all even-positioned bits using a bit mask and shift ... Read More

When to Use JSONStringer in Java

Aishwarya Naglot
Updated on 22-Apr-2025 14:33:12

540 Views

A JSONStringer provides a convenient way of producing JSON text, and it can strictly follow to JSON syntax rules. Each instance of JSONStringer can produce one JSON text. A JSONStringer instance provides a value method for appending values to the text and a key-method for adding keys before values in objects. We have array () and endArray() methods that create and bind array values, and object() and endObject () methods that create and bind object values. It is part of the org.json library. It is generally used in Android and lightweight Java programs. In this article, we will learn when to use a JSONStringer in Java. When to use ... Read More

Convert List to JSON Array in Java

Aishwarya Naglot
Updated on 22-Apr-2025 14:25:07

33K+ Views

Converting a list to a JSON array is one of the common tasks in Java. Let's see how to convert a list to a JSON array in Java. If you do not know what JSON is, then you can read the JSON tutorial. The following are various ways to convert a list to a JSON array in Java: Manual construction of JSON array Using Jackson library Using Gson library Using org.json library Let's learn the process of each of them one by ... Read More

Convert JSON Object to Java Object Using Gson Library in Java

Aishwarya Naglot
Updated on 22-Apr-2025 14:24:14

9K+ Views

Let's see learn how to change a JSON object into a Java object using the Gson library. Gson is a tool made by Google for converting Java objects into JSON and back. JSON stands for JavaScript Object Notation. In the JSON format, data is stored in key-value pairs. Mainly, it is used for sharing data between a server and a web app. Gson is a Java tool that can turn Java objects into JSON and JSON back into Java objects. It is used by many developers because it is simple and easy. Why Convert JSON Object to Java Object? Here ... Read More

Pretty Print JSON Using Gson Library in Java

Aishwarya Naglot
Updated on 22-Apr-2025 12:30:39

4K+ Views

JSON is a data interchange format that is easy to read and write. It is lightweight and gets parsed easily. It is commonly used in web applications for sending and receiving data. To know more about JSON, refer to JSON. Pretty print is a type of formatting that formats data in a more easily readable way by adding indentation and line breaks. It is useful for debugging and logging purposes. Enabling pretty print Using Gson Library Gson is a JSON library for Java, which was created by Google. By using Gson, we can generate JSON and convert JSON to Java objects. ... Read More

Reverse a String In-Place in C or C++

Farhan Muhamed
Updated on 22-Apr-2025 11:42:12

713 Views

Reversing a string means, moving first character to last, second character to second last and so on. In this article we will discuss how to reverse a string in place using C/C++ program. In the "in place" string reversing, we are not allowed take extra memory to store the string while running program. First of all, let's understand our problem statement:We are given a character string as input and we need to find and output the reverse string of the given string. For example: // Input : a character string "This is a string" //Output : Reverse of ... Read More

Generate Random Numbers Using Probability Distribution Function in C++

Ravi Ranjan
Updated on 22-Apr-2025 11:38:55

2K+ Views

The probability density function (pdf) is a function that describes the relative likelihood for this random variable to take on a given value. It is also called as density of a continuous random variable. The probability of the random variable fall within a particular range of values is given by the integral of this variable's density over that range, So, it is given by the area under the density function but above the horizontal axis and between the lowest and greatest values of the range. Probability Distribution is based upon this probability density function. In this article, we will generate ... Read More

Generate Random Numbers Using Middle-Square Method in C++

Ravi Ranjan
Updated on 22-Apr-2025 11:38:27

1K+ Views

The middle-square method is one of the simplest methods of generating random numbers. This method will either begin repeatedly generating the same number or cycle to a previous number in the sequence and loop indefinitely. For a generator of n-digit random numbers, the period can be no longer than the specified n(number of digits). If the middle n digits are all zeroes, the generator then generates zeroes forever. In this article, we will implement a C++ program to generate ten 4-digits random number using the middle-square method. Steps for Middle-Square Random Number Generation The steps for generating random numbers ... Read More

Advertisements