Can someone explain the output of this simple program?
#include <stdio.h>
int main(int argc, char *argv[])
{
char charArray[1024] = "";
char charArrayAgain[1024] = "";
int number;
number = 2;
sprintf(charArray, "%d", number);
printf("charArray : %s\n", charArray);
snprintf(charArrayAgain, 1, "%d", number);
printf("charArrayAgain : %s\n", charArrayAgain);
return 0;
}
The output is:
./a.out
charArray : 2
charArrayAgain : // Why isn't there a 2 here?
2
, you dosizeof(charArrayAgain)
. – Birddog