Find the output of the following C Apptitude (2)
My question is
Find the output of the following
void main() { char *s="\12345s\n"; printf("%d",sizeof(s)); }Advance Thanks,
R.Rengaraj
{Java Certification Quiz}
{On this forum my 22nd Question.}
void main() { char *s="\12345s\n"; printf("%d",sizeof(s)); }Advance Thanks,
Member • Dec 6, 2009
Member • Dec 6, 2009
Can you please tell that don't we specify char with ' ' rather than " "The variable s is a pointer to a string. (its because of "").
is it because we have taken it as a char pointer
seeing as if it can be said that the output will be 6
Is it the right answer?
Member • Dec 6, 2009
Member • Dec 6, 2009
Sir,sarveshguptaCan you please tell that don't we specify char with ' ' rather than " "
is it because we have taken it as a char pointer
seeing as if it can be said that the output will be 6
Is it the right answer?
Member • Dec 7, 2009
The output depends on the compiler you use. 16 bit compilers store the pointers as 2 byte entity.dipen30compile this code and run it.
It gives the output 2.
can anyone explain how the output is 2? char contain 1 byte.
Member • Dec 7, 2009
Actually i counted the characters in the stringrengarajSir,
How you say the output is 6 ? can you please explain.
R.Rengaraj
Member • Dec 7, 2009
Member • Dec 7, 2009
dipen30I am using 16-bit compiler. so it gives output 2?
Member • Dec 7, 2009
E_S is exactly right. A pointer is 2 bytes long in 16-bit compilers, and 4 bytes long in 32-bit compilers.dipen30I am using 16-bit compiler. so it gives output 2?
Member • Dec 7, 2009
Member • Dec 8, 2009
Member • Dec 8, 2009
Member • Jul 10, 2016
answer is 2dipen30compile this code and run it.
It gives the output 2.
can anyone explain how the output is 2? char contain 1 byte.