PL/I Interview Questions (11 - 20)
11. What are built-in functions in PL/I?
PL/I provides several built-in functions for common operations, such as:
- Mathematical functions: ABS (absolute value), SQRT (square root), SIN, COS, etc.
- String functions: SUBSTR (substring), INDEX (position of a substring), LENGTH, etc.
- Conversion functions: FLOAT, FIXED, CHAR, etc.
12. What is a BASED variable in PL/I?
A BASED variable in PL/I is a variable that does not have storage allocated at compile time. Instead, its storage is determined at runtime, typically through the use of pointers. This allows for dynamic memory allocation and flexible data structures.
13. How do you declare a pointer in PL/I?
In PL/I, a pointer is declared using the POINTER attribute. For example:
DCL PTR POINTER;
This declares PTR as a pointer variable.
14. What is the purpose of the GET LIST and PUT LIST statements in PL/I?
- GET LIST: Used to read input from the standard input (e.g., keyboard).
- PUT LIST: Used to write output to the standard output (e.g., screen).
15. What does the OPTIONS(MAIN) attribute signify in a PL/I program?
The OPTIONS(MAIN) attribute indicates that the procedure is the main entry point of the program. It signifies the starting point of execution.
PROC OPTIONS(MAIN);
16. How do you handle exceptions in PL/I?
PL/I provides the ON statement to handle exceptions. You can define exception handlers for various conditions, such as ERROR, ENDFILE, ZERODIVIDE, etc.
ON ERROR BEGIN;
/* Exception handling code */
END;
17. What is the difference between CALL and GOTO in PL/I?
- CALL: Transfers control to a subroutine or procedure and expects to return after the subroutine completes.
- GOTO: Transfers control to a specified label within the program.
18. What is the purpose of the ENTRY statement in PL/I?
The ENTRY statement in PL/I defines an alternate entry point to a procedure, allowing a single procedure to be invoked using different names. This is useful when a procedure needs to perform different tasks based on the entry point used.
PROC MAIN OPTIONS(MAIN);
ENTRY ALTERNATE_ENTRY;
/* Procedure code */
END MAIN;
19. How do you include external files or copybooks in a PL/I program?
In PL/I, external files or copybooks are included using the %INCLUDE preprocessor directive.
%INCLUDE 'COPYBOOK_NAME';
20. What are the different storage classes in PL/I?
PL/I provides several storage classes to define the lifetime and scope of variables:
- AUTOMATIC: Variables are created upon entry to a block and destroyed upon exit. Default for variables declared within procedures.
- STATIC: Variables retain their values between procedure calls and are initialized only once.
- CONTROLLED: Variables are dynamically allocated and deallocated using the ALLOCATE and FREE statements.
- BASED: Variables whose storage is based on a pointer and are not automatically allocated.