Skip to content

in Insertion-sort.c : the user can access to other blocks of memory #1628

@wassim31

Description

@wassim31

int n, array[1000], c, d, t; printf("Enter number of elements\n"); scanf("%d", &n);

the compiler is allocating 4000 bytes in the stack , then the program asks the user how many elements he wants..
instead of that , it's better to ask the user how many elements he wants first ( upper-bounded ) , do dynamic memory allocation on the heap segement using standard library function void * malloc( size_t memorySize );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions