2

I am getting an 'Illegal Expression' error when creating a const char array of const chars.

Program Foo; (*excerpt*)
Const
  X : Char = 'X';
  O : Char = 'O';
  P : Array [1..2] of Char = (X,O);
Begin
  (*stuff*)
End.

2 Answers 2

3

I'm typing this from a device that doesn't have pascal. So I can't verify it, but this probably works:

Const 
X = 'x';
O = 'o';
P : array[1..2] of char = (o,x);
Sign up to request clarification or add additional context in comments.

4 Comments

The language is case-insensitive. You wrote the same thing I already have.
No, i didn't specify the type of the constants, which makes a difference. Just try it, and let me know if it works.
Oh, got you. I actually did make X and O typeless before, but I wanted to know why giving them types causes an error.
Correct. This is because a typed constant is more like an initialzed var.
2

You could also have written

Const
 X : Char = 'X';
 O : Char = 'O';
 P : Array [1..2] of Char = ('X', 'O');

to achieve the same effect

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.