Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #14360 > unrolled thread

Why C has Pointers.

Started bycurixinfotech <curixinfotech.54dl3z@no-mx.forums.yourdomain.com.au>
First post2011-12-07 07:22 -0500
Last post2011-12-19 02:48 -0800
Articles 20 on this page of 86 — 32 participants

Back to article view | Back to comp.lang.c


Contents

  Why C has Pointers. curixinfotech <curixinfotech.54dl3z@no-mx.forums.yourdomain.com.au> - 2011-12-07 07:22 -0500
    Re: Why C has Pointers. Malcolm McLean <malcolm.mclean5@btinternet.com> - 2011-12-07 04:35 -0800
    Re: Why C has Pointers. Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-12-07 07:58 -0500
      Re: Why C has Pointers. Mike Manilone <zhtx10@gmail.com> - 2011-12-07 13:15 +0000
        Re: Why C has Pointers. Bill Reid <hormelfree@gmail.com> - 2011-12-08 06:29 -0800
    Re: Why C has Pointers. Vincenzo Mercuri <vincenzo.mercuri@hotmail.it> - 2011-12-07 14:50 +0100
      Re: Why C has Pointers. Keith Thompson <kst-u@mib.org> - 2011-12-07 11:01 -0800
        Re: Why C has Pointers. Vincenzo Mercuri <vincenzo.mercuri@yahoo.it> - 2011-12-07 20:49 +0100
        Re: Why C has Pointers. Brian <nospam@nospam.com> - 2011-12-07 20:00 +0000
          Re: Why C has Pointers. James Kuyper <jameskuyper@verizon.net> - 2011-12-07 15:30 -0500
            Re: Why C has Pointers. 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-07 12:43 -0800
              Re: Why C has Pointers. Keith Thompson <kst-u@mib.org> - 2011-12-07 13:09 -0800
            Re: Why C has Pointers. Vincenzo Mercuri <vincenzo.mercuri@hotmail.it> - 2011-12-08 19:39 +0100
              Re: Why C has Pointers. James Kuyper <jameskuyper@verizon.net> - 2011-12-08 14:16 -0500
                Re: Why C has Pointers. Vincenzo Mercuri <vincenzo.mercuri@hotmail.it> - 2011-12-08 20:23 +0100
      Re: Why C has Pointers. Kaz Kylheku <kaz@kylheku.com> - 2011-12-07 20:48 +0000
        Re: Why C has Pointers. Vincenzo Mercuri <vincenzo.mercuri@yahoo.it> - 2011-12-07 22:07 +0100
        Re: Why C has Pointers. Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-12-10 07:34 +0000
    Re: Why C has Pointers. August Karlstrom <fusionfile@gmail.com> - 2011-12-07 16:16 +0100
    Re: Why C has Pointers. Borax Man <rotflol2@hotmail.com> - 2011-12-08 18:32 +1100
      Re: Why C has Pointers. Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-12-08 00:20 -0800
        Re: Why C has Pointers. André Gillibert <MetaEntropy.removeThis@gmail.com> - 2011-12-08 13:44 +0100
          Re: Why C has Pointers. Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-12-09 05:04 -0800
            Re: Why C has Pointers. gazelle@shell.xmission.com (Kenny McCormack) - 2011-12-09 14:59 +0000
              Re: Why C has Pointers. Malcolm McLean <malcolm.mclean5@btinternet.com> - 2011-12-09 20:19 -0800
              Re: Why C has Pointers. Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-12-10 07:36 -0800
    Re: Why C has Pointers. Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-12-08 00:12 -0800
    Re: Why C has Pointers. Cong Wang <xiyou.wangcong@gmail.com> - 2011-12-15 07:26 +0000
    Re: Why C has Pointers. 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-17 08:51 -0800
      Re: Why C has Pointers. Barry Schwarz <schwarzb@dqel.com> - 2011-12-17 10:10 -0800
        Re: Why C has Pointers. ralph <nt_consulting64@yahoo.net> - 2011-12-17 14:28 -0600
          Re: Why C has Pointers. ralph <nt_consulting64@yahoo.net> - 2011-12-17 15:00 -0600
          Re: Why C has Pointers. Keith Thompson <kst-u@mib.org> - 2011-12-17 13:55 -0800
            Re: Why C has Pointers. ralph <nt_consulting64@yahoo.net> - 2011-12-17 18:27 -0600
              Re: Why C has Pointers. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-12-18 01:26 +0000
                Re: Why C has Pointers. ralph <nt_consulting64@yahoo.net> - 2011-12-17 22:34 -0600
                  Re: Why C has Pointers. "Philip Lantz" <prl@canterey.us> - 2011-12-17 23:48 -0800
                    Re: Why C has Pointers. superpollo <superpollo@tznvy.pbz> - 2011-12-18 11:06 +0100
                  Re: Why C has Pointers. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-12-18 13:44 +0000
                  Re: Why C has Pointers. pete <pfiland@mindspring.com> - 2011-12-18 11:05 -0500
                  Re: Why C has Pointers. James Kuyper <jameskuyper@verizon.net> - 2011-12-18 11:50 -0500
                  Re: Why C has Pointers. Keith Thompson <kst-u@mib.org> - 2011-12-18 13:10 -0800
                    Re: Why C has Pointers. ralph <nt_consulting64@yahoo.net> - 2011-12-27 16:03 -0600
                      Re: Why C has Pointers. Barry Schwarz <schwarzb@dqel.com> - 2011-12-27 14:40 -0800
                      Re: Why C has Pointers. Keith Thompson <kst-u@mib.org> - 2011-12-27 15:08 -0800
                        Re: Why C has Pointers. ralph <nt_consulting64@yahoo.net> - 2011-12-27 20:09 -0600
                          Re: Why C has Pointers. Keith Thompson <kst-u@mib.org> - 2011-12-27 23:00 -0800
                          Re: Why C has Pointers. Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-12-28 02:53 -0800
                          Re: Why C has Pointers. James Kuyper <jameskuyper@verizon.net> - 2011-12-28 08:39 -0500
                      Re: Why C has Pointers. James Kuyper <jameskuyper@verizon.net> - 2011-12-27 18:14 -0500
                        Re: Why C has Pointers. Keith Thompson <kst-u@mib.org> - 2011-12-27 15:36 -0800
                          Re: Why C has Pointers. James Kuyper <jameskuyper@verizon.net> - 2011-12-27 18:53 -0500
                      Re: Why C has Pointers. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-12-28 13:20 +0000
                  Re: Why C has Pointers. John Bode <jfbode1029@gmail.com> - 2011-12-28 08:42 -0800
                Re: Why C has Pointers. 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-17 20:36 -0800
                  Re: Why C has Pointers. Seebs <usenet-nospam@seebs.net> - 2011-12-18 04:56 +0000
                    Re: Why C has Pointers. 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-17 21:37 -0800
                      Re: Why C has Pointers. Seebs <usenet-nospam@seebs.net> - 2011-12-18 05:42 +0000
                        Re: Why C has Pointers. 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-18 08:08 -0800
                          Re: Why C has Pointers. Robert Wessel <robertwessel2@yahoo.com> - 2011-12-18 10:36 -0600
                          Re: Why C has Pointers. Seebs <usenet-nospam@seebs.net> - 2011-12-18 18:50 +0000
                          Re: Why C has Pointers. Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-12-19 02:39 -0800
                          Re: Why C has Pointers. gordonb.1i27q@burditt.org (Gordon Burditt) - 2011-12-21 22:34 -0600
                        Re: Why C has Pointers. 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-19 07:56 -0800
                          Re: Why C has Pointers. John Tsiombikas <nuclear@member.fsf.org> - 2011-12-19 18:38 +0000
                            Re: Why C has Pointers. 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-19 13:47 -0800
                              Re: Why C has Pointers. Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-12-28 02:58 -0800
                                Re: Why C has Pointers. 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-28 03:21 -0800
              Re: Why C has Pointers. Keith Thompson <kst-u@mib.org> - 2011-12-18 13:07 -0800
                Re: Why C has Pointers. "io_x" <a@b.c.invalid> - 2011-12-19 04:02 +0100
          Re: Why C has Pointers. 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-17 15:35 -0800
            Re: Why C has Pointers. ralph <nt_consulting64@yahoo.net> - 2011-12-17 18:41 -0600
          Re: Why C has Pointers. John Bode <jfbode1029@gmail.com> - 2011-12-19 05:14 -0800
        Re: Why C has Pointers. 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-18 09:50 -0800
        Re: Why C has Pointers. 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-09 15:48 -0800
          Re: Why C has Pointers. Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-01-10 00:21 -0800
            Re: Why C has Pointers. 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-10 01:03 -0800
      Re: Why C has Pointers. Keith Thompson <kst-u@mib.org> - 2011-12-17 11:45 -0800
        Re: Why C has Pointers. 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-17 15:18 -0800
        Re: Why C has Pointers. 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-19 14:10 -0800
          Re: Why C has Pointers. 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-20 10:46 -0800
    Re: Why C has Pointers. "Skybuck Flying" <Windows7IsOK@DreamPC2006.com> - 2011-12-17 19:15 +0100
      Re: Why C has Pointers. "Skybuck Flying" <Windows7IsOK@DreamPC2006.com> - 2011-12-17 19:19 +0100
        Re: Why C has Pointers. Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-12-19 02:48 -0800
    Re: Why C has Pointers. 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-18 11:05 -0800
      Re: Why C has Pointers. Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-12-19 02:48 -0800

Page 1 of 5  [1] 2 3 4 5  Next page →


#14360 — Why C has Pointers.

Fromcurixinfotech <curixinfotech.54dl3z@no-mx.forums.yourdomain.com.au>
Date2011-12-07 07:22 -0500
SubjectWhy C has Pointers.
Message-ID<curixinfotech.54dl3z@no-mx.forums.yourdomain.com.au>
hi
my Q is on the c language tell me now why c has pointers.
parshant


-- 
curixinfotech
------------------------------------------------------------------------
curixinfotech's Profile: http://forums.yourdomain.com.au/member.php?userid=134
View this thread: http://forums.yourdomain.com.au/showthread.php?t=3319

[toc] | [next] | [standalone]


#14361

FromMalcolm McLean <malcolm.mclean5@btinternet.com>
Date2011-12-07 04:35 -0800
Message-ID<d10a3bf2-e915-4bb6-bab6-0b8edd126192@i6g2000vbh.googlegroups.com>
In reply to#14360
On Dec 7, 2:22 pm, curixinfotech <curixinfotech.54d...@no-
mx.forums.yourdomain.com.au> wrote:
> hi
> my Q is on the c language tell me now why c has pointers.
>
Writing to an address is a fundamental assembly-language operation.
The designers of C chose to make this transparent to the programmer.

There are many good reasons for designing a language without pointers.
C is not that language.
--
Malcolm's website
http://www.malcolmmclean.site11.com/www

[toc] | [prev] | [next] | [standalone]


#14362

FromEric Sosman <esosman@ieee-dot-org.invalid>
Date2011-12-07 07:58 -0500
Message-ID<jbnnu9$1fe$1@dont-email.me>
In reply to#14360
On 12/7/2011 7:22 AM, curixinfotech wrote:
>
> my Q is on the c language tell me now why c has pointers.

     To point at things, of course.

     Do you ever use pronouns when you speak or write a natural
language?  That is, do you ever refer to some person or thing
without using a name?  Do you say "Parshant went to Rajiv's
birthday party, and Parshant gave Rajiv a gift along with best
wishes from Parshant's mother," or do you say "*I* went to
*his* birthday party, and *I* gave *him* a gift along with
best wishes from *my* mother"?

     The analogy is far from perfect, but that, in a way, is
what pointers allow you to do: To write code that refers to
objects without using names. This means you can get the code
to do something with variable X, and then use the exact same
code to work with variable Y, and then use it again to work
with variable Z, all by writing the code to use "that variable
over there" and giving it a pointer to X this time, Y the next
time, and Z the time after that.

-- 
Eric Sosman
esosman@ieee-dot-org.invalid

[toc] | [prev] | [next] | [standalone]


#14363

FromMike Manilone <zhtx10@gmail.com>
Date2011-12-07 13:15 +0000
Message-ID<slrnjdupt4.djf.zhtx10@laptop.mike>
In reply to#14362

On 2011-12-07, Eric Sosman <esosman@ieee-dot-org.invalid> wrote:
> On 12/7/2011 7:22 AM, curixinfotech wrote:
>>
>> my Q is on the c language tell me now why c has pointers.
>
>      To point at things, of course.
>
>      Do you ever use pronouns when you speak or write a natural
> language?  That is, do you ever refer to some person or thing
> without using a name?  Do you say "Parshant went to Rajiv's
> birthday party, and Parshant gave Rajiv a gift along with best
> wishes from Parshant's mother," or do you say "*I* went to
> *his* birthday party, and *I* gave *him* a gift along with
> best wishes from *my* mother"?
>
>      The analogy is far from perfect, but that, in a way, is
> what pointers allow you to do: To write code that refers to
> objects without using names. This means you can get the code
> to do something with variable X, and then use the exact same
> code to work with variable Y, and then use it again to work
> with variable Z, all by writing the code to use "that variable
> over there" and giving it a pointer to X this time, Y the next
> time, and Z the time after that.
>

In short, Dennis Ritchie thinks pointers can confuse you!


-- 
Best Regards,
Mike Manilone.

[toc] | [prev] | [next] | [standalone]


#14392

FromBill Reid <hormelfree@gmail.com>
Date2011-12-08 06:29 -0800
Message-ID<d3734376-8c74-4f0d-a37d-b0238fc9892a@f11g2000yql.googlegroups.com>
In reply to#14363
On Dec 7, 5:15 am, Mike Manilone <zht...@gmail.com> wrote:
> > > On 12/7/2011 7:22 AM, curixinfotech wrote:
>
> >> my Q is on the c language tell me now why c has pointers.
>
> In short, Dennis Ritchie thinks pointers can confuse you!
>
EXACTLY!!!

Also, it looks really cool and inscrutable the way you
can increment and dereference pointers, unlike the crystal
clear alternate method of array sub-scripting, which
winds up looking like something written in BASIC, for
cryin' out loud...

Sure, you could make a weak argument that you can
pass pointers around with a little more flexiblity,
but I'm sure the confusing coolness is what decided
the matter!

---
William Ernest Reid

[toc] | [prev] | [next] | [standalone]


#14365

FromVincenzo Mercuri <vincenzo.mercuri@hotmail.it>
Date2011-12-07 14:50 +0100
Message-ID<86ednS4jNcaK8kLTnZ2dnUVZ8mmdnZ2d@giganews.com>
In reply to#14360
Il 07/12/2011 13:22, curixinfotech ha scritto:
> hi
> my Q is on the c language tell me now why c has pointers.
> parshant
>

Hi,

here is a short article that can give you a clue as to why and how:
http://duramecho.com/ComputerInformation/WhyCPointers.html

A similar question has been posted here some time ago, you may find
the answers very interesting. Here is my favourite one:

OP: "Why use pointers at all??"

Richard Heathfield: "No reason at all, if you don't want to.
                     So don't bother, until a need for them arises."

http://bytes.com/topic/c/answers/538974-why-pointers

-- 
Vincenzo Mercuri | www.backbox.org

[toc] | [prev] | [next] | [standalone]


#14367

FromKeith Thompson <kst-u@mib.org>
Date2011-12-07 11:01 -0800
Message-ID<lnk468kxzj.fsf@nuthaus.mib.org>
In reply to#14365
Vincenzo Mercuri <vincenzo.mercuri@hotmail.it> writes:
> Il 07/12/2011 13:22, curixinfotech ha scritto:
>> my Q is on the c language tell me now why c has pointers.
>
> here is a short article that can give you a clue as to why and how:
> http://duramecho.com/ComputerInformation/WhyCPointers.html

Do you know of another article that doesn't falsely claim that arrays
are pointers?

    In C, an array variable is just a pointer to a chunk of memory
    where the elements are stored in order

Arrays *are not* pointers.  See section 6 of the comp.lang.c FAQ
<http://c-faq.com>.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#14368

FromVincenzo Mercuri <vincenzo.mercuri@yahoo.it>
Date2011-12-07 20:49 +0100
Message-ID<Dq6dnWUlVfT6XkLTnZ2dnUVZ8i-dnZ2d@giganews.com>
In reply to#14367
Keith Thompson ha scritto:
> Vincenzo Mercuri<vincenzo.mercuri@hotmail.it>  writes:
>> Il 07/12/2011 13:22, curixinfotech ha scritto:
>>> my Q is on the c language tell me now why c has pointers.
>>
>> here is a short article that can give you a clue as to why and how:
>> http://duramecho.com/ComputerInformation/WhyCPointers.html
>
> Do you know of another article that doesn't falsely claim that arrays
> are pointers?
>
>      In C, an array variable is just a pointer to a chunk of memory
>      where the elements are stored in order
>

Good catch! I must have missed that part.

> Arrays *are not* pointers.  [...]

Of course.

-- 
Vincenzo Mercuri | www.backbox.org

[toc] | [prev] | [next] | [standalone]


#14369

FromBrian <nospam@nospam.com>
Date2011-12-07 20:00 +0000
Message-ID<jbogkk$j20$1@speranza.aioe.org>
In reply to#14367
On Wed, 07 Dec 2011 11:01:04 -0800, Keith Thompson wrote:
> Vincenzo Mercuri <vincenzo.mercuri@hotmail.it> writes:
>> Il 07/12/2011 13:22, curixinfotech ha scritto:
>>> my Q is on the c language tell me now why c has pointers.
>>
>> here is a short article that can give you a clue as to why and how:
>> http://duramecho.com/ComputerInformation/WhyCPointers.html
> 
> Do you know of another article that doesn't falsely claim that arrays
> are pointers?
> 
>     In C, an array variable is just a pointer to a chunk of memory where
>     the elements are stored in order
> 
> Arrays *are not* pointers.  See section 6 of the comp.lang.c FAQ
> <http://c-faq.com>.

You are wrong about that, an array access like a[5] actually translates 
into *(a+5) - pointer operation.

Cheers Brian

[toc] | [prev] | [next] | [standalone]


#14370

FromJames Kuyper <jameskuyper@verizon.net>
Date2011-12-07 15:30 -0500
Message-ID<4EDFCD02.9050309@verizon.net>
In reply to#14369
On 12/07/2011 03:00 PM, Brian wrote:
> On Wed, 07 Dec 2011 11:01:04 -0800, Keith Thompson wrote:
...
>> Arrays *are not* pointers.  See section 6 of the comp.lang.c FAQ
>> <http://c-faq.com>.
> 
> You are wrong about that, an array access like a[5] actually translates 
> into *(a+5) - pointer operation.

Did you bother following that link? Before asserting that arrays are
pointers, try comparing sizeof(a) with sizeof(&a[0]); if they happen to
be equal, double the length of the array, and try it again. Also, please
explain why the following does NOT work:

	int a[10];
	int **p = &a;

[toc] | [prev] | [next] | [standalone]


#14371

From88888 Dihedral <dihedral88888@googlemail.com>
Date2011-12-07 12:43 -0800
Message-ID<12051021.524.1323290629855.JavaMail.geo-discussion-forums@pril5>
In reply to#14370
On Thursday, December 8, 2011 4:30:58 AM UTC+8, James Kuyper wrote:
> On 12/07/2011 03:00 PM, Brian wrote:
> > On Wed, 07 Dec 2011 11:01:04 -0800, Keith Thompson wrote:
> ...
> >> Arrays *are not* pointers.  See section 6 of the comp.lang.c FAQ
> >> <http://c-faq.com>.
> > 
> > You are wrong about that, an array access like a[5] actually translates 
> > into *(a+5) - pointer operation.
> 
> Did you bother following that link? Before asserting that arrays are
> pointers, try comparing sizeof(a) with sizeof(&a[0]); if they happen to
> be equal, double the length of the array, and try it again. Also, please
> explain why the following does NOT work:
> 
> 	int a[10];
> 	int **p = &a;

 How a multi-dimensional array in C is implemented? The pointer stores an
address. What a  void pointer variable stores( just an address) and points to a value type which can be  different in C.

 


[toc] | [prev] | [next] | [standalone]


#14374

FromKeith Thompson <kst-u@mib.org>
Date2011-12-07 13:09 -0800
Message-ID<ln8vmoks1v.fsf@nuthaus.mib.org>
In reply to#14371
88888 Dihedral <dihedral88888@googlemail.com> writes:
> On Thursday, December 8, 2011 4:30:58 AM UTC+8, James Kuyper wrote:
>> On 12/07/2011 03:00 PM, Brian wrote:
>> > On Wed, 07 Dec 2011 11:01:04 -0800, Keith Thompson wrote:
>> ...
>> >> Arrays *are not* pointers.  See section 6 of the comp.lang.c FAQ
>> >> <http://c-faq.com>.
>> > 
>> > You are wrong about that, an array access like a[5] actually translates 
>> > into *(a+5) - pointer operation.
>> 
>> Did you bother following that link? Before asserting that arrays are
>> pointers, try comparing sizeof(a) with sizeof(&a[0]); if they happen to
>> be equal, double the length of the array, and try it again. Also, please
>> explain why the following does NOT work:
>> 
>> 	int a[10];
>> 	int **p = &a;
>
> How a multi-dimensional array in C is implemented?
[...]

A multi-dimensional array is simply an array of arrays.

There are data structure that behave like multidimensional arrays using
arrays of pointers.  For example, you can have an array of double*
elements, where each element points to the first element of an array of
double.  The syntax for accessing an element (a[x][y]) is similar, but
it's not a multidimensional array in the sense that the C standard uses
the term.  Implementations using pointers are much more flexible, but
require more housekeeping work to allocate and deallocate memory.

Section 6 of the comp.lang.c FAQ, <http://c-faq.com>, is an excellent
resource.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#14395

FromVincenzo Mercuri <vincenzo.mercuri@hotmail.it>
Date2011-12-08 19:39 +0100
Message-ID<jPqdnXqPVN3hmXzTnZ2dnUVZ7o2dnZ2d@giganews.com>
In reply to#14370
Il 07/12/2011 21:30, James Kuyper ha scritto:
...
> ... Before asserting that arrays are
> pointers, try comparing sizeof(a) with sizeof(&a[0]); if they happen to
> be equal, double the length of the array, and try it again. ...

Okay:

#include <stdio.h>

int f(int a[])
{
     return sizeof(a) == sizeof(&a[0]);
}

int main(void)
{
     int a[3] = {10, 100, 1000};

     printf("sizeof(a) == sizeof(&a[0]) is");

     if (f(a))
         puts(" true");
     else
         puts(" false");

     return 0;
}

/* just kidding... :) */

-- 
Vincenzo Mercuri | www.backbox.org

[toc] | [prev] | [next] | [standalone]


#14396

FromJames Kuyper <jameskuyper@verizon.net>
Date2011-12-08 14:16 -0500
Message-ID<4EE10D1C.1090608@verizon.net>
In reply to#14395
On 12/08/2011 01:39 PM, Vincenzo Mercuri wrote:
> Il 07/12/2011 21:30, James Kuyper ha scritto:
> ...
>> ... Before asserting that arrays are
>> pointers, try comparing sizeof(a) with sizeof(&a[0]); if they happen to
>> be equal, double the length of the array, and try it again. ...
> 
> Okay:
> 
> #include <stdio.h>
> 
> int f(int a[])
> {
>      return sizeof(a) == sizeof(&a[0]);
> }
...
> /* just kidding... :) */

For Brian's benefit, I'll point out that while, in this context, 'a' IS
a pointer, it's also NOT an array, appearances to the contrary
notwithstanding, so it doesn't provide support for his claims. I suspect
that those "appearances to the contrary" are part of the motivation for
such claims.

[toc] | [prev] | [next] | [standalone]


#14398

FromVincenzo Mercuri <vincenzo.mercuri@hotmail.it>
Date2011-12-08 20:23 +0100
Message-ID<9c-dnT-k_olZk3zTnZ2dnUVZ8g-dnZ2d@giganews.com>
In reply to#14396
Il 08/12/2011 20:16, James Kuyper ha scritto:
> On 12/08/2011 01:39 PM, Vincenzo Mercuri wrote:
>> Il 07/12/2011 21:30, James Kuyper ha scritto:
>> ...
>>> ... Before asserting that arrays are
>>> pointers, try comparing sizeof(a) with sizeof(&a[0]); if they happen to
>>> be equal, double the length of the array, and try it again. ...
>>
>> Okay:
>>
>> #include<stdio.h>
>>
>> int f(int a[])
>> {
>>       return sizeof(a) == sizeof(&a[0]);
>> }
> ...
>> /* just kidding... :) */
>
> For Brian's benefit, I'll point out that while, in this context, 'a' IS
> a pointer, it's also NOT an array, appearances to the contrary
> notwithstanding, so it doesn't provide support for his claims. I suspect
> that those "appearances to the contrary" are part of the motivation for
> such claims.

Indeed it doesn't absolutely provide support for his claims,
since an array is never passed to a function.

-- 
Vincenzo Mercuri | www.backbox.org

[toc] | [prev] | [next] | [standalone]


#14372

FromKaz Kylheku <kaz@kylheku.com>
Date2011-12-07 20:48 +0000
Message-ID<20111207123642.485@kylheku.com>
In reply to#14365
On 2011-12-07, Vincenzo Mercuri <vincenzo.mercuri@hotmail.it> wrote:
> Il 07/12/2011 13:22, curixinfotech ha scritto:
>> hi
>> my Q is on the c language tell me now why c has pointers.
>> parshant
>>
>
> Hi,
>
> here is a short article that can give you a clue as to why and how:
> http://duramecho.com/ComputerInformation/WhyCPointers.html

This article claims to be about C, but then recommends the use of C++ features
new and delete instead of malloc and free.

I.e. this is about the C-like subset within C++ and not about C.

Also, it teaches the casting of the malloc return value.  This is required
in C++, but not in C. It's not a bad idea in C, but you have to remember to
#include <stdlib.h> (not mentioned anywhere in the article), which you might
not unless your C compiler is configured to warn about the use of undeclared
functions. (Whenever possible, find out how to get this warning if it's not
there by default.) Without a prior declaration of malloc, 
int *x = (int *) malloc(42) means "call the function int malloc(int)"
and not "call the function void *malloc(size_t)". The cast suppresses the
diagnostic about the int to (int *) conversion which would otherwise occur.

C++ does not permit calls to undeclared functions, and does not permit
conversions from void * without a cast: good features, but they are not present
in C.

[toc] | [prev] | [next] | [standalone]


#14373

FromVincenzo Mercuri <vincenzo.mercuri@yahoo.it>
Date2011-12-07 22:07 +0100
Message-ID<o7mdnWvQz68-SELTnZ2dnUVZ8tKdnZ2d@giganews.com>
In reply to#14372
Kaz Kylheku ha scritto:
> On 2011-12-07, Vincenzo Mercuri<vincenzo.mercuri@hotmail.it>  wrote:
>> Il 07/12/2011 13:22, curixinfotech ha scritto:
>>> hi
>>> my Q is on the c language tell me now why c has pointers.
>>> parshant
>>>
>>
>> Hi,
>>
>> here is a short article that can give you a clue as to why and how:
>> http://duramecho.com/ComputerInformation/WhyCPointers.html
>
> This article claims to be about C, but then recommends the use of C++ features
> new and delete instead of malloc and free.
>
> I.e. this is about the C-like subset within C++ and not about C.
...

I believe I completely missed the point posting that link.
My intention was to give some useful hint to the OP
but I must recognize that the article turns out to be
a "dangerouse" reading for learners. My mistake, I was
supposed to read it carefully.

-- 
Vincenzo Mercuri | www.backbox.org

[toc] | [prev] | [next] | [standalone]


#14431

FromJorgen Grahn <grahn+nntp@snipabacken.se>
Date2011-12-10 07:34 +0000
Message-ID<slrnje62st.q8l.grahn+nntp@frailea.sa.invalid>
In reply to#14372
On Wed, 2011-12-07, Kaz Kylheku wrote:
> On 2011-12-07, Vincenzo Mercuri <vincenzo.mercuri@hotmail.it> wrote:
>> Il 07/12/2011 13:22, curixinfotech ha scritto:
>>> hi
>>> my Q is on the c language tell me now why c has pointers.
>>> parshant
>>>
>>
>> Hi,
>>
>> here is a short article that can give you a clue as to why and how:
>> http://duramecho.com/ComputerInformation/WhyCPointers.html
>
> This article claims to be about C, but then recommends the use of C++ features
> new and delete instead of malloc and free.
>
> I.e. this is about the C-like subset within C++ and not about C.

To C++'s defense, it's not about proper C++ either -- it's almost
never a good idea to use new/delete to manage arrays like he does in
his examples. 

/Jorgen

-- 
  // Jorgen Grahn <grahn@  Oo  o.   .     .
\X/     snipabacken.se>   O  o   .

[toc] | [prev] | [next] | [standalone]


#14366

FromAugust Karlstrom <fusionfile@gmail.com>
Date2011-12-07 16:16 +0100
Message-ID<jbo00k$gnq$1@dont-email.me>
In reply to#14360
On 2011-12-07 13:22, curixinfotech wrote:
> hi
> my Q is on the c language tell me now why c has pointers.
> parshant
>

All programs store and use references to different memory locations 
(addresses). In a language like PHP for instance, these references are 
mostly handled behind the scenes. In C we have precise control over 
memory usage and the memory references are exposed to the programmer as 
pointers.

The main reason for needing pointers is due to the fact that we cannot 
store a new value between two adjacent memory locations; so if a data 
structure (without a fixed capacity) needs to grow it has to do so in a 
fragmented fashion or be relocated at a different place in memory. The 
former approach makes its data scattered around in memory.


August

[toc] | [prev] | [next] | [standalone]


#14385

FromBorax Man <rotflol2@hotmail.com>
Date2011-12-08 18:32 +1100
Message-ID<2fOdnb5grLiC9X3TnZ2dnUVZ_qaXnZ2d@netspace.net.au>
In reply to#14360
curixinfotech wrote:

> parshant
I can't believe how many people responded to this spam.

[toc] | [prev] | [next] | [standalone]


Page 1 of 5  [1] 2 3 4 5  Next page →

Back to top | Article view | comp.lang.c


csiph-web