I was testing the use of sizeof operator in C/C++ with this code:
#include <ctype.h> /* Character types */
#include <stdio.h> /* Standard buffered input/output */
#include <stdlib.h> /* Standard library functions */
#include <string.h> /* String operations */
#include <sys/types.h> /* Data types */
#include <sys/wait.h> /* Declarations for waiting */
#include <unistd.h>
void main()
{
char a[100];
char *des = malloc(100*sizeof(char));
strcpy(des,"abcded\0");
printf("%d\n",sizeof(des));
printf("%d\n",sizeof(a));
free(des);
}
Why does this program output:
4
100
As opposed to:
100
100