www.delorie.com/archives/browse.cgi | search |
From: | Tom St Denis <stdenis AT compmore DOT net> |
Newsgroups: | comp.os.msdos.djgpp |
Subject: | Re: var.......ptr |
Date: | Sun, 07 Jan 2001 16:12:48 GMT |
Organization: | Deja.com |
Lines: | 53 |
Message-ID: | <93a4hs$mp9$1@nnrp1.deja.com> |
References: | <939uln$roo1 AT imsp212 DOT netvigator DOT com> |
NNTP-Posting-Host: | 24.156.37.224 |
X-Article-Creation-Date: | Sun Jan 07 16:12:48 2001 GMT |
X-Http-User-Agent: | Mozilla/4.0 (compatible; MSIE 5.5; Windows 98) |
X-Http-Proxy: | 1.1 x52.deja.com:80 (Squid/1.1.22) for client 24.156.37.224 |
X-MyDeja-Info: | XMYDJUIDtomstdenis |
To: | djgpp AT delorie DOT com |
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Reply-To: | djgpp AT delorie DOT com |
In article <939uln$roo1 AT imsp212 DOT netvigator DOT com>, "Honey LAN >_^" <honeymak AT yahoo DOT com> wrote: > what're the differences between pointers and global variables? > i know global variables are storing value and pointers are storing memory > address > but can pointers replace global variables? can global variables replace > pointers? > why we need pointers? why we need global variables? > thank Q..........i m a newbie in programming Global variables can be pointers... Global variables are good if the function of the variable, is um global. I.e it's used in more then one place and must maintain coherancy to work (i.e all functions must see the same value). Local variables are often passed onto functions via arguments (pushed on the processor stack). Pointers are mainly used when you have an array of objects (i.e a buffer) where the pointer would normally point to the first element of the array. Pointers can also be used to reference the original copy of a function argument such as myfunc(int a) { a = 4; } myfunc2(int *a) { *a = 4; } main() { int a; a = 3; myfunc(a); /* a is still three since myfunc() modifies the stack copy */ myfunc2(&a); /* a is now four */ } You should specify what lang you are learning too btw... :-) Tom Sent via Deja.com http://www.deja.com/
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |