Re: tryick use of sizeof again[Explaination Wanted]



goacross@xxxxxxxxx writes:
char ch='a';

int v=sizeof ++ch;

cout<<ch<<endl;// output: 'a'

why not 'b'?

If you're going to post code here, please make sure it's C, not C++.
It's also helpful to post a (small) complete program rather than an
isolated snippet.

'cout', '<<', and 'endl' are specific to C++.

Your underlying question happens, in this particular case, to be
equally valid in both languages, but there are subtle differences
between C and C++ that even the C experts here may not be aware of.

Just this once, I'll show you a C version of your program.

#include <stdio.h>
int main(void)
{
char ch = 'a';
int v = sizeof ++ch;
printf("%c\n", ch);
return 0;
}

Next time, please either post C in the first place, or post to
comp.lang.c++. If you're having trouble knowing the difference, you
need to learn one language or the other (perhaps eventually both).
A newsgroup is not a good place to do that, but
alt.comp.lang.learn.c-c++ might be more appropriate for your purposes
than comp.lang.c.

Several people have already given you the answer to your question --
which is unfortunate, since the question looks very much like
homework. An expression like 'sizeof ++ch' isn't something that you'd
write if your goal is to accomplish something. It was almost
certainly written by someone trying to make a specific point.

If you want us to do your homework for you, please post your
instructor's e-mail address so we can submit our solutions directly.
We're willing to provide hints if you've done some of the work
yourself and you're stuck on something, but we won't (usually) do it
for you.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.



Relevant Pages

  • Re: tryick use of sizeof again[Explaination Wanted]
    ... isolated snippet. ... equally valid in both languages, but there are subtle differences ... If you want us to do your homework for you, ...
    (comp.lang.c)
  • Re: "Friendly Premises"
    ... positions and debate it again. ... > Obviously, in my case, training involved PCVL but not ... > subtle differences were between "subroutine languages" ...
    (sci.logic)
  • Re: "Friendly Premises"
    ... Obviously, in my case, training involved PCVL but not ... subtle differences were between "subroutine languages" ... explaining them in common language. ...
    (sci.logic)
  • Re: A question about two formal languages
    ... You have the right to thinks so, but in fact it is not a homework, ... > What properties distinguish regular languages from context-free ... I tried to use the pumping lemma but didn't get a contradiction, ...
    (comp.theory)
  • Re: srand
    ... your question just looks like homework. ... Since srand is a void function, ... You mean other languages are peculiar because they ...
    (comp.lang.c)