I allocate memory

int *A; A = (int*)malloc(strlen(Text) *sizeof(int)); 

The debugger shows that the text is and the length of the text is rather big, only memory is allocated only for 1 element. Why is it and how to fix it? enter image description here

Closed due to the fact that the essence of the question is not clear to the participants insolor , 0xdb , MSDN.WhiteKnight , pavel , Grundy Aug 26 '18 at 10:54 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 3
    What makes you think that memory is allocated for one element? - Croessmah
  • What does it mean to be "allocated only to one element" Why do you think so? And what kind of "element" are we talking about? - AnT
  • What is going on here? Why is sizeof (int), what relation does int type have to Text? malloc allocates as many bytes as you told it in the parameter, and returns void *. The size of the allocated memory in the debugger looks at least strange in this way. - wirtwelt
  • one
    The debugger simply shows you the address (0x033a0068) and the first 4 bytes at this address, interpreting from as int ( -842150451 ). Since int* can be both an array and a pointer to a single number, the debugger always thinks that it is a pointer to one int and shows you its address and numbervegorov

0