Hi, i just want to make sure, Is this correct?
Code:int f1(char *a) { return f2(&a); } int f2(char *a) { *a++; return 1: } or should be; int f1(char *a) { return f2(*a); }
Thank you!!
Hi, i just want to make sure, Is this correct?
Code:int f1(char *a) { return f2(&a); } int f2(char *a) { *a++; return 1: } or should be; int f1(char *a) { return f2(*a); }
Thank you!!
Think: in f1, a is a char*. Therefore, &a is a char**, and *a is a char. For f2, the parameter a is a char*. Therefore, what should you pass to f2 from f1?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Well did you try them both with a compiler (which would have taken mere seconds)
Both are wrong by the way.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Hmmm .. thats true.. so i would just have to make like this?Yea thats makes sense...
I tryed to make that like here:Code:int f1(char *a) { return f2(a); }
But the output is 100.. whats wrong?Code:#include <stdlib.h> #include <stdio.h> int f2(char *a); int f1(char *a); int main() { char a; int b; a = 100; b = f1(&a); printf("%u \n", a); system("PAUSE"); } int f1(char *a) { return f2(a); } int f2(char *a) { *a++; return 1; }
i did try with a++ but with the same output...
Thank you!
Try with (*a)++
It´s a precedence thing.
Also, if you´re using gcc, then use "-W -Wall" as command line options.
IIRC, it would complain that your *a++ was a "unused" side effect.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Thank you!! It worked You helped a lot!! Actually, it did not complain haha. But thank you.
And laserlight made everything more clear to me!!
Cya
-pedantic -O2
Optimisation implies data flow analysis, which might be needed for more advanced unused detection.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Oh, ok i will make use of that!! Thank you!