Which pointer arithmetic expressions are valid in C?
- Thread starter Math Is Hard
- Start date
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
41 replies · 8K views
Physics news on Phys.org
Staff Emeritus
Science Advisor
Gold Member
- 4,663
- 36
php tags
I am SO loving this! Yeah - I just went back and indented and it was so EASY!
I am SO loving this! Yeah - I just went back and indented and it was so EASY!
Staff Emeritus
Science Advisor
Gold Member
- 4,663
- 36
chroot said:Math Is Hard,
The assignment seemed to specifically ask for pointer incrementing, like this:
PHP:void copy_ptr(double *ar1,double *ar2,int n) { int i; for(i=0;i<n;i++) *(ar2++) = *(ar1++); }
oops! sorry- I think I got carried away with the formatting fun stuff!
so, I should use ++ for "pointer incrementing"? using + i won't move to the correct position in the array?
Staff Emeritus
Science Advisor
Gold Member
- 10,270
- 45
Math Is Hard,
Remember the three qualities of a good programmer:
1) Laziness. No one should have to do much work, so a good programmer should strive to make the user's life utterly push-button easy.
2) Impatience. No one should ever have to wait for a computer to do anything, so programmers should be careful with their algorithm designs to make sure their users never have to wait for anything.
3) Hubris. Programmers should take excessive pride in their work, and should strive to make every program they write complete, totally functional, and elegant.
The PHP tags are really an example of some programmer on the vBulletin team demonstrating quality number one.
- Warren
Remember the three qualities of a good programmer:
1) Laziness. No one should have to do much work, so a good programmer should strive to make the user's life utterly push-button easy.
2) Impatience. No one should ever have to wait for a computer to do anything, so programmers should be careful with their algorithm designs to make sure their users never have to wait for anything.
3) Hubris. Programmers should take excessive pride in their work, and should strive to make every program they write complete, totally functional, and elegant.
The PHP tags are really an example of some programmer on the vBulletin team demonstrating quality number one.
- Warren
Staff Emeritus
Science Advisor
Gold Member
- 10,270
- 45
Your code using pointer arithmetic (the + signs) will certainly work, but it might not be the best way to meet the specification. The specification said to use pointer incrementing. Normally, I associate the ++ operator with the word "incrementing," but it may just be a semantic issue.Math Is Hard said:oops! sorry- I think I got carried away with the formatting fun stuff!so, I should use ++ for "pointer incrementing"?
using + i won't move to the correct position in the array?
- Warren
Staff Emeritus
Science Advisor
Gold Member
- 4,663
- 36
Wow - who knew?? I promise to try my best to acquire these ..uh.. virtues!chroot said:Math Is Hard,
Remember the three qualities of a good programmer:
1) Laziness. No one should have to do much work, so a good programmer should strive to make the user's life utterly push-button easy.
2) Impatience. No one should ever have to wait for a computer to do anything, so programmers should be careful with their algorithm designs to make sure their users never have to wait for anything.
3) Hubris. Programmers should take excessive pride in their work, and should strive to make every program they write complete, totally functional, and elegant.
Staff Emeritus
Science Advisor
Gold Member
- 4,663
- 36
chroot said:Normally, I associate the ++ operator with the word "incrementing," but it may just be a semantic issue.
That's good enough for me. I'll take your advice on that and use ++ in my final version.
Staff Emeritus
Science Advisor
Gold Member
- 4,663
- 36
Thanks, again!
faust9
- 690
- 2
chroot said:Math Is Hard,
Remember the three qualities of a good programmer:
1) Laziness. No one should have to do much work, so a good programmer should strive to make the user's life utterly push-button easy.
2) Impatience. No one should ever have to wait for a computer to do anything, so programmers should be careful with their algorithm designs to make sure their users never have to wait for anything.
3) Hubris. Programmers should take excessive pride in their work, and should strive to make every program they write complete, totally functional, and elegant.
The PHP tags are really an example of some programmer on the vBulletin team demonstrating quality number one.
- Warren
You forgot 4)
4) Once you land a job as a programmer learn to obfuscate as much as possible so that you are the only programmer able to maintain certain chuncks of code thus ensuring job security.
Staff Emeritus
Science Advisor
Gold Member
- 4,663
- 36
faust9 said:You forgot 4)
4) Once you land a job as a programmer learn to obfuscate as much as possible so that you are the only programmer able to maintain certain chuncks of code thus ensuring job security.
OMG! I had a job once where ALL the programmers lived religiously by that guideline. Not even the tiniest cryptic comment was ever written. My job? To go around to the programmers and produce documentation on what they were coding. Since they all refused to document or comment my boss thought I should be the one to do it. He wanted to farm out some of the work overseas so he wanted to create a guidebook for these contracted developers who would write new modules of the app.
It was horrible. The programmers were really protective and defensive about showing anyone their code or explaining to anyone what it did.
And what a mess. By the time I came to work their the application was three fourths done and there was no formal spec - just shoe boxes full of meeting notes and emails from the client.
- 7,521
- 3,048
For more qualities, consult this enlightening article on good
programming techniques:
How To Write Unmaintainable Code
How To Write Unmaintainable Code
Staff Emeritus
Science Advisor
Gold Member
- 4,663
- 36
robphy said:For more qualities, consult this enlightening article on goodprogramming techniques:
How To Write Unmaintainable Code
LOL! That's hilarious!
I love the quotes at the beginning of each section, especially thie one:
Quidquid latine dictum sit, altum sonatur.
Whatever is said in Latin sounds profound.
Similar threads
Pointer arithmetic and array modification in C
- MorrowUoN
- · Replies 11 ·
- Engineering and Comp Sci Homework Help
- Replies
- 11
Can you skip nodes in a singly linked list using pointer arithmetic?
- AcecA
- · Replies 2 ·
- Programming and Computer Science
- Replies
- 2
Java Transforming Infix to Postfix in Java: Solving Arithmetic Expressions with RPN
- muna580
- · Replies 7 ·
- Programming and Computer Science
- Replies
- 7