I am trying to dump the memory of my c++ app.

#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile;
  myfile.open ("example.txt");
  myfile << "Writing this to a file.\r\n";
  int *p;
  *p = 25;
  char b[] = "hello";
  int a;
  for (a=0; a==-1; *(p++)){
  myfile.open ("example.txt");
  myfile << p <<"    "<< *p <<"\r\n";
  return 0;

I get

Writing this to a file.

how to find a size of pointer/array? :D

Recommended Answers

All 3 Replies

You can use sizeof operator...


That's a little bit misleading, the sizeof operator won't work for sizes unknown at compile time. In this case, the size is certainly dynamic and what he'll likely get from sizeof(dynamic_array) is (4), or, the size in bytes of the pointer to its base address.

Note how this is different:

int a[20] = 0;
sizeof(a); // will return 20, because the size is known by the compiler

How to find size of dynamic one?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.