malloc

How does C / C++ know how much memory to free up if it doesn't know the size of the array?

In C / C++, in order to process an array, you need to know its size. Accordingly, you should always "remember" this size and ... r to the array. And if C / C++ can somehow calculate the size, then why constantly "drag" it with you in a separate variable?

Differences between calloc and malloc functions

What is the difference between the malloc function and calloc? Are there any cases where only one of these functions is suitable?

Violation of access rights when writing to an address in C. The strcat function

There is a simple mp3 player: #include <windows.h> #include <Mmsystem.h> #pragma comment(lib,"winmm.lib") #pragm ... ject4.exe: 0xC0000005: нарушение прав доступа при записи по адресу 0x00C27B3D. Why does this error occur? How can solve it?

What is the difference in the syntaxes ptr = (int*) malloc(sizeof (int)) and ptr = malloc(sizeof (int))?

I have a doubt about dynamic allocation in C. At the time of allocating memory I have seen these two types of syntax: ptr ... t the difference in use between them. Each site seems to talk about something different. Could anyone explain the difference?

How to allocate a dynamic stack, with size provided by the user?

I want to allocate a dynamic stack with the size provided by the user, then treating it as a "vector" would be more or less w ... == NULL) return 0; Elem* no; no = (Elem*) malloc(tam * sizeof(Elem)); if(no == NULL) return 0; }

Semantic difference of "Malloc" and Calloc"

I was in the programming class with C and I had doubts about the difference between Malloc and Calloc, but not in what each o ... does, but in the meaning of "M" and "C". I know that Malloc comes from memory allocation, already the Calloc I have no idea.

Malloc does not work in C code

When trying to compile the code I get the following error messages: #include <stdio.h> #include <stdlib.h> # ... ; default: printf("Operação não disponível\n"); break; } } while(opcao != 0); return OK; }

Malloc function error: sysmalloc: Assertion failed in C

I am implementing a Red Black Tree in C, and when I am going to allocate memory to the second node, it gives the error: ... return insert(node->left, node, key); } else return insert(node->right, node, key); }

Dynamic allocation in C-unknowingly allocating the total amount of elements

I am having a doubt regarding dynamic allocation in c, as to the use of function malloc(). If we take, for example, a case o ... t had only 10 characters? Would I occupy only the first 10 spaces and the other 10? Would there be a waste in that case then?

Handling malloc() and realloc()

I still don't feel completely confident about using malloc() or realloc(), are these two ways equivalent? 1) int main() { ... mory? scanf(" %s", s2); s2=malloc(strlen(s2)); What does it really do a malloc() and realloc() internally in memory?

Casting The Return of Malloc (), Calloc () and Realloc () - C

According to the discussion of I cast the result of malloc?, in C it is not recommended or correct to cast Malloc () return. ... also apply to Calloc() and Realloc () functions? Taking advantage, the correct is to speak Cast, Casting or are both correct?

insert names neatly into a list, I'm not knowing fz this

/ / function to insert ai; ai so does it with the first 3 names, the others it does not sort Aluno *cad(Aluno *aluno) { ... if(aux3->prox == NULL) { aux3->prox = criar; } } aluno = aux; } return aluno; }

sizeof does not work to determine malloc size

Well, I was doing some data structure work when I came across the need to allocate a vector dynamically, however, even alloca ... always the same, i.e. vector size in bytes is always 8. Why does this happen, and what would be the solution to this problem?

How do I pass the address of the first char of a string to a function write to it?

The problem is this: I made a function that takes the output of a certain command from the OS and stores it in a string. The ... umber++; } pclose(fp); return 0; } Note: I know the code won't work, it's just to get an idea of the structure.

Error relocating struct vector to add more positions

I am doing a college job where it is necessary to develop a program for shoe stock management. When inserting the eleventh ... do.quantidade); printf("Valor: "); scanf("%f", &parCalcado.valor); printf("\n"); return parCalcado; }

Problems with CRUD in C (delete method)

In the Delete function, the user will inform an RA that wants to delete, when the RA exists in the memory it deletes, this pa ... f the previous one is NULL it means that it has already traversed all structs, then it does not exist, but it is not working

Pointer pointing to another pointer, how to use free () correctly?

When I have a pointer pointing to another pointer like: int *ponteiro1 = malloc(sizeof(int)); int *ponteiro2; *ponteiro1 = ... I use the free(ponteiro2) command, so am I deallocating the ponteiro1? If yes, should I then do some treatment for ponteiro2?

Error when deallocating array-double free or corruption C

Hello, I'm making a program to rotate an array, which after allocating performs the rotation function, and then deallocates t ... in the case, the cop Matrix), x and y is the size of the Matrix necessary for the image to be rotated. Theta = 90º as example

C-Stack Smashing Detected - how to properly initialize a graph by adjacency list and insert edges?

I am receiving, sporadically and without having made any changes to the code or input, an error called Stack Smashing Detecte ... g1); insereAresta(3, 5, 1, &g1); insereAresta(4, 5, 1, &g1); */ printf("Compilou carajo!\n"); return 0; }