Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: return in c...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 43057 of 47561
Post > Topic >>

Re: return in conditon - why not?

by Tristan Wibberley <maihem-nn1@[EMAIL PROTECTED] > Feb 2, 2008 at 06:09 PM

On Fri, 2008-02-01 at 16:26 -0800, exander77@[EMAIL PROTECTED]
 wrote:
> I am quite new to c++, about half of a year.
> I juct wonder, why such code is not possible:
> 
> int chlen(char * ar) {
>   for(int i=0;ar[i]||return i;i++);
> }

because it is totally unreadable?

> In my opinion, it would be much "cuter" than this:
> 
> int chlen(char * ar) {
>     int i;
>     for(i=0;ar[i];i++);
>     return i;
> }

Why not:

int chlen(char * ar)
{
    char *arc = ar;
    while (*arc) ++arc;
    return arc - ar;
}

-- 
Tristan Wibberley

Any opinion expressed is mine (or else I'm playing devils advocate for
the sake of a good argument). My employer had nothing to do with this
communication.
 




 1 Posts in Topic:
Re: return in conditon - why not?
Tristan Wibberley <mai  2008-02-02 18:09:22 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Sep 7 3:29:41 CDT 2008.