C programming: working with pointers

Click For Summary

Homework Help Overview

The discussion revolves around understanding pointers in C programming, specifically the validity of various pointer expressions involving integer pointers and integer variables. Participants are exploring the nuances of pointer arithmetic and memory addressing.

Discussion Character

  • Exploratory, Conceptual clarification, Mathematical reasoning, Assumption checking

Approaches and Questions Raised

  • Participants are analyzing specific expressions involving pointer arithmetic, questioning the validity of adding pointers and the implications of incrementing pointers. There is also discussion about the understanding of pointers as variables that hold memory addresses.

Discussion Status

Some participants have provided clarifications and examples to illustrate their points, while others are seeking further understanding of pointer behavior in C. There is an ongoing exploration of concepts without a clear consensus on all aspects discussed.

Contextual Notes

Participants are addressing potential misconceptions about pointers and their operations, including the implications of pointer addition and subtraction. There is an emphasis on understanding the size of data types and how it affects pointer arithmetic.

  • #31
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++);
}
 
Physics news on Phys.org
  • #32
php tags

I am SO loving this! Yeah - I just went back and indented and it was so EASY!
 
  • #33
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! :redface: so, I should use ++ for "pointer incrementing"?
using + i won't move to the correct position in the array?
 
  • #34
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
 
  • #35
Math Is Hard said:
oops! sorry- I think I got carried away with the formatting fun stuff! :redface: so, I should use ++ for "pointer incrementing"?
using + i won't move to the correct position in the array?
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.

- Warren
 
  • #36
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.
Wow - who knew?? I promise to try my best to acquire these ..uh.. virtues! :biggrin:
 
  • #37
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.
 
  • #38
Thanks, again!
 
  • #39
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.
 
  • #40
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.
 
  • #42
robphy said:
For more qualities, consult this enlightening article on good :-p programming techniques:
How To Write Unmaintainable Code

LOL! That's hilarious! :smile:

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

  • · Replies 17 ·
Replies
17
Views
3K
Replies
12
Views
2K
Replies
7
Views
4K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 19 ·
Replies
19
Views
6K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
86
Views
2K