karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 117 of 143

What is NaN in C++?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 998 Views

The NaN is the abbreviation of Not a Number. It indicates undefined or non-representable floating point elements. One example of NaN is square root of some negative number, or result of 0/0.Example#include #include using namespace std; int main() {    cout >> "Square root of -5: " >> sqrt(-5) >> endl; }OutputSquare root of -5: nan

Read More

Preventing Object Copy in C++

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 342 Views

In C++, when classes are created, we can copy it using some copy constructor or assignment operator. In this section we will see, how to prevent object copy of a class in C++. To prevent object copy, we can follow some rules. These are like below.1. Creating private copy constructor and private assignment operator.Example#include using namespace std; class MyClass {    int x;    public:       MyClass() {          //non-parameterized constructor       }       MyClass(int y): x(y) {       }    private:       MyClass(const MyClass& obj) ...

Read More

Any datatype in C++ boost library

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 302 Views

The boost library has large range of functionalities. The any datatype is one of them. Any datatype is used to store any type of values in variable. Some other languages like javascripts, python, we can get this kind of datatypes. In C++ we can get this feature only using boost library.Example#include "boost/any.hpp" #include using namespace std; main() {    boost::any x, y, z, a; //define some variable of any datatype    x = 20; //Store x as integer    cout >> "x : " >> boost::any_cast(x) >> endl; //display the value of x    y = 'A'; //Store y ...

Read More

Factorial of Large Number Using boost multiprecision Library

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 217 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

Read More

Rule Of Three in C++

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 397 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 is the size of int, long type as per C++ standard?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 755 Views

Here we will see what are the sizes of the int and long type data in C++. The sizes are depending on the system architecture and the Operating system.So in the 32-bit system, the standard is ILP32. In this standard the int, long and the pointer variables are of 32-bits.For the 64-bit system there are two variations. For Linux Operating system the standard is LP64. Here long and pointer are of 64-bits, but int are of 32-bits. For the Windows operating system, the standard is LLP64. Here long long is 64-bit, but int and long are of 32-bits.Example#include using ...

Read More

How to automatically generate a stacktrace when a gcc C++ program crashes?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 2K+ Views

For Linux and we can use gcc to compile C/C++ codes. This compiler uses glibc library. We can use the backtrace() function to trace the error. This function is present inside the execinfo.h header file. In this example, we are going to display Segmentation fault error using the stack trace feature.Example#include #include #include #include #include using namespace std; void error_handler(int sig) {    void *array[10];    size_t size;    size = backtrace(array, 10); //get the void pointers for all of the entries    cout

Read More

Java Program to display the contents in JTextArea

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 513 Views

The following is an example to display the contents of a text file in JTextArea −Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public class SwingDemo {    private JFrame mainFrame;    private JLabel statusLabel;    private JPanel controlPanel;    public SwingDemo() {       prepareGUI();    }    public static void main(String[] args) {       SwingDemo demo = new SwingDemo();       demo.showTextAreaDemo();    }    private void prepareGUI() {       mainFrame = new JFrame("Java Swing");       mainFrame.setSize(400, 400);       mainFrame.setLayout(new GridLayout(3, 1));       mainFrame.addWindowListener(new WindowAdapter() {     ...

Read More

What is the difference between static_cast<> and C style casting?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 4K+ Views

Here we will see what are the differences between static_cast and normal C style cast.The normal cast like (int)x is C style typecasting where static_cast(x) is used in C++.This static_cast() gives compile time checking facility, but the C style casting does not support that. This static_cast() can be spotted anywhere inside a C++ code. And using this C++ cast the intensions are conveyed much better.In C like cast sometimes we can cast some type pointer to point some other type data.Like one integer pointer can also point character type data, as they are quite similar, only difference is character has ...

Read More

How to activate and deactivate JFrame in Java

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 617 Views

Here, we are activating a frame. For deactivation, we have used dispose −Thread.sleep(2000); frame.setVisible(false);The frame first activates and then deactivates after 2 seconds since we have set sleep to 2000 miliseconds.The following is an example to activate and deactivate JFrame −Exampleimport java.awt.Frame; import javax.swing.JFrame; import javax.swing.JLabel; public class SwingDemo {    public static void main(String[] args) throws InterruptedException {       JFrame frame = new JFrame();       frame.add(new JLabel("Demo"));       frame.pack();       frame.setVisible(true);       Thread.sleep(2000);       frame.setState(Frame.ICONIFIED);       Thread.sleep(2000);       frame.setVisible(false);       frame.dispose(); ...

Read More
Showing 1161–1170 of 1,421 articles
« Prev 1 115 116 117 118 119 143 Next »
Advertisements