function will not return bool variable as true

Pages: 12
What did you expect to happen?
point is not part of an array, so dereferencing the pointer after you increment it results in undefined behavior.
ah yeah!! i forgot! this code is actually written before i post my question. in my thought earlier, i thought that *p++ will show the value of point, before increase the value by 1. and my curiosity still "stuck" when my post answered so i'm still feel like that that is not the correct answer my bad :)
btw, is it legal that the "while" in my code it should be have a brace, but it doesn't
There's no need for braces if the body consists of a single statement.
but it should be more than 1 line:
 
while (first != last) if (*first++ == val) ++res;

it should be written like:
1
2
3
while (first != last)
	if (*first++ == val)
		++res;


so it has to be:
1
2
3
4
while (first != last) {
	if (*first++ == val)
		++res;
}


right?
hello?
C++ doesn't care about whitespace (and that includes newlines), so you still don't need braces.

You can write this line as:
1
2
3
4
5
6
7
8
9
10
11
while                       (
  first
!=                                              last                            )
	  if (
*
first                       ++==               val)

++

       res       
                                         ;


and the compiler won't care a bit. Try it!
i mean like this:

 
while (first != last) if (*first++ == val) ++res;


it should be written like:

1
2
3
while (first != last)
	if (*first++ == val) //the first line, ok no braces...
		++res; //this is another line, connected to the first "if" 


am i right? if i'm right then it should be like this:
1
2
3
4
while (first != last) { //using braces to combine the two statement...
	if (*first++ == val)
		++res;
}
so, do you mean because:
1
2
if (...)
statement


is considered as 1 line so:

 
while (first != last) if (*first++ == val) ++res;


is considered as a "while" with 1 line?
hmm... i consider my answer as "yes"?
Yes, that's right. Though like a previous poster mentioned, 'lines' is a misnomer. It's really 'statements'. That first snippet with the if() is only one statement, so braces are unneeded.
Topic archived. No new replies allowed.
Pages: 12