[Courses] Re: [C] Beginner's Lesson 12: another answer to Exercise 1 (Simple Pointers)

Lorne Gutz lgutz at vistar.ca
Wed Nov 27 09:58:29 EST 2002


Your correct K
Lets do it that way.

Cut and pasted you simple pointer program into an
editor and did:
 gcc -Wall simple.c
It compled without a single warning.   That's good.
Then ran it,.....I was impressed with the amount or
work you put into this.

Lorne

On Tuesday 26 November 2002 23:33, KWMelvin wrote:
> On Tue, Nov 26, 2002 at 01:22:13PM -0500, Lorne Gutz wrote:
> > With *(PR +1)  the pointer PR will be incremented 1st  and then used
> > as a pointer into the array.
> > with *PR++  1st the pointer is used to get the element and then
> > incremented. cheers
> > Lorne
>
> Hello Lorne,
>
> I really really appreciate the help, however, it would be GREAT if
> we could have these chats sent to the list.  If I make a mistake,
> and you correct me, it is best sent to the list.  My mistakes need
> to be aired in public.  My questions and replies to your posts need
> to go to the list.  Thank-you notes, etc, don't have to go to the list.
> If you'll go back in the archives, you'll see that I came here to
> TAKE a course, not to teach one. I'm just about one page ahead of
> the other [C] Beginners, and a few pages behind some of the others.
>
> I NEED the HELP! However, I'm not after personalized help. I figure
> that if *I* need help, then at least 10 other people (who are lurking)
> need help as well. The CHALLENGE to you, as an experienced C programmer,
> is to make your reply as educational as possible, to all the mistakes
> I'm making ... and posting.  I'm not afraid to make mistakes, and I
> spend a lot of time making them.  That is what the learning process
> is all about: an employer figures that a newbie has already made the
> first 500 mistakes in school!
>
> Anyway, unless my mistake might really, really confuse another beginner,
> please post to the list! Here is a beginning program I've done for
> Self-Help:
>
> /*
> ** 1.c -- Simple pointers 1
> */
> #include <stdio.h>
> int main(void)
> {
>   int varA, varB;
>   int *ptrA, *ptrB;
>
>   printf("\nDeclare varA, varB, *ptrA, and *ptrB as integers:\n");
>   printf("    int varA, varB;\n    int *ptrA, *ptrB;\n");
>   varA = 0;
>   varB = 1;
>
>   printf("\nAssign each variable a value:\n");
>   printf("    varA = 0;\n    varB = 1;\n");
>
>   ptrA = &varA;
>   ptrB = &varB;
>   printf("\nAssign the addresses of the variables to the pointers\n");
>   printf("    ptrA = &varA;\n    ptrB = &varB;\n");
>
>   printf("\nWhat does each variable and pointer hold or point to?\n");
>   printf("    varA has the value %d\n    varB has the value %d\n", varA,
> varB); printf("    *ptrA has the value %d\n    *ptrB has the value %d\n",
> *ptrA, *ptrB); printf("    &varA points to %p\n    &varB points to %p\n",
> (void *) &varA, (void *) &varB); printf("    ptrA points to %p (the address
> of varA)\n", (void *) ptrA); printf("    ptrB points to %p (the address of
> varB)\n", (void *) ptrB);
>
>   printf("\nif (&varA == ptrA && &varB == ptrB) printf(\"TRUE\"); ");
>   if (&varA == ptrA && &varB == ptrB)
>     printf("TRUE\n");
>   printf("if (varA == *ptrA && varB == *ptrB) printf(\"TRUE\"); ");
>   if (varA == *ptrA && varB == *ptrB)
>     printf("TRUE\n");
>
> return 0;
> }





More information about the Courses mailing list