www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/16/20:53:04

From: "Earlblunt" <earlblunt AT usa DOT net>
Newsgroups: comp.os.msdos.djgpp
References: <3622bf31 DOT 0 AT news1 DOT tm DOT net DOT my> <36235843 DOT 1189 AT infi DOT net>
Subject: Re: Pointer Usage
Date: Tue, 13 Oct 1998 22:59:37 -0700
Lines: 69
Organization: OEM USER
X-Newsreader: Microsoft Outlook Express 4.72.3110.1
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
NNTP-Posting-Host: mr-85-175.tm.net.my
X-NNTP-Posting-Host: mr-85-175.tm.net.my
Message-ID: <362369b9.0@news1.tm.net.my>
X-Trace: 13 Oct 1998 22:54:49 +0800, mr-85-175.tm.net.my
X-NNTP-Posting-Host: 202.188.95.15
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

so, char pointers do not need * right?

Joe Wright wrote in message <36235843 DOT 1189 AT infi DOT net>...
>Earlblunt wrote:
>>
>> Hello,
>>
>> I am new in C programming and now learning about pointers.
>> Could anyone check for me the codes below for the CORRECT usage of
pointers?
>>
>
>I don't know how you got this to compile.  There are several errors.
>
>> int main()
>> {
>> char crispin[15] , *zunliang[15] ,  *fauzi[15];
>
>crispin is an array of char but zunliang is an array of pointers to
>char, as is fauzi.
>
>> int cris ,  *liew , *ogy;
>
>cris is an int while liew and ogy are pointers to int.
>>
>> strcpy(crispin, "He's in 2A.");
>
>this is ok.
>
>> strcpy(zunliang, crispin);
>> strcpy(fauzi, zunliang);
>
>these are not. in this context while crispin is pointer to char,
>zunliang is a pointer to a pointer to char.  type mis-match and
>requuires a compiler diagnostic.
>>
>> printf("%s\n", crispin);
>> printf("%s\n", zunliang);
>> printf("%s\n", fauzi);
>>
>> cris = 14;
>> liew = cris;
>> ogy = cris;
>>
>> printf("Info on Crispin: %s and he is %d years old.\n", crispin, cris);
>> printf("Info on Liew Zunliang: %s and he is %d years old.\n", zunliang,
>> liew);
>> printf("Info on Mohd. Fauzi: %s and he is %d years old.\n", fauzi, ogy);
>>
>> return 0;
>> }
>>
>> /* OUTPUT:
>>
>> He's in 2A.
>> He's in 2A.
>> He's in 2A.
>> Info on Crispin: He's in 2A. and he is 14 years old.
>> Info on Liew Zunliang: He's in 2A. and he is 14 years old.
>> Info on Mohd. Fauzi: He's in 2A. and he is 14 years old.
>>
>> */
>
>--
>Joe Wright                                 mailto:conserv3 AT infi DOT net
>"Everything should be made as simple as possible, but not simpler."
>                    --- Albert Einstein ---


- Raw text -


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