hello everyone I have this snippet of the code
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct Date {
int date;
char* month;
int year;
} Date_t;
typedef Date_t* pDate_t;
void assignMonth(pDate_t birth)
{
//1)
birth->month = "Nov";
//2)
//birth->month = malloc(sizeof(char) * 4);
//birth->month = strcpy(birth->month, "Nov");
}
int main()
{
Date_t birth;
birth.date = 13;
assignMonth(&birth);
birth.year = 1969;
printf("%d %s %d\n",birth.date, birth.month, birth.year);
return 0;
}
in function assignMonth
I have two possibilies for assigning month, both give me the same result in the output, what is the difference between them, I think that second variant is the good one, am I wrong? if yes why? if not why?
thanks in advance for any help
P.S. I'm interested in what is going on in my memory in both cases