Skip to content

Commit

Permalink
“c-pointer”
Browse files Browse the repository at this point in the history
  • Loading branch information
LordMoMA committed Mar 11, 2024
1 parent 0cc05d0 commit 82afc69
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Patterns-C/Backtracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ The size of 10000 * sizeof(char*) depends on the size of a pointer on your syste

Remember that sizeof(char*) gives the size of a pointer to a char, not the size of a char itself. The size of a char is always 1 byte, but the size of a pointer can vary depending on the system.

```c
int* res = malloc(10 * sizeof(int)); // Dynamically allocates memory for an array of 10 integers

char** res = malloc(10 * sizeof(char*)); // Dynamically allocates memory for an array of 10 strings
for(int i = 0; i < 10; i++) {
res[i] = malloc(50 * sizeof(char)); // Allocate memory for each string
}

free(res); // For the integer array

for(int i = 0; i < 10; i++) {
free(res[i]); // Free each string
}
free(res); // Then free the array of strings
```
```c
void backtrack(int left, int right, char* path, char*** res, int* returnSize, int* pathSize) {
if (left == 0 && right == 0) {
Expand Down

0 comments on commit 82afc69

Please sign in to comment.