Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > What's the position of pointers

Reply
Thread Tools

What's the position of pointers

 
 
CBFalconer
Guest
Posts: n/a
 
      09-12-2008
"Yee.Chuang" wrote:
> Nick Keighley <(E-Mail Removed)> wrote:
>> CBFalconer <(E-Mail Removed)> wrote:
>>> Stephen Sprunk wrote:
>>>> Yee.Chuang wrote:
>>>>
>>>>> When I began to learn C, My teacher told me that pointer is the
>>>>> most difficult part of C, it makes me afraid of it. After
>>>>> finishing C program class, I found that all the code I wrote in
>>>>> C contains little pointers, obviously I avoid using them.
>>>>
>>>> That's pretty much what happened with me; I came from a Pascal
>>>> background where I had used pointers once or twice in several
>>>> years, and before that BASIC, which didn't even have the concept
>>>> at all.
>>>
>>> Then you weren't using Pascal thoroughly. The prime uses of
>>> pointers are very similar between Pascal and C, but Pascal doesn't
>>> allow the loose generic conversion of VAR parameters to pointers,
>>> and similar things for arrays, etc. This allows Pascal to check
>>> for most common errors, unlike C.

>>
>> yes I moved from pascal to C and didn't find pointers a problem.
>> They seemed very like pascal pointers. Though I thought the sysntax
>> was *very* strange!
>>
>> On the other hand I'd programmed in Coral, Assmebler and had
>> brief exposure to BCPL. So pointers seemed quite normal!

>
> Something I forgot to tell: C is the first language I've learned,
> after that I understand the basic skills of programming. Most of the
> time I just use software like SAS, Matlab and R to solve problems.
> Yes, I don't write any software, I just use them.
> If learning pointers can help me with programing thoughts or improve
> my program skills, I'm glad to do so.


If C pointers are bothering you, you might consider first learning
Pascal and handling pointers therein. Then returning to C would
mean abandoning the safety and adding new capabilities.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
 
Reply With Quote
 
 
 
 
Richard
Guest
Posts: n/a
 
      09-12-2008
CBFalconer <(E-Mail Removed)> writes:

> "Yee.Chuang" wrote:
>> Nick Keighley <(E-Mail Removed)> wrote:
>>> CBFalconer <(E-Mail Removed)> wrote:
>>>> Stephen Sprunk wrote:
>>>>> Yee.Chuang wrote:
>>>>>
>>>>>> When I began to learn C, My teacher told me that pointer is the
>>>>>> most difficult part of C, it makes me afraid of it. After
>>>>>> finishing C program class, I found that all the code I wrote in
>>>>>> C contains little pointers, obviously I avoid using them.
>>>>>
>>>>> That's pretty much what happened with me; I came from a Pascal
>>>>> background where I had used pointers once or twice in several
>>>>> years, and before that BASIC, which didn't even have the concept
>>>>> at all.
>>>>
>>>> Then you weren't using Pascal thoroughly. The prime uses of
>>>> pointers are very similar between Pascal and C, but Pascal doesn't
>>>> allow the loose generic conversion of VAR parameters to pointers,
>>>> and similar things for arrays, etc. This allows Pascal to check
>>>> for most common errors, unlike C.
>>>
>>> yes I moved from pascal to C and didn't find pointers a problem.
>>> They seemed very like pascal pointers. Though I thought the sysntax
>>> was *very* strange!
>>>
>>> On the other hand I'd programmed in Coral, Assmebler and had
>>> brief exposure to BCPL. So pointers seemed quite normal!

>>
>> Something I forgot to tell: C is the first language I've learned,
>> after that I understand the basic skills of programming. Most of the
>> time I just use software like SAS, Matlab and R to solve problems.
>> Yes, I don't write any software, I just use them.
>> If learning pointers can help me with programing thoughts or improve
>> my program skills, I'm glad to do so.

>
> If C pointers are bothering you, you might consider first learning
> Pascal and handling pointers therein. Then returning to C would
> mean abandoning the safety and adding new capabilities.


That is atrocious advice. And would certainly lead to expectations not
met by C.

Anyway outside of c.l.c pointers are easily taught. They are an address
where some data is. You can de-reference that address to get the data
there. You can advance the pointer to point to different addresses.

Trivial stuff when you do not try to be too clever and blind the poor
nOOB with ridiculous nonsense not applicable to their system at too
early a stage.
 
Reply With Quote
 
 
 
 
Yee.Chuang
Guest
Posts: n/a
 
      09-13-2008
On Sep 12, 11:45*pm, Richard<(E-Mail Removed)> wrote:
> CBFalconer <(E-Mail Removed)> writes:
> > "Yee.Chuang" wrote:
> >> Nick Keighley <(E-Mail Removed)> wrote:
> >>> CBFalconer <(E-Mail Removed)> wrote:
> >>>> Stephen Sprunk wrote:
> >>>>> Yee.Chuang wrote:

>
> >>>>>> When I began to learn C, My teacher told me that pointer is the
> >>>>>> most difficult part of C, it makes me afraid of it. *After
> >>>>>> finishing C program class, I found that all the code I wrote in
> >>>>>> C contains little pointers, obviously I avoid using them.

>
> >>>>> That's pretty much what happened with me; I came from a Pascal
> >>>>> background where I had used pointers once or twice in several
> >>>>> years, and before that BASIC, which didn't even have the concept
> >>>>> at all.

>
> >>>> Then you weren't using Pascal thoroughly. *The prime uses of
> >>>> pointers are very similar between Pascal and C, but Pascal doesn't
> >>>> allow the loose generic conversion of VAR parameters to pointers,
> >>>> and similar things for arrays, etc. *This allows Pascal to check
> >>>> for most common errors, unlike C.

>
> >>> yes I moved from pascal to C and didn't find pointers a problem.
> >>> They seemed very like pascal pointers. Though I thought the sysntax
> >>> was *very* strange!

>
> >>> On the other hand I'd programmed in Coral, Assmebler and had
> >>> brief exposure to BCPL. So pointers seemed quite normal!

>
> >> Something I forgot to tell: C is the first language I've learned,
> >> after that I understand the basic skills of programming. Most of the
> >> time I just use software like SAS, Matlab and R to solve problems.
> >> Yes, I don't write any software, I just use them.
> >> If learning pointers can help me with programing thoughts or improve
> >> my program skills, I'm glad to do so.

>
> > If C pointers are bothering you, you might consider first learning
> > Pascal and handling pointers therein. *Then returning to C would
> > mean abandoning the safety and adding new capabilities.

>
> That is atrocious advice. And would certainly lead to expectations not
> met by C.
>
> Anyway outside of c.l.c pointers are easily taught. They are an address
> where some data is. You can de-reference that address to get the data
> there. You can advance the pointer to point to different addresses.
>
> Trivial stuff when you do not try to be too clever and blind the poor
> nOOB with ridiculous nonsense not applicable to their system at too
> early a stage.


Hey, Richard, it's not so serious about that so called "atrocious
advice". I came here for your advise. Thanks for all of your
instructions, now I know more about points than I used to do, that's
great and fun.
There was no malice in their discussions.
 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      09-13-2008
"Yee.Chuang" <(E-Mail Removed)> writes:

> On Sep 12, 11:45*pm, Richard<(E-Mail Removed)> wrote:
>> CBFalconer <(E-Mail Removed)> writes:
>> > "Yee.Chuang" wrote:
>> >> Nick Keighley <(E-Mail Removed)> wrote:
>> >>> CBFalconer <(E-Mail Removed)> wrote:
>> >>>> Stephen Sprunk wrote:
>> >>>>> Yee.Chuang wrote:

>>
>> >>>>>> When I began to learn C, My teacher told me that pointer is the
>> >>>>>> most difficult part of C, it makes me afraid of it. *After
>> >>>>>> finishing C program class, I found that all the code I wrote in
>> >>>>>> C contains little pointers, obviously I avoid using them.

>>
>> >>>>> That's pretty much what happened with me; I came from a Pascal
>> >>>>> background where I had used pointers once or twice in several
>> >>>>> years, and before that BASIC, which didn't even have the concept
>> >>>>> at all.

>>
>> >>>> Then you weren't using Pascal thoroughly. *The prime uses of
>> >>>> pointers are very similar between Pascal and C, but Pascal doesn't
>> >>>> allow the loose generic conversion of VAR parameters to pointers,
>> >>>> and similar things for arrays, etc. *This allows Pascal to check
>> >>>> for most common errors, unlike C.

>>
>> >>> yes I moved from pascal to C and didn't find pointers a problem.
>> >>> They seemed very like pascal pointers. Though I thought the sysntax
>> >>> was *very* strange!

>>
>> >>> On the other hand I'd programmed in Coral, Assmebler and had
>> >>> brief exposure to BCPL. So pointers seemed quite normal!

>>
>> >> Something I forgot to tell: C is the first language I've learned,
>> >> after that I understand the basic skills of programming. Most of the
>> >> time I just use software like SAS, Matlab and R to solve problems.
>> >> Yes, I don't write any software, I just use them.
>> >> If learning pointers can help me with programing thoughts or improve
>> >> my program skills, I'm glad to do so.

>>
>> > If C pointers are bothering you, you might consider first learning
>> > Pascal and handling pointers therein. *Then returning to C would
>> > mean abandoning the safety and adding new capabilities.

>>
>> That is atrocious advice. And would certainly lead to expectations not
>> met by C.
>>
>> Anyway outside of c.l.c pointers are easily taught. They are an address
>> where some data is. You can de-reference that address to get the data
>> there. You can advance the pointer to point to different addresses.
>>
>> Trivial stuff when you do not try to be too clever and blind the poor
>> nOOB with ridiculous nonsense not applicable to their system at too
>> early a stage.

>
> Hey, Richard, it's not so serious about that so called "atrocious
> advice". I came here for your advise. Thanks for all of your
> instructions, now I know more about points than I used to do, that's
> great and fun.
> There was no malice in their discussions.


I realise there was no malice. But it was a silly idea to tell someone
to learn an entire different language to teach what is, after all, a
relatively simple concept when approached in the correct
manner. Especially an effectively dead language such as Pascal which
Falconer seems to love.
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      09-13-2008
Richard wrote:
> CBFalconer <(E-Mail Removed)> writes:
>

.... snip ...
>
>> If C pointers are bothering you, you might consider first learning
>> Pascal and handling pointers therein. Then returning to C would
>> mean abandoning the safety and adding new capabilities.

>
> That is atrocious advice. And would certainly lead to expectations
> not met by C.


Except that it duplicates my experience of long long ago, and I
have no problems with C pointers.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      09-13-2008
CBFalconer <(E-Mail Removed)> writes:

> Richard wrote:
>> CBFalconer <(E-Mail Removed)> writes:
>>

> ... snip ...
>>
>>> If C pointers are bothering you, you might consider first learning
>>> Pascal and handling pointers therein. Then returning to C would
>>> mean abandoning the safety and adding new capabilities.

>>
>> That is atrocious advice. And would certainly lead to expectations
>> not met by C.

>
> Except that it duplicates my experience of long long ago, and I
> have no problems with C pointers.


Of long long ago.

I have experience of new C programmers and have never, ever had a
problem explaining them pointers and de referencing pointers. I tend to
use a debugger a block of memory. Easy.

They do not need to learn a dead language like Pascal to understand
pointers.

 
Reply With Quote
 
Chad
Guest
Posts: n/a
 
      09-13-2008
On Sep 11, 5:02 am, "Yee.Chuang" <(E-Mail Removed)> wrote:
> When I began to learn C, My teacher told me that pointer is the most
> difficult part of C, it makes me afraid of it. After finishing C
> program class, I found that all the code I wrote in C contains little
> pointers, obviously I avoid using them.
> A few days ago when I was reading a book about programming, I was told
> that pointers are the very essence of C language, if I couldn't use it
> well, I'm a bad programmer, it's a big shock.
> So now I'm wondering: what's the exact position of pointers in C? Is
> it really necessary to learn how it works again?



I personally had more issues with the math end of C than pointers
themselves. Yes, I had real issues with the concepts of logical
conjunction, disjunction, implication, and NAND. De Morgans law also
bit me. With that, I'm just going back to being a silent bystander on
this forum.
 
Reply With Quote
 
sh.vipin@gmail.com
Guest
Posts: n/a
 
      09-13-2008

> So now I'm wondering: what's the exact position of pointers in C? Is
> it really necessary to learn how it works again?


Try to solve the following problem based on your current knowledge.
If you are able to solve it without using the pointers, you don't need
to learn.

/* Puzzle code*/

void X(?????){
???????
}

int main(int cnt, char *aa[]){
int a;
a = 5;
X(??????); //line # 5
printf("\n Value of a is %d",a);
retrun 0;

}

---------------Desired OUTPUT -----------
Value of a is 20

Problem Statement
-----------------------
In the above code, at all the places where you see "?????" you have to
write some C Code.
you have to write the code such that without modifying the variable
"a" in main, value of "a" becomes 20. That is the output of program
when run is as shown in desired output.


Once you finish this, you will realize that there are many cases/
problems which cann;t be solved without using the pointers.
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      09-13-2008
Richard<(E-Mail Removed)> writes:
[...]
> Anyway outside of c.l.c pointers are easily taught. They are an address
> where some data is. You can de-reference that address to get the data
> there. You can advance the pointer to point to different addresses.
>
> Trivial stuff when you do not try to be too clever and blind the poor
> nOOB with ridiculous nonsense not applicable to their system at too
> early a stage.


Treating pointers simply as machine addresses can easily lead to the
assumption of a single linear address space. That's a common
implementation, but it's not required. For example, as far as C is
concerned, pointers to two independently declared objects have no
defined relationship to each other (other than inequality), and even
computing ``&x < &y'' invokes undefined behavior.

A C pointer is a more abstract concept than you're implying, defined
in such a way that a machine address pointing somewhere in monolithic
linear memory is one way, but not the only way, to implement them.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      09-13-2008
(E-Mail Removed) writes:
>> So now I'm wondering: what's the exact position of pointers in C? Is
>> it really necessary to learn how it works again?

>
> Try to solve the following problem based on your current knowledge.
> If you are able to solve it without using the pointers, you don't need
> to learn.
>
> /* Puzzle code*/
>
> void X(?????){
> ???????
> }
>
> int main(int cnt, char *aa[]){


main's two parameters can legally be given any name you like, but
they're traditionally called argc and argv. Calling them anything
else is obfuscation. And since you don't use them, you can omit them,
declaring main as "int main(void)".

> int a;
> a = 5;


Ok, but why not use an initializer? "int a = 5;".

> X(??????); //line # 5


Um that's not line 5, unless the definition of X is in a separate
source file.

> printf("\n Value of a is %d",a);


You have a call to printf. Where's the required #include <stdio.h>?

I don't know where this bizarre habit of putting the "\n" at the
beginning of a line rather than at the end came from. This prints an
unnecessary blank line, and fails to properly terminate the output
line. Some implementations may require a terminating "\n" for valid
output.

printf("Value of a is %d\n", a);

> retrun 0;


It's spelled "return". Sure, it's a minor error, but one that you
couldn't have made if you'd bothered to compile your code before
posting it. (Some of my own dumbest mistakes here have been the
result of assuming I could just write code off the top of my head
without bothering to compile it.)

> }
>
> ---------------Desired OUTPUT -----------
> Value of a is 20
>
> Problem Statement
> -----------------------
> In the above code, at all the places where you see "?????" you have to
> write some C Code.
> you have to write the code such that without modifying the variable
> "a" in main, value of "a" becomes 20. That is the output of program
> when run is as shown in desired output.


It's not possible for the value of a to become 20 unless you modify
it. You mean that the code shouldn't *directly* modify a.

> Once you finish this, you will realize that there are many cases/
> problems which cann;t be solved without using the pointers.


It's probably better just to read about pointers in some good tutorial
or reference work, such as K&R2.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pointers, pointers, pointers... cerr C Programming 12 04-07-2011 11:17 PM
detecting mouse click position in canvas tag has position off James Black Javascript 0 05-28-2006 03:27 AM
Where is Form Relative Position and Absolute Position in VS.Net 2005 ? Luqman ASP .Net 1 02-07-2006 10:27 AM
position image based on document position edouard.lauer@pt.lu Javascript 3 01-14-2006 06:04 PM
How to set position of a web control depending on other control's position at run-time? James Wong ASP .Net Web Controls 4 07-14-2004 10:24 AM



Advertisments