Samual Sam has Published 2492 Articles

What is the difference between an int and a long in C++?

Samual Sam

Samual Sam

Updated on 26-Jun-2020 09:20:19

1K+ Views

intThe datatype int is used to store the integer values. It could be signed or unsigned. The datatype int is of 32-bit or 4 bytes. It requires less memory area than long to store a value. The keyword “int” is used to declare an integer variable.The following is the syntax ... Read More

When to use extern in C/C++

Samual Sam

Samual Sam

Updated on 26-Jun-2020 09:18:57

10K+ Views

External variables are also known as global variables. These variables are defined outside the function and are available globally throughout the function execution. The “extern” keyword is used to declare and define the external variables.The keyword [ extern “C” ] is used to declare functions in C++ which is implemented ... Read More

What is the size of an object of an empty class in C++?

Samual Sam

Samual Sam

Updated on 26-Jun-2020 09:17:42

255 Views

The following is an example to find the size of object of an empty class.Example Live Demo#include using namespace std; class p1 {    public:    void first() {       cout

Java Program to add leading zeros to a number

Samual Sam

Samual Sam

Updated on 26-Jun-2020 09:15:38

14K+ Views

To add leading zeros to a number, you need to format the output. Let’s say we need to add 4 leading zeros to the following number with 3 digits.int val = 290;For adding 4 leading zeros above, we will use %07d i.e. 4+3 = 7. Here, 3, as shown above, ... Read More

How to catch a divide by zero error in C++?

Samual Sam

Samual Sam

Updated on 26-Jun-2020 09:13:25

521 Views

The following is an example to catch a divide by zero error.Example Live Demo#include using namespace std; int display(int x, int y) {    if( y == 0 ) {       throw "Division by zero condition!";    }    return (x/y); } int main () {    int a = 50;    int b = 0;    int c = 0;    try {       c = display(a, b);       cout

Java NumberFormat.getInstance() method

Samual Sam

Samual Sam

Updated on 26-Jun-2020 09:12:20

393 Views

The java.text.NumberFormat class is used for formatting numbers and currencies as per a specific Locale. Number formats varies from country to country.To get the instance of the NumberFormat class, call getInstance() method in Java.First, we will use the getInstance() method.NumberFormat n = NumberFormat.getInstance();Now, we will format a double.double val = ... Read More

Swapping two variable value without using third variable in C/C++

Samual Sam

Samual Sam

Updated on 26-Jun-2020 09:12:20

438 Views

The following is an example of swapping two variables.Example Live Demo#include int main() {    int a, b;    printf("Enter the value of a : ");    scanf("%d", &a);    printf("Enter the value of b : ");    scanf("%d", &b);    a += b -= a = b - a; ... Read More

Why does C++ require a cast for malloc() but C doesn't?

Samual Sam

Samual Sam

Updated on 26-Jun-2020 09:11:25

713 Views

In C language, the void pointers are converted implicitly to the object pointer type. The function malloc() returns void * in C89 standard. In earlier versions of C, malloc() returns char *. In C++ language, by default malloc() returns int value. So, the pointers are converted to object pointers using ... Read More

How to convert a single char into an int in C++

Samual Sam

Samual Sam

Updated on 26-Jun-2020 09:09:53

596 Views

The following is an example to convert a character into int.Example Live Demo#include using namespace std; int main() {    char c = '8';    int i = c - 48;    cout

Java NumberFormat.getPercentageInstance() method

Samual Sam

Samual Sam

Updated on 26-Jun-2020 09:09:02

385 Views

The java.text.NumberFormat class is used for formatting numbers and currencies as per a specific Locale. Number formats varies from country to countryTo format a number as percentage you need a percentage NumberFormat instance. To achieved this, use the getPercentageInstance() method.Example Live Demoimport java.text.NumberFormat; import java.util.Locale; public class MainClass {    public static void main(String[] args) {        // Currency ... Read More

Advertisements