Memory Allocation for Strings

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    // Memory allocation for strings
    char *dynamicString;

    dynamicString = (char *)malloc(50 * sizeof(char));

    if (dynamicString == NULL) {
        printf("Memory allocation failed.\n");
        return 1;
    }

    // Use the dynamically allocated string

    // Free the allocated memory
    free(dynamicString);

    return 0;
}
chevron_left
chevron_right

Leave a comment

Your email address will not be published. Required fields are marked *

Comment
Name
Email
Website