Server Side Programming Articles - Page 2309 of 2651

References in C++

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

293 Views

A reference variable is an alias, that is, another name for an already existing variable. Once a reference is initialized with a variable, either the variable name or the reference name may be used to refer to the variable.References vs PointersReferences are often confused with pointers but three major differences between references and pointers are −You cannot have NULL references. You must always be able to assume that a reference is connected to a legitimate piece of storage.Once a reference is initialized to an object, it cannot be changed to refer to another object. Pointers can be pointed to another ... Read More

Execute both if and else statements in C/C++ simultaneously

Revathi Satya Kondra
Updated on 17-Apr-2025 18:39:52

441 Views

In this article, we will see how to execute the if and else section simultaneously in a C or C++, code. This solution is a little bit tricky. When the if and else are executed one after another then it is like executing statements where if-else are not present. But here we will see if they are present how to execute them one after another. Let's go through the different ways to simulate execution of both if and else blocks. This may include using functions, macros, or separating logic completely. Using Separate Functions ... Read More

Levels of Pointers in C/C++

Revathi Satya Kondra
Updated on 11-Apr-2025 22:04:00

337 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

How does #include work in C++?

Revathi Satya Kondra
Updated on 17-Apr-2025 18:38:17

3K+ Views

In C++, the is a header file. This file includes all standard library. Sometimes in some coding contests, when we have to save time while solving, then using this header file is helpful. In software engineering approach we should reduce the minimize the include. Using this header file, it will include lots of files, sometimes that may not be required in the program. So it may increase the compile time and program size. The disadvantages of this header file is listed below. This is ... Read More

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

George John
Updated on 30-Jul-2019 22:30:25

3K+ Views

Dangling pointerDangling pointer is a pointer pointing to a memory location that has been freed (or deleted). There are different ways where Pointer acts as dangling pointerFunction CallThe pointer pointing to local variable becomes dangling when local variable is not static.int *show(void) {    int n = 76; /* ... */ return &n; }OutputOutput of this program will be garbage address.De-allocation of memoryint main() {    float *p = (float *)malloc(sizeof(float));    //dynamic memory allocation.    free(p);    //after calling free()    p becomes a dangling pointer p = NULL;    //now p no more a dangling pointer. }Variable goes ... Read More

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

Revathi Satya Kondra
Updated on 17-Apr-2025 18:03:55

3K+ 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

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

Revathi Satya Kondra
Updated on 17-Apr-2025 17:56:51

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

How do you declare an interface in C++?

Revathi Satya Kondra
Updated on 17-Apr-2025 17:58:16

522 Views

The C++ interfaces are implemented using abstract classes and these abstract classes should not be confused with data abstraction which is a concept of keeping implementation details separate from associated data. A class is made abstract by declaring at least one of its functions as a pure virtual function. A pure virtual function is specified by placing "= 0" in its declaration as follows : class Box { public: // pure virtual function virtual double getVolume() = 0; private: ... Read More

Which one is better in between pass by value or pass by reference in C++?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

559 Views

In C++ we can pass arguments into a function in different ways. These different ways are −Call by ValueCall by ReferenceCall by AddressSometimes the call by address is referred to as call by reference, but they are different in C++. Incall by address, we use pointer variables to send the exact memory address, but in call by reference we pass the reference variable (alias of that variable). This feature is not present in C, there we have to pass the pointer to get that effect.In this section, we will see what are the advantages of call by reference over call ... Read More

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

Revathi Satya Kondra
Updated on 17-Apr-2025 18:00:07

7K+ 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

Advertisements