The value returned from main can be printed using echo $? after you are done with the execution. The return value from main is generally used to indicate the execution status.
The max value is limited to 512. If you try to return a greater value than 512, 512%val would be set in $?.