Languages :: Pascal :: What's the difference? |
|||
| By: barlow_g |
Date: 19/04/2003 00:00:00 |
Points: 50 | Status: Answered Quality : Excellent |
|
What's the difference between TYPE and VAR? |
|||
| By: VGR | Date: 19/04/2003 22:00:00 | Type : Answer |
|
| Type defines a type, Var defines a variable :D type == class var == instance Types : integer, record(struct), array, file of..., real(float),boolean... var : a of type boolean, i of type integer, etc thus : type St4 = String[4]; Var ext_with_dot : St4; Begin // program ext_with_dot:='.TXT'; ext_with_dot:=3; // error because incompatible TYPES End. // program |
|||
| By: billious | Date: 19/04/2003 22:14:00 | Type : Assist |
|
| A TYPE is precisely what it says - a TYPE of variable. There are pre-defined TYPEs, such as byte, char and integer, and user-defined types where you build-your-own normally by combining pre-defined types into a RECORD. A VAR is an instance of a type. hence, var x : integer; y : byte; z : char; establishes 3 different variables x is an integer [value may be -(2**15) to ((2**15) - 1)] y is a byte [value may be 0 to 255] z is a char [single character] To some extent, types may be compatible, so x := y; will always be ok since all possible values of y are within the range of possible values of x but y := x; will not necessarily be ok beacuse some possible values of x are outside of the range of y. y := z; is nonsense because 'a' for instance (a character) is not representable as a number. BUT y := ord(z); is fine because the ord function converts the single-character contained in z to the accepted numerical equivalent in the ASCII alphabet. equally, z:=y; is nonsense, but z := asc(y); is fine. (asc is the reverse of the ord function) HTH ...Bill |
|||
| By: VGR | Date: 19/04/2003 22:25:00 | Type : Comment |
|
| let's call you verbi(lli)ous ;-) |
|||
| By: billious | Date: 19/04/2003 22:39:00 | Type : Comment |
|
| VGR: So I have a background in COBOL. ...Bill |
|||
| By: VGR | Date: 19/04/2003 23:15:00 | Type : Comment |
|
| or FORTRAN, because of the (2**15) notation ;-) |
|||
| By: Okey | Date: 19/04/2003 23:52:00 | Type : Comment |
|
| Type defines data structures for compiling!(not in exe) Var uses existing or defined data struxctures, which are created in exe! |
|||
| By: VGR | Date: 20/04/2003 00:01:00 | Type : Comment |
|
| mouais 8-) data structures are in the EXE (or COM ;-), at least by looking at the memory layout. You'll find the records' fields, the array elements, the strings and their length... anyway, I don't want to polemicate |
|||
| By: billious | Date: 20/04/2003 00:31:00 | Type : Comment |
|
| VGR: Yeah, FORTRAN too Second language I learnt, after Assembler. Not used it commercially for nearly 20 years. Interesting how notation conventions are observed across languages. ...Bill |
|||
| By: OpConsole | Date: 08/09/2003 13:03:00 | Type : Comment |
|
| barlow_g: This old question needs to be finalized -- accept an answer, split points, or get a refund. |
|||
| By: VGR | Date: 09/09/2003 06:42:00 | Type : Comment |
|
| given the proximity in time, I suggest a fair split |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








