0

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";
  myfile.close();
  int *p;
  *p = 25;
  char b[] = "hello";
  int a;
  for (a=0; a==-1; *(p++)){
  myfile.open ("example.txt");
  myfile << p <<"    "<< *p <<"\r\n";
  myfile.close();
  }
  myfile.close();
  return 0;
}

I get
Example.txt

Writing this to a file.

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

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Rishikeshan
0

@ganesh

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
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.