Revathi Satya Kondra

Revathi Satya Kondra

Technical Content Writer, Tutorialspoint

65 Articles Published

Articles by Revathi Satya Kondra

Page 5 of 7

Dangling, Void, Null and Wild Pointers in C++

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 17-Apr-2025 1K+ Views

In C++, direct memory access is possible using pointers. However, the improper use of pointers can lead to problems such as dangling pointers, null pointers, void pointers, and wild pointers. You must have to fix these problems properly for correct code compilation and execution. Let us learn how these problems occur and how you can fix them. Dangling Pointer A dangling pointer is a variable that points to invalid or freed memory, causing errors if accessed. It is like calling a disconnected phone number. When the local variable is not static, the pointer pointing to it becomes dangling. Syntax Following ...

Read More

Why use static_cast(x) instead of (int)x in C++?

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 17-Apr-2025 3K+ Views

The (int)x is C-style typecasting, where static_cast(x) is used in C++. This static_cast() gives a 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 intentions are conveyed much better. In C like cast, sometimes we can cast some type pointer to a point some other type data. Like one integer pointer can also point character type data, as they are quite similar, the only difference is character has 1-byte, integer has 4-bytes. In C++, the static_cast() is more strict than C-like casting. ...

Read More

Understanding cin.clear() and cin.ignore() in C++

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 11-Apr-2025 2K+ Views

When we attempt to work with user input in C++, unwanted behavior may be caused by errors or leftover characters in the input buffer. So, in that case cin.clear() and cin.ignore() are functions that can help in dealing with this kind of problem. cin.clear() cin.ignore() cin.clear and cin.ignore() cin.clear() The cin.clear() resets the error flags on the cin stream and is used when an input operation fails (e.g., entering a non-numeric value for an integer variable). Without clearing the error flags, further input operations will not work. ...

Read More

Why is it considered a bad practice to omit curly braces in C/C++?

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 11-Apr-2025 1K+ Views

In C/C++, omitting the curly braces assumes that only the first statement is the block and this leads to quite a few issues during debugging, as code is pretty tough to read and comprehend. Curly braces help us prevent errors and confusion, which also helps with the flow of the program. Proper Use of Curly Braces In C++, we can omit the curly braces after if-else statements, or after any loop. If we do not use curly braces, then only one statement after the if-else or loop will be considered under that block. Syntax The following is the syntax: − ...

Read More

C++ Program to Print only Odd Numbered Levels of a Tree

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 11-Apr-2025 323 Views

In C++, to print the odd-numbered levels of a binary tree, the levels are numbered from the root as Level 1. The odd-numbered levels are Level 1, Level 3, and so on. This program prints the nodes present at these odd levels. It uses level-order traversal to process the tree level by level and prints the nodes found at these levels. Algorithm to Print only Odd Numbered Levels of a Tree Following is the Algorithm to print odd numbered levels of a tree − Create a structure for tree nodes with data and pointers to left ...

Read More

Static methods vs Instance methods in Java

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 28-Jan-2025 3K+ Views

In Java, the behaviour of any variable or method is defined by the keyword used in front of its declaration. One of the non-access modifiers is static, which can be used with both methods and variables. The static methods are defined at the class level and can be accessed without creating an instance of the class, while instance methods require an object of the class for accessibility. Static methods exist as a single copy for the entire class, whereas instance methods exist as multiple copies, depending on the number of instances created for that particular class. Static methods cannot directly ...

Read More

Java Math subtractExact(long x, long y) method

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 28-Jan-2025 581 Views

We will discuss the Java Math subtractExact(long x, long y) method in Java and understand its functionalities and working. The subtractExact()is an inbuilt function in the Java Math library. The function returns the difference between the two parameters passed as arguments in the function. The function returns an exception when the returned value overflows the range of values of a particular data type. It is the most commonly used class for mathematical operations is the java.lang.Math class is a part of the Java Standard Library and is included in the java.lang package. Syntax Following is the syntax of the subtractExact() function ...

Read More

Java program to find the length of the Longest Consecutive 1’s in Binary Representation of a given integer

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 28-Jan-2025 540 Views

The length of the longest consecutive 1s in the binary representation of a given integer involves converting the integer to its binary form and then identifying the longest run of contiguous 1s. Here, we can represent each integer in binary as a series of 0s and 1s. Bitwise operations allow efficient bit manipulation, making it easy to count and update the longest sequence of consecutive 1s. Consider special cases such as when the integer is 0 (binary representation 0) or when it contains only 1s (e.g., for the number 7, binary 111). To understand the concept clearly, Let's go through ...

Read More

What is Runnable interface in Java?

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 17-Jan-2025 2K+ Views

An interface is like a reference type, similar to a class that enforces the rules that the class must implements(It is a keyword). An interface may have abstract methods i.e. methods without a definition and also constants or variables with fixed value. What is a Runnable interface in Java? If your class is intended to be executed as a thread, then you can achieve this by implementing a Runnable interface. This belongs to the java.lang package. The Runnable interface in Java is a functional interface that enables the compiled code of the class to run as a separate thread. The ...

Read More

Java Program to return a Date set to noon to the closest possible millisecond of the day

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 14-Jan-2025 419 Views

To set a Date object to noon to the closest possible millisecond of the day, we will make sure that the hour is set to noon, and both the minutes, seconds, and milliseconds are set to zero. This precise setting can be achieved using the Calendar class in Java. By setting these specific fields, we can ensure that the time is 12:00:00.000 PM, providing the closest possible millisecond representation of noon. Returning a date set to noon to the closest possible millisecond of the day in Java is quite easy. Let's learn the following ways: ...

Read More
Showing 41–50 of 65 articles
« Prev 1 3 4 5 6 7 Next »
Advertisements