DO NOT DEAL WITH THIS MEMBER
a.out returns something else everytime.
PHP Code
<?php int main(int argc, char *argv[]) { std::cout << (int)argv[2] + (int)argv[3] << std::endl; }
(Dec 12, 2018 11:57 AM)F.A.S.T Wrote: a.out returns something else everytime.
PHP Code
<?php int main(int argc, char *argv[]) { std::cout << (int)argv[2] + (int)argv[3] << std::endl; }
You are just casting random pointers to int. Nothing special and not worth making a thread about it.
using namespace std;
^ use this more often
!
(Dec 12, 2018 12:16 PM)wit Wrote: using namespace std;
^ use this more often
Dont use that more often. Its a bad practice. Its fine for smaller projects but keep in mind that the std namespace has tons of identifiers, many of which are very common ones (think list, sort, string, iterator, etc.) which are very likely to appear in other code, too.
(Dec 12, 2018 12:34 PM)RascalPascal Wrote: Dont use that more often. Its a bad practice. Its fine for smaller projects but keep in mind that the std namespace has tons of identifiers, many of which are very common ones (think list, sort, string, iterator, etc.) which are very likely to appear in other code, too.
The OP's code looks like something from a school assignment, in that case std is fine to use 99% of the time.
!
I tried this just now.
PHP Code
<?php #include <stdio.h> #include <stdlib.h>
int main() { short i = 10; while (i) { void *ptr = (int *)malloc(1); printf("%p:%d\n", ptr, ptr); free (ptr); --i; } return 0; }
Output:
Code 00000000002F7470:3110000
00000000003C76C0:3962560
00000000003C76C0:3962560
00000000003C76C0:3962560
00000000003C76C0:3962560
00000000003C76C0:3962560
00000000003C76C0:3962560
00000000003C76C0:3962560
00000000003C76C0:3962560
00000000003C76C0:3962560
Ahh yes, there is a VIRTUAL MEMORY !!
That's just ASLR in action.
DO NOT DEAL WITH THIS MEMBER
(Dec 12, 2018 12:42 PM)wit Wrote: The OP's code looks like something from a school assignment, in that case std is fine to use 99% of the time.
No it's just experiments. NO School assignment.
Anyway, I just wanted to know why that was happening. Thanks alot people.
(Dec 15, 2018 08:35 AM)F.A.S.T Wrote: No it's just experiments. NO School assignment.
Anyway, I just wanted to know why that was happening. Thanks alot people.
Your welcome dude.
(Dec 12, 2018 12:42 PM)wit Wrote: The OP's code looks like something from a school assignment, in that case std is fine to use 99% of the time.
Still, better to avoid bad practice for future sake than ignore what might be ahead and do it anyway. Maybe that philosophy is a bit much for simple stuff such as a statement for namespace usage, but it can tie in with anything and does with everything lol.
It actually makes me feel a bit better because I can see I'm not the only one specifying separate namespaces even on small tinkering projects like this.
|