Revathi Satya Kondra

Revathi Satya Kondra

Technical Content Writer, Tutorialspoint

65 Articles Published

Articles by Revathi Satya Kondra

Page 4 of 7

Compare *ptr++, *++ptr and ++*ptr in C++

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

In C++, both ptr++ and ++ptr are used to increment pointers, but they behave differently in expressions. The difference lies in when the increment happens: before or after the value is used. This is essential when working with loops, arrays, or pointer. Syntax Following is the syntax to compare ptr++ vs ++ptr in C++: ptr++: post-increment; ++ptr: pre-increment; Following is the table to compare ptr++ vs ++ptr in C++ ...

Read More

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<int>(x) instead of (int)x in C++?

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 17-Apr-2025 2K+ 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

Find out the current working directory in C/C++

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

To find the Current Working Directory (CWD) in C or C++ is like asking your program: "Hey, where am I right now?". Simply we can say that it is like a folder of your program which is present and used to operate in. We can use functions like getcwd() from unistd.h in C/C++ or filesystem::current_path() from C++17. Below are the list of the ways to achieve this. Using getcwd() in C/C++ Using filesystem in C++17 Using getcwd() Function in C/C++ In C/C++, we use the getcwd() function. This function gets ...

Read More

Standard Size of character (\\\'a\\\') in C/C++ on Linux

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

In C/C++, every character including 'a' is stored using a specific size in memory. Most of the systems including Linux, the size of a character is 1 byte. This means that any character (like a) can occupy 1 byte(8 bits of memory). To determine how much memory is used by the character 'a', we can use the sizeof() operator. So, it returns the size in bytes of a variable or data type. Following are the list of different ways to check the Standard Size in C/C++. Using sizeof with character literal ...

Read More

Levels of Pointers in C/C++

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

In C/C++, the pointers have multiple levels, which means a pointer can point to another pointer – so the chains of indirection can go on and on. For instance, a pointer to a variable's address is stored at "*ptr" (single-level pointer) while, at "**ptr", the address of another pointer is kept (a double-level pointer), so on. This is useful in allocating memory dynamically, working with multi-dimensional arrays, and handling complicated data structures.Following is the list of different levels of pointers. Let us understand these with the help of examples: Single Level Pointer ...

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 302 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

How do I remove a particular element from an array in JavaScript

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 10-Feb-2025 1K+ Views

In JavaScript, Removing a particular element from an array refers to the process of deleting or filtering out a particular element from the array. so that a element is no longer exists within that array. The Arrays are the most commonly used data structures in JavaScript, allowing developers to store and manipulate collections of items. Syntax Following is the syntax to remove a particular element from an array. array(index, deleteCount[, element1[, element2[, ...]]]) Parameters Here, we have three parameters to remove a particular element from an array in JavaScript − index − The index ...

Read More
Showing 31–40 of 65 articles
Advertisements