S
Shivanand Kadwadkar
I was trying to test what is the output of program if i dont reserve
any space for '\0' in the character array that i have declared.
---------------------------------------------------------------------------------
#include<stdio.h>
int main()
{
char var1='A',var2[2]="BC",var3='E';
printf("\n var1=%c var2=%s var3=%c and sizeof(var2)=
%d",var1,var2,var3,sizeof(var2));
return 0;
}
output:
var1=A var2=BC var3=E and sizeof(var2)=2
in memory they are allocated in following way:
FFF5 : A
FFF4 : // i havent checked what is here ? assumed it is \0
FFF3 :C
FFF2 :B
FFF1 : E
my question here is, is compiler implicitly reserves a byte for '\0'
when we dont reserve any space for '\0' as the case with var2 always?
---------------------------------------------------------------------------------
any space for '\0' in the character array that i have declared.
---------------------------------------------------------------------------------
#include<stdio.h>
int main()
{
char var1='A',var2[2]="BC",var3='E';
printf("\n var1=%c var2=%s var3=%c and sizeof(var2)=
%d",var1,var2,var3,sizeof(var2));
return 0;
}
output:
var1=A var2=BC var3=E and sizeof(var2)=2
in memory they are allocated in following way:
FFF5 : A
FFF4 : // i havent checked what is here ? assumed it is \0
FFF3 :C
FFF2 :B
FFF1 : E
my question here is, is compiler implicitly reserves a byte for '\0'
when we dont reserve any space for '\0' as the case with var2 always?
---------------------------------------------------------------------------------