www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/06/12/00:10:07

From: j DOT aldrich6 AT genie DOT com
Message-Id: <199606120348.AA022271330@relay1.geis.com>
Date: Wed, 12 Jun 96 03:47:00 UTC 0000
To: djgpp AT delorie DOT com
Mime-Version: 1.0
Subject: Re: Question about pointers

Reply to message 8767006    from CALVID AT CORTEZ on 06/10/96 12:26PM


This is just basic C.  Go read any textbook.

>big zero;        <-- this will be 40K bytes
>big *one;        <-- this will be 4 bytes
>big *two;        <-- so will this
>big *three;      <-- and this

Pointers NEVER create their own space, unless you use malloc().  That's
the whole point.  If you modify *one, you'd be modifying zero, *two, and
*three,
assuming that one, two, and three all pointed to zero.

Since you sound like a beginner, I'll give you another tip.  ALWAYS
initialize your pointers before using them.  For example, this is okay:

int foo[100];
foo[0] = 10;

But this is not:

int *foo;
foo[0] = 10;

The reason is that when you declare it, foo is completely undefined
until you initialize it with a value.  If you try the latter example, you will
be lucky if your program only crashes.

John

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019