![]() The With statement provides an alternative way to do that. This way the name of the record variable has to be written every time. We have discussed that the members of a record can be accessed using the member access operator (.). Writeln( 'Book 2 book_id : ', Book2^.book_id) ![]() Writeln( 'Book 2 subject : ', Book2^.subject) Writeln('Book 2 author : ', Book2^.author) Writeln ('Book 2 title : ', Book2^.title) Writeln( 'Book 1 book_id : ', Book1^.book_id) Writeln( 'Book 1 subject : ', Book1^.subject) Writeln('Book 1 author : ', Book1^.author) ![]() Writeln ('Book 1 title : ', Book1^.title) (* Declare Book1 and Book2 of pointer type that refers to Book type *)īook1^.subject := 'C Programming Tutorial' īook2^.subject := 'Telecom Billing Tutorial' Hope this will be easy for you to understand the concept − Let us re-write the first example using a pointer to the Books record. ![]() operator as follows −įinally, don't forget to dispose the used storage, when it is no longer in use − To access the members of a record using a pointer to that record, you must use the ^. To declare a variable of the created pointer type, you use the var keyword −īefore using these pointers, you must create storage for a record-name type variable, which will be manipulated by these pointers. Now, you can store the address of a record type variable in the above-defined pointer variable. You can define pointers to records in very similar way as you define pointer to any other variable as follows − Writeln( 'Book book_id : ', book.book_id) Writeln( 'Book subject : ', book.subject) You would access the record fields in the similar way as you have accessed in the above example − You can pass a record as a subprogram argument in very similar way as you pass any other variable or pointer. When the above code is compiled and executed, it produces the following result −īook 2 subject : Telecom Billing Tutorial Writeln( 'Book 2 book_id : ', Book2.book_id) Writeln( 'Book 2 subject : ', Book2.subject) Writeln ('Book 2 title : ', Book2.title) Writeln( 'Book 1 book_id : ', Book1.book_id) Writeln( 'Book 1 subject : ', Book1.subject) Writeln ('Book 1 title : ', Book1.title) Following is the example to explain usage of structure −īook1, Book2: Books (* Declare Book1 and Book2 of type Books *)īook1.subject := 'C Programming Tutorial' īook2.subject := 'Telecom Billing Tutorial' The member access operator is coded as a period between the record variable name and the field that we wish to access. To access any field of a record, we use the member access operator (.). The record variables are defined in the usual way asĪlternatively, you can directly define a record type variable as − Here is the way you would declare the Book record − ![]() To define a record type, you may use the type declaration statement. Suppose you want to keep track of your books in a library, you might want to track the following attributes about each book − Pascal arrays allow you to define type of variables that can hold several data items of the same kind but a record is another user-defined data type available in Pascal which allows you to combine data items of different kinds. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |