Find the output of the following C Apptitude (2)
Sir / madam,
My question is
Find the output of the following
R.Rengaraj
{Java Certification Quiz}
{On this forum my 22nd Question.}
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.}
Replies
-
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? -
gaurav.bhorkar
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?
The answer may be 4 as any pointer is 4 bytes long (correct me if I'm wrong). -
dipen30compile this code and run it.
It gives the output 2.
can anyone explain how the output is 2? char contain 1 byte. -
rengaraj
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?
How you say the output is 6 ? can you please explain.
R.Rengaraj -
gaurav.bhorkar
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.
Which compiler you used? -
sarveshgupta
Actually i counted the characters in the stringrengarajSir,
How you say the output is 6 ? can you please explain.
R.Rengaraj
As we are calculating the length of the string so i counted the length of the string
but if we see for a normal char we know that in java char occupies 2 bytes
so if it has to consider char the output should be 2
Am I right? -
dipen30I am using 16-bit compiler. so it gives output 2?
-
Saandeep Sreerambatladipen30I am using 16-bit compiler. so it gives output 2?
Yes the pointer is 2 bytes irrespective of the type it is pointing to.
Depends on the compiler though.
Yes Gaurav said 16 bit gives 2 bytes.
32 bit gives 4 bytes. -
gaurav.bhorkar
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?
@sarveshgupta: Remember, it is not a character string, its a pointer to a character string. -
sarveshguptaOk gaurav.. thanks
-
dipen30thanx gaurav & E-S
-
rengarajSir,
Have anybody tested on the compiler ???
I hope the solution will be 6.
R.Rengaraj -
aishwarya mk
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.
because char data type 1 byte for * and another byte for s(address of array)
You are reading an archived discussion.
Related Posts
Hello Everyone,
I just wanted to introduce myself.
My name is Bill and I'm from the Northeast US.
I'm currently studying civil engineering and I work with a firm that...
i found a video in utube on an episode of planet mechanics where these people use wind power to run a moped, the episode was really interesting.
compressed air cylinder...
i'm an ECE 6th sem stdnt.....i want to know how is it possible to interface PC to LED/LCD in order to form a graphic display...
Twitter co-founder Jack Dorsey announced his new company on Tuesday in appropriate fashion: with a tweet on the network he created in 2006. His new company, Square, allows merchants and...
The draw says it will be South Africa playing hosts to the FIFA world cup next year
The 32 teams participating at next year's FIFA World Cup™ finals discovered their...