S
somenath
Hi All,
I have a doubt regarding the pointer assignment . Please have a look
at the following program .
#include<stdio.h>
#include<stdlib.h>
#define NAMESIZE 10
#define SAFE_FREE(t) if(t)\
{\
free(t);\
t=NULL;\
}\
int main(void)
{
char *s = malloc(NAMESIZE * sizeof *s);
s = "somenath";
*(s+1)= 'b';/* will it show undefine behavior ??*/
puts(s);
SAFE_FREE(s);
return 0;
}
My question is
1) is the assignment "s = "somenath"; " copy the string to s?
2) is the behavior of *(s+1)= 'b' is defined ?
Currently I am getting the output as
sbmenath
Regards,
Somenath
I have a doubt regarding the pointer assignment . Please have a look
at the following program .
#include<stdio.h>
#include<stdlib.h>
#define NAMESIZE 10
#define SAFE_FREE(t) if(t)\
{\
free(t);\
t=NULL;\
}\
int main(void)
{
char *s = malloc(NAMESIZE * sizeof *s);
s = "somenath";
*(s+1)= 'b';/* will it show undefine behavior ??*/
puts(s);
SAFE_FREE(s);
return 0;
}
My question is
1) is the assignment "s = "somenath"; " copy the string to s?
2) is the behavior of *(s+1)= 'b' is defined ?
Currently I am getting the output as
sbmenath
Regards,
Somenath