TYPE CHECKING IN DIFFERENT LANGUAGES
{ Demonstration of Pascal type checking }
program GetAge;
var
Age : integer;
{ Variable to store
user's age }
begin
write('Enter your age: '); { display prompt }
readln(Age);
{ read age from the keyboard }
write('Your age is : '); { echo
age to screen }
writeln(Age);
end.
Enter your age: J
INTEGER READ operation is not valid.
-- Demonstration of Ada type checking.
WITH Text_IO; USE Text_IO;
PROCEDURE Get_Age IS
Age : Natural RANGE 0 .. 199; -- Variable to store
user's age
PACKAGE My_Int_IO IS NEW INTEGER_IO(INTEGER);
USE My_Int_IO;
BEGIN
Put ("Please enter your age: "); --
display prompt
Get ( Age
);
-- read age from keyboard
Put ( "Your age is:
");
-- echo age to screen
Put ( Age );
New_Line;
END Get_Age;
Enter your age: J
Unhandled exception: io_exceptions: data_error
/* Demonstration of C lack of type checking. */
#include <stdio.h>
int main(void)
{
int Age;
printf("Please enter your age: ");
scanf("%d",&Age);
printf("Your age is: %d \n",
Age);
return 0;
}
Enter your age: J
Your age is: 4211552