A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
In the description of the warning in the doc at the
link provided by RLWA32:
"This warning indicates that your code dereferences a
potentially null pointer."
the key word is "potentially". If calloc should fail
then the pointer will be NULL, if it succeeds it
won't be NULL. That will only be known at run time,
and could be different at different times under
varying circumstances. So the compiler has no way
to tell what will happen at run time, but it
can tell what might happen and is warning you
of the possibility.
As the doc also suggests, if you add code to verify
that calloc has not failed then the compiler will
suppress that warning. For example:
int n; scanf_s("%d", &n);
int** dArray = calloc(n, sizeof(int*));
if(!dArray)
{
return -1;
}
for (int r = 0; r < n; r++)
{
*(dArray + r) = calloc((r + 1), sizeof(int));
}
or
int n; scanf_s("%d", &n);
int** dArray = calloc(n, sizeof(int*));
if(dArray)
{
for (int r = 0; r < n; r++)
{
*(dArray + r) = calloc((r + 1), sizeof(int));
}
}
- Wayne