Server Side Programming Articles - Page 2300 of 2651

Global memory management in C++ : Stack or Heap?

Samual Sam
Updated on 30-Jul-2019 22:30:25

2K+ Views

Stack and heap are used to store variables during the execution of the program and it also get destroyed.Global data structures or global variables are not consumed by stack or heap. They basically allocated in a fixed memory block, which remains unchanged.int a[10]; // located in a fixed memory block int main() {    int main() {       float *ptr = (int *)malloc(sizeof(float)10.0)); //use heap.    } }

What does “dereferencing” a pointer mean in C/C++?

Samual Sam
Updated on 08-Nov-2024 16:56:54

22K+ Views

Dereferencing is used to access or manipulate data contained in memory location pointed to by a pointer. *(asterisk) is used with pointer variable when dereferencing the pointer variable, it refers to variable being pointed, so this is called dereferencing of pointers. int main() {  int a = 7, b ;  int *p; // Un-initialized Pointer  p = &a; // Stores address of a in ptr  b = *p; // Put Value at ptr in b }Here, address in p is basically address of a variable.Complete tutorial on dereferencing: C++ Dereferencing

How does “void *” differ in C and C++?

Revathi Satya Kondra
Updated on 10-Jun-2025 14:27:29

633 Views

Both languages (C and C++) support void pointers, but their behaviour is different. In C, a void pointer can be directly assigned to any other pointer type without the need for a typecast. However, in C++, assigning a void pointer to any other pointe type require an explicit typecast. In this article, we will learn the differences between void pointers in C and C++.. Void Pointer in C A void pointer (also called a generic pointer) in C is a special type of pointer that can point to any data type, but doesn’t have any type by itself. It ... Read More

Data type of character constants in C and C++

Revathi Satya Kondra
Updated on 30-May-2025 17:31:42

1K+ Views

The character constant is a constant that is enclosed in a single quote (' '). It represents the integer value (i.e., ASCII) of the character. In C programming language, the data type of character constant is an integer (represented by int) and it needs 4 bytes to store a character constant. For example: 'A', '1', '3', etc., are the character constants. In C++, the data type for character constants is char and it needs only 1 byte to store a character constant. Here are the size of different data types in bytes: ... Read More

Can we use function on left side of an expression in C and C++?

Revathi Satya Kondra
Updated on 17-Jun-2025 14:49:02

396 Views

In C, you cannot use a function call on the left side of an assignment if it returns a value because function calls return non-assignable values. For example, function_name() = value; However, if the function returns a pointer, you can dereference it to assign a value. For example, *function_name() = value; In C++, the same rule applies. You can use the returned reference/pointer on the left side to modify the original variable which is valid only if it returns a reference. function_name() = value; Note: References allow direct access to variables, and pointers allow indirect access via dereferencing. ... Read More

Printing Heart Pattern in C

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

9K+ Views

In this program we will see how to print heart shaped pattern in C. The heart shape pattern will be look like thisNow if we analyze this pattern, we can find different section in this pattern. The base of the heart is an inverted triangle; the upper portion has two different peaks. Between these two peaks there is a gap. To make this pattern we have to manage these parts into our code to print the pattern like this.Example Live Demo#include int main() {    int a, b, line = 12;    for (a = line/2; a

C++ Array of Strings

Farhan Muhamed
Updated on 21-Jul-2025 19:04:39

20K+ Views

A string is a sequence of characters used to store information as text. In C++, strings are represented as array of characters using the std::string class. In this article, we will learn what is an array of strings in C++, how to declare and initialize it, and how to access its elements. C++ Array of Strings Array of strings refer to an array where each element is a string. Just like a normal array, we can define an array of strings by specifying the data type as std::string and the size of the array inside square brackets. To initialize ... Read More

Complex numbers in C++

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

9K+ Views

In this section we will see how to create and use complex numbers in C++. We can create complex number class in C++, that can hold the real and imaginary part of the complex number as member elements. There will be some member functions that are used to handle this class.In this example we are creating one complex type class, a function to display the complex number into correct format. Two additional methods to add and subtract two complex numbers etc.Example Live Demo#include using namespace std; class complex {    int real, img;    public:       complex() {   ... Read More

Builtin functions of GCC compiler in C++

Revathi Satya Kondra
Updated on 10-Jun-2025 14:33:31

778 Views

When you want to write a program in C++, your compiler (like GCC) converts your code into computer language. While doing this, GCC offers some special functions called built-in functions. The built-in functions are predefined functions by the compiler itself, but not provided by any standard library. The GCC compiler provides several built-in functions. Some of these functions are listed below: __builtin_popcount(x) __builtin_parity(x) __builtin_clz(x) __builtin_ctz(x) The __builtin_popcount(x) Function This builtin function is used to count the number of 1s in an integer ... Read More

Wide char and library functions in C++

Revathi Satya Kondra
Updated on 10-Jun-2025 13:24:03

4K+ Views

Wide Characters Wide characters are similar to character datatype. The main difference is that char takes 1-byte space, but wide character takes 2-bytes (sometimes 4-byte depending on compiler) of space in memory. For 2-byte space wide character can hold 64K (65536) different characters. So the wide char can hold UNICODE characters. The UNICODE values are international standard which allows for encoding for characters virtually for any character of any language. Example 1: Size of a single wide character This program demonstrates how to declare a single wide character using wchar_t to print its value and memory size. #include using namespace ... Read More

Advertisements