Undeclared Usage of srand(), rand(), and system() Functions

In handling extensive software projects involving sizeable teams, it is crucial to distinguish between time intervals and “absolute” times and be aware of their magnitudes. As a solution, one can use a function that accepts an argument of type unsigned int.

Solution 1:

The function calls you made were assumed to accept an unknown number of arguments and return values of type


since you failed to provide

#include <stdlib.h>

. This can lead to undefined behavior.

To begin, add the code

#include <stdlib.h>

to the top of your file.

Solution 2:

My situation was alike; the code compiled successfully, still, a warning message appeared.

// Selection sort
int main()
    int list[100], i;
    for(i = 0 ; i < 100; i++) {
        list[i] = ( rand()%99 + 1 );
        printf("%d ", list[i]);
    } printf("n");
    return 0;

When I compile it,

gcc -o selection_sort selection_sort.c -lm
selection_sort.c: In function ‘main’:
selection_sort.c:11:15: warning: implicit declaration of function ‘rand’; did you mean ‘nanl’? [-Wimplicit-function-declaration]
list[i] = ( rand()%99 + 1 );

The warning message disappeared once


was included.

Frequently Asked Questions