answersLogoWhite

0

Hi,

The following statement will give the size.

(char*)(ptr+1)-(char*)(ptr)

Kalyan.S

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

Memory mangment New and delete pointer to object link list?

In C++, memory management for linked lists typically involves using new to allocate memory for each node and delete to deallocate that memory when nodes are no longer needed. When creating a linked list, each node is dynamically allocated using new, which returns a pointer to the allocated memory. To avoid memory leaks, it's crucial to traverse the list and use delete on each node before the list goes out of scope or is destroyed. Properly managing memory ensures that resources are freed, preventing memory leaks and ensuring efficient memory use.


What is an array of pointers to pointers?

A pointer is a variable that stores value of address of a variable. Since a pointer itself is a variable, it is allocated a memory location.Pointer to pointer means a pointer which points to the address of a pointer. In other words a pointer to a pointer has the address of the address of a variable.We can have pointers to int, and pointers to char, and pointers to any structures we've defined, and in fact pointers to any type in C, it shouldn't come as too much of a surprise that we can have pointers to other pointers. If we're used to thinking about simple pointers, and to keeping clear in our minds the distinction between the pointer itself and what it points to, we should be able to think about pointers to pointers, too, although we'll now have to distinguish between the pointer, what it points to, and what the pointer that it points to points.


Write an Algorithm to delete a last element from the array?

// Assuming you dynamically allocated this array using "new"... delete array[arraysize - 1]; arraysize--;


How do you delete variables that are dynamically allocated?

It depends, especially if you are going to use C++.If you allocated the variable using the malloc call or any of its derivatives you must use the corresponding 'free' subroutine call to delete them.If you use the more modern C++ 'new' operator, then use the 'delete' operator to remove the memory dynamically in the program.


What is the function to allocate memory?

In C and C++, the function used to allocate memory dynamically is malloc() (memory allocation). It allocates a specified number of bytes and returns a pointer to the first byte of the allocated memory. In C++, the new operator is commonly used for memory allocation, as it also constructs objects. It's important to free allocated memory using free() in C or delete in C++ to avoid memory leaks.


What is a segmentation fault?

An error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers in the source code, dereferencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.


What is a segment fault?

An error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers in the source code, dereferencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.


Call by reference using pointer in c plus plus?

Example: void foo( MyClass& object ){} // function with call by reference signature MyClass* p = new MyClass(); // instantiate a pointer to MyClass foo( *p ); // call by reference using the pointer


Why are pointers needed in C programming?

pointer is used when we want to retain the change in values between the function calls. Similarly double pointer is used when we want to retain the change in pointers between the function calls. If you want to modify pointers than you need double pointer to retain the change.


What is the difference between destructors and delete?

Delete is a built-in operator used forcibly release a dynamically allocated resource. Delete can only be used on pointer types, including pointer arrays. A destructor is a class method used to clean up any resources acquired by objects of the class. Destructors are invoked automatically from the most-derived class to the least-derived class, as soon as an object falls from scope. When you delete a pointer to an object, the object's destructor sequence is invoked. Note that you must not delete named objects otherwise you end up with a null reference. References must never be null.


What are problem that can be arise when using allocating memory dynamic memory?

1. Using memory before/after the allocated area.2. Using the memory after deallocation.3. Forgetting deallocation.4. Multiple deallocation.5. Non-checking whether the allocation was succesfull or not.Not releasing dynamically allocated memory when it is no longer needed can cause the system to run out of mmory prematurely .this sometimes called a"memory leak"


What is pointer in java?

There is no concept similar to pointers in Java. Pointers are a feature in C programming using which a programmer can access the memory. This was the cause of major catastrophic programming bugs. The creators of Java excluded this feature just to avoid such catastrophic bugs.