ɎȿȾȿɊȺɅɖɇɈȿ ȺȽȿɇɌɋɌȼɈ ɉɈ ɈȻɊȺɁɈȼȺɇɂɘ ȽɈɋɍȾȺɊɋɌȼȿɇɇɈȿ ɈȻɊȺɁɈȼȺɌȿɅɖɇɈȿ ɍɑɊȿɀȾȿɇɂȿ ȼɕɋɒȿȽɈ ɉɊɈɎȿɋɋɂɈɇȺɅɖɇɈȽɈ ɈȻɊȺɁɈȼȺɇɂə «ȼ...
19 downloads
271 Views
321KB Size
Report
This content was uploaded by our users and we assume good faith they have the permission to share this book. If you own the copyright to this book and it is wrongfully on our website, we offer a simple DMCA procedure to remove your content from our site. Start by pressing the button below!
Report copyright / DMCA form
ɎȿȾȿɊȺɅɖɇɈȿ ȺȽȿɇɌɋɌȼɈ ɉɈ ɈȻɊȺɁɈȼȺɇɂɘ ȽɈɋɍȾȺɊɋɌȼȿɇɇɈȿ ɈȻɊȺɁɈȼȺɌȿɅɖɇɈȿ ɍɑɊȿɀȾȿɇɂȿ ȼɕɋɒȿȽɈ ɉɊɈɎȿɋɋɂɈɇȺɅɖɇɈȽɈ ɈȻɊȺɁɈȼȺɇɂə «ȼɈɊɈɇȿɀɋɄɂɃ ȽɈɋɍȾȺɊɋɌȼȿɇɇɕɃ ɍɇɂȼȿɊɋɂɌȿɌ»
Ɉɫɧɨɜɵ ɹɡɵɤɚ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ C++ ɫ ɩɪɢɦɟɧɟɧɢɟɦ ɬɟɯɧɨɥɨɝɢɢ ɨɛɴɟɤɬɧɨ-ɨɪɢɟɧɬɢɪɨɜɚɧɧɨɝɨ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ ɍɱɟɛɧɨ-ɦɟɬɨɞɢɱɟɫɤɨɟ ɩɨɫɨɛɢɟ ɞɥɹ ɜɭɡɨɜ
ɋɨɫɬɚɜɢɬɟɥɶ Ɇ.Ʉ. ɑɟɪɧɵɲɨɜ
ɂɡɞɚɬɟɥɶɫɤɨ-ɩɨɥɢɝɪɚɮɢɱɟɫɤɢɣ ɰɟɧɬɪ ȼɨɪɨɧɟɠɫɤɨɝɨ ɝɨɫɭɞɚɪɫɬɜɟɧɧɨɝɨ ɭɧɢɜɟɪɫɢɬɟɬɚ 2007
ɍɬɜɟɪɠɞɟɧɨ ɧɚɭɱɧɨ-ɦɟɬɨɞɢɱɟɫɤɢɦ ɫɨɜɟɬɨɦ ɮɚɤɭɥɶɬɟɬɚ ɉɆɆ 14 ɦɚɹ 2007 ɝ., ɩɪɨɬɨɤɨɥ ʋ 9
ɍɱɟɛɧɨ-ɦɟɬɨɞɢɱɟɫɤɨɟ ɩɨɫɨɛɢɟ ɩɨɞɝɨɬɨɜɥɟɧɨ ɧɚ ɤɚɮɟɞɪɟ ɦɚɬɟɦɚɬɢɱɟɫɤɨɝɨ ɨɛɟɫɩɟɱɟɧɢɹ ɗȼɆ ɮɚɤɭɥɶɬɟɬɚ ɉɆɆ ȼɨɪɨɧɟɠɫɤɨɝɨ ɝɨɫɭɞɚɪɫɬɜɟɧɧɨɝɨ ɭɧɢɜɟɪɫɢɬɟɬɚ/
Ɋɟɤɨɦɟɧɞɭɟɬɫɹ ɞɥɹ ɫɬɭɞɟɧɬɨɜ 2-ɝɨ ɤɭɪɫɚ ɮɚɤɭɥɶɬɟɬɚ ɉɆɆ, ɢɡɭɱɚɸɳɢɯ ɤɭɪɫ «Ɉɛɴɟɤɬɧɨ-ɨɪɢɟɧɬɢɪɨɜɚɧɧɨɟ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɟ», ɚ ɬɚɤɠɟ ɫɬɭɞɟɧɬɨɜ, ɫɩɟɰɢɚɥɢɡɢɪɭɸɳɢɯɫɹ ɧɚ ɤɚɮɟɞɪɟ ɆɈ ɗȼɆ.
Ⱦɥɹ ɫɩɟɰɢɚɥɶɧɨɫɬɢ: 010501 – ɉɪɢɤɥɚɞɧɚɹ ɦɚɬɟɦɚɬɢɤɚ ɢ ɢɧɮɨɪɦɚɬɢɤɚ
2
1. Ɉɛɴɟɤɬɧɨ-ɨɪɢɟɧɬɢɪɨɜɚɧɧɵɣ ɩɨɞɯɨɞ ɜ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɢ 1.1. Ɍɟɯɧɨɥɨɝɢɢ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ Ɍɟɯɧɨɥɨɝɢɹ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ – ɷɬɨ ɫɨɜɨɤɭɩɧɨɫɬɶ ɦɟɬɨɞɨɜ ɢ ɫɪɟɞɫɬɜ ɪɚɡɪɚɛɨɬɤɢ (ɧɚɩɢɫɚɧɢɹ) ɩɪɨɝɪɚɦɦ ɢ ɩɨɪɹɞɨɤ ɩɪɢɦɟɧɟɧɢɹ ɷɬɢɯ ɦɟɬɨɞɨɜ ɢ ɫɪɟɞɫɬɜ. ɇɚ ɪɚɧɧɢɯ ɷɬɚɩɚɯ ɪɚɡɜɢɬɢɹ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ, ɤɨɝɞɚ ɩɪɨɝɪɚɦɦɵ ɩɪɟɞɫɬɚɜɥɹɥɢ ɫɨɛɨɣ ɩɨɫɥɟɞɨɜɚɬɟɥɶɧɨɫɬɶ ɦɚɲɢɧɧɵɯ ɤɨɦɚɧɞ, ɤɚɤɚɹ-ɥɢɛɨ ɬɟɯɧɨɥɨɝɢɹ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ ɨɬɫɭɬɫɬɜɨɜɚɥɚ. ɉɟɪɜɵɟ ɲɚɝɢ ɜ ɪɚɡɪɚɛɨɬɤɟ ɬɟɯɧɨɥɨɝɢɢ ɫɨɫɬɨɹɥɢ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ ɩɪɨɝɪɚɦɦɵ ɜ ɜɢɞɟ ɩɨɫɥɟɞɨɜɚɬɟɥɶɧɨɫɬɢ ɨɩɟɪɚɬɨɪɨɜ. ɇɚɩɢɫɚɧɢɸ ɩɨɫɥɟɞɨɜɚɬɟɥɶɧɨɫɬɢ ɦɚɲɢɧɧɵɯ ɤɨɦɚɧɞ ɩɪɟɞɲɟɫɬɜɨɜɚɥɨ ɫɨɫɬɚɜɥɟɧɢɟ ɨɩɟɪɚɬɨɪɧɨɣ ɫɯɟɦɵ, ɨɬɪɚɠɚɸɳɟɣ ɩɨɫɥɟɞɨɜɚɬɟɥɶɧɨɫɬɶ ɨɩɟɪɚɬɨɪɨɜ ɢ ɩɟɪɟɯɨɞɵ ɦɟɠɞɭ ɧɢɦɢ. Ɉɩɟɪɚɬɨɪɧɵɣ ɩɨɞɯɨɞ ɩɨɡɜɨɥɢɥ ɪɚɡɪɚɛɨɬɚɬɶ ɩɟɪɜɵɟ ɩɪɨɝɪɚɦɦɵ ɞɥɹ ɚɜɬɨɦɚɬɢɡɚɰɢɢ ɫɨɫɬɚɜɥɟɧɢɹ ɩɪɨɝɪɚɦɦ – ɬɚɤ ɧɚɡɵɜɚɟɦɵɟ ɫɨɫɬɚɜɥɹɸɳɢɟ ɩɪɨɝɪɚɦɦɵ. ɋ ɭɜɟɥɢɱɟɧɢɟɦ ɪɚɡɦɟɪɨɜ ɩɪɨɝɪɚɦɦ ɫɬɚɥɢ ɜɵɞɟɥɹɬɶ ɢɯ ɨɛɨɫɨɛɥɟɧɧɵɟ ɱɚɫɬɢ ɢ ɨɮɨɪɦɥɹɬɶ ɢɯ ɤɚɤ ɩɨɞɩɪɨɝɪɚɦɦɵ. ɑɚɫɬɶ ɬɚɤɢɯ ɩɨɞɩɪɨɝɪɚɦɦ ɨɛɴɟɞɢɧɹɥɚɫɶ ɜ ɛɢɛɥɢɨɬɟɤɢ, ɢɡ ɤɨɬɨɪɵɯ ɩɨɞɩɪɨɝɪɚɦɦɵ ɦɨɠɧɨ ɛɵɥɨ ɜɤɥɸɱɚɬɶ ɜ ɪɚɛɨɱɢɟ ɩɪɨɝɪɚɦɦɵ ɢ ɡɚɬɟɦ ɜɵɡɵɜɚɬɶ ɢɡ ɪɚɛɨɱɢɯ ɩɪɨɝɪɚɦɦ. ɗɬɨ ɩɨɥɨɠɢɥɨ ɧɚɱɚɥɨ ɩɪɨɰɟɞɭɪɧɨɦɭ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɸ – ɛɨɥɶɲɚɹ ɩɪɨɝɪɚɦɦɚ ɩɪɟɞɫɬɚɜɥɹɥɚɫɶ ɫɨɜɨɤɭɩɧɨɫɬɶɸ ɩɪɨɰɟɞɭɪ-ɩɨɞɩɪɨɝɪɚɦɦ. Ɉɞɧɚ ɢɡ ɩɨɞɩɪɨɝɪɚɦɦ ɹɜɥɹɥɚɫɶ ɝɥɚɜɧɨɣ, ɢ ɫ ɧɟɟ ɧɚɱɢɧɚɥɨɫɶ ɜɵɩɨɥɧɟɧɢɟ ɩɪɨɝɪɚɦɦɵ. ȼ 1958 ɝɨɞɭ ɛɵɥɢ ɪɚɡɪɚɛɨɬɚɧɵ ɩɟɪɜɵɟ ɹɡɵɤɢ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ, Ɏɨɪɬɪɚɧ (FORTRAN) ɢ Ⱥɥɝɨɥ-58 (ALGOL). ɉɪɨɝɪɚɦɦɚ ɧɚ Ɏɨɪɬɪɚɧɟ ɫɨɫɬɨɹɥɚ ɢɡ ɝɥɚɜɧɨɣ ɩɪɨɝɪɚɦɦɵ ɢ ɧɟɤɨɬɨɪɨɝɨ ɤɨɥɢɱɟɫɬɜɚ ɩɪɨɰɟɞɭɪ – ɩɨɞɩɪɨɝɪɚɦɦ ɢ ɮɭɧɤɰɢɣ. ɉɪɨɝɪɚɦɦɚ ɧɚ Ⱥɥɝɨɥɟ-58 ɢ ɟɝɨ ɩɨɫɥɟɞɭɸɳɟɣ ɜɟɪɫɢɢ Ⱥɥɝɨɥɟ-60 ɩɪɟɞɫɬɚɜɥɹɥɚ ɫɨɛɨɣ ɟɞɢɧɨɟ ɰɟɥɨɟ, ɧɨ ɢɦɟɥɚ ɛɥɨɱɧɭɸ ɫɬɪɭɤɬɭɪɭ, ɜɤɥɸɱɚɸɳɭɸ ɝɥɚɜɧɵɣ ɛɥɨɤ ɢ ɜɥɨɠɟɧɧɵɟ ɛɥɨɤɢ ɩɨɞɩɪɨɝɪɚɦɦ ɢ ɮɭɧɤɰɢɣ. Ʉɨɦɩɢɥɹɬɨɪɵ ɞɥɹ Ɏɨɪɬɪɚɧɚ ɨɛɟɫɩɟɱɢɜɚɥɢ ɪɚɡɞɟɥɶɧɭɸ ɬɪɚɧɫɥɹɰɢɸ ɩɪɨɰɟɞɭɪ ɢ ɩɨɫɥɟɞɭɸɳɟɟ ɢɯ ɨɛɴɟɞɢɧɟɧɢɟ ɜ ɪɚɛɨɱɭɸ ɩɪɨɝɪɚɦɦɭ, ɩɟɪɜɵɟ ɤɨɦɩɢɥɹɬɨɪɵ ɞɥɹ Ⱥɥɝɨɥɚ ɩɪɟɞɩɨɥɚɝɚɥɢ, ɱɬɨ ɬɪɚɧɫɥɢɪɭɟɬɫɹ ɫɪɚɡɭ ɜɫɹ ɩɪɨɝɪɚɦɦɚ, ɪɚɡɞɟɥɶɧɚɹ ɬɪɚɧɫɥɹɰɢɹ ɩɪɨɰɟɞɭɪ ɧɟ ɨɛɟɫɩɟɱɢɜɚɥɚɫɶ. ɉɪɨɰɟɞɭɪɧɵɣ ɩɨɞɯɨɞ ɩɨɬɪɟɛɨɜɚɥ ɫɬɪɭɤɬɭɪɢɪɨɜɚɧɢɹ ɛɭɞɭɳɟɣ ɩɪɨɝɪɚɦɦɵ, ɪɚɡɞɟɥɟɧɢɹ ɟɟ ɧɚ ɨɬɞɟɥɶɧɵɟ ɩɪɨɰɟɞɭɪɵ. ɉɪɢ ɪɚɡɪɚɛɨɬɤɟ ɨɬɞɟɥɶɧɨɣ ɩɪɨɰɟɞɭɪɵ ɨ ɞɪɭɝɢɯ ɩɪɨɰɟɞɭɪɚɯ ɬɪɟɛɨɜɚɥɨɫɶ ɡɧɚɬɶ ɬɨɥɶɤɨ ɢɯ ɧɚɡɧɚɱɟɧɢɟ ɢ ɫɩɨɫɨɛ ɜɵɡɨɜɚ. ɉɨɹɜɢɥɚɫɶ ɜɨɡɦɨɠɧɨɫɬɶ ɩɟɪɟɪɚɛɚɬɵɜɚɬɶ ɨɬɞɟɥɶɧɵɟ ɩɪɨɰɟɞɭɪɵ, ɧɟ ɡɚɬɪɚɝɢɜɚɹ ɨɫɬɚɥɶɧɨɣ ɱɚɫɬɢ ɩɪɨɝɪɚɦɦɵ, ɫɨɤɪɚɳɚɹ ɩɪɢ ɷɬɨɦ ɡɚɬɪɚɬɵ ɬɪɭɞɚ ɢ ɦɚɲɢɧɧɨɝɨ ɜɪɟɦɟɧɢ ɧɚ ɪɚɡɪɚɛɨɬɤɭ ɢ ɦɨɞɟɪɧɢɡɚɰɢɸ ɩɪɨɝɪɚɦɦ. 3
ɋɥɟɞɭɸɳɢɦ ɲɚɝɨɦ ɜ ɭɝɥɭɛɥɟɧɢɢ ɫɬɪɭɤɬɭɪɢɪɨɜɚɧɢɹ ɩɪɨɝɪɚɦɦ ɫɬɚɥɨ ɬɚɤ ɧɚɡɵɜɚɟɦɨɟ ɫɬɪɭɤɬɭɪɧɨɟ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɟ, ɩɪɢ ɤɨɬɨɪɨɦ ɩɪɨɝɪɚɦɦɚ ɜ ɰɟɥɨɦ ɢ ɨɬɞɟɥɶɧɵɟ ɩɪɨɰɟɞɭɪɵ ɪɚɫɫɦɚɬɪɢɜɚɥɢɫɶ ɤɚɤ ɩɨɫɥɟɞɨɜɚɬɟɥɶɧɨɫɬɢ ɤɚɧɨɧɢɱɟɫɤɢɯ ɫɬɪɭɤɬɭɪ: ɥɢɧɟɣɧɵɯ ɭɱɚɫɬɤɨɜ, ɰɢɤɥɨɜ ɢ ɪɚɡɜɟɬɜɥɟɧɢɣ. ɉɨɹɜɢɥɚɫɶ ɜɨɡɦɨɠɧɨɫɬɶ ɱɢɬɚɬɶ ɢ ɩɪɨɜɟɪɹɬɶ ɩɪɨɝɪɚɦɦɭ ɤɚɤ ɩɨɫɥɟɞɨɜɚɬɟɥɶɧɵɣ ɬɟɤɫɬ, ɱɬɨ ɩɨɜɵɫɢɥɨ ɩɪɨɢɡɜɨɞɢɬɟɥɶɧɨɫɬɶ ɬɪɭɞɚ ɩɪɨɝɪɚɦɦɢɫɬɨɜ ɩɪɢ ɪɚɡɪɚɛɨɬɤɟ ɢ ɨɬɥɚɞɤɟ ɩɪɨɝɪɚɦɦ. ɋ ɰɟɥɶɸ ɩɨɜɵɲɟɧɢɹ ɫɬɪɭɤɬɭɪɧɨɫɬɢ ɩɪɨɝɪɚɦɦɵ ɛɵɥɢ ɜɵɞɜɢɧɭɬɵ ɬɪɟɛɨɜɚɧɢɹ ɤ ɛɨɥɶɲɟɣ ɧɟɡɚɜɢɫɢɦɨɫɬɢ ɩɨɞɩɪɨɝɪɚɦɦ, ɩɨɞɩɪɨɝɪɚɦɦɵ ɞɨɥɠɧɵ ɫɜɹɡɵɜɚɬɶɫɹ ɫ ɜɵɡɵɜɚɸɳɢɦɢ ɢɯ ɩɪɨɝɪɚɦɦɚɦɢ ɬɨɥɶɤɨ ɩɭɬɟɦ ɩɟɪɟɞɚɱɢ ɢɦ ɚɪɝɭɦɟɧɬɨɜ. ɂɫɩɨɥɶɡɨɜɚɧɢɟ ɜ ɩɨɞɩɪɨɝɪɚɦɦɚɯ ɩɟɪɟɦɟɧɧɵɯ, ɩɪɢɧɚɞɥɟɠɚɳɢɯ ɞɪɭɝɢɦ ɩɪɨɰɟɞɭɪɚɦ ɢɥɢ ɝɥɚɜɧɨɣ ɩɪɨɝɪɚɦɦɟ, ɫɬɚɥɨ ɫɱɢɬɚɬɶɫɹ ɧɟɠɟɥɚɬɟɥɶɧɵɦ. Ɍɟɯɧɨɥɨɝɢɢ ɩɪɨɰɟɞɭɪɧɨɝɨ ɢ ɫɬɪɭɤɬɭɪɧɨɝɨ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ ɡɚɬɪɨɧɭɥɢ ɩɪɟɠɞɟ ɜɫɟɝɨ ɩɪɨɰɟɫɫ ɨɩɢɫɚɧɢɹ ɚɥɝɨɪɢɬɦɚ ɤɚɤ ɩɨɫɥɟɞɨɜɚɬɟɥɶɧɨɫɬɢ ɲɚɝɨɜ, ɜɟɞɭɳɢɯ ɨɬ ɜɚɪɶɢɪɭɟɦɵɯ ɢɫɯɨɞɧɵɯ ɞɚɧɧɵɯ ɤ ɢɫɤɨɦɨɦɭ ɪɟɡɭɥɶɬɚɬɭ. Ⱦɥɹ ɪɟɲɟɧɢɹ ɫɩɟɰɢɚɥɶɧɵɯ ɡɚɞɚɱ ɫɬɚɥɢ ɪɚɡɪɚɛɚɬɵɜɚɬɶɫɹ ɹɡɵɤɢ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ, ɨɪɢɟɧɬɢɪɨɜɚɧɧɵɟ ɧɚ ɤɨɧɤɪɟɬɧɵɣ ɤɥɚɫɫ ɡɚɞɚɱ: ɧɚ ɫɢɫɬɟɦɵ ɭɩɪɚɜɥɟɧɢɹ ɛɚɡɚɦɢ ɞɚɧɧɵɯ, ɢɦɢɬɚɰɢɨɧɧɨɟ ɦɨɞɟɥɢɪɨɜɚɧɢɟ ɢ ɬɚɤ ɞɚɥɟɟ. ɉɪɢ ɪɚɡɪɚɛɨɬɤɟ ɬɪɚɧɫɥɹɬɨɪɨɜ ɜɫɟ ɛɨɥɶɲɟ ɜɧɢɦɚɧɢɹ ɫɬɚɥɨ ɭɞɟɥɹɬɶɫɹ ɨɛɧɚɪɭɠɟɧɢɸ ɨɲɢɛɨɤ ɜ ɢɫɯɨɞɧɵɯ ɬɟɤɫɬɚɯ ɩɪɨɝɪɚɦɦ, ɨɛɟɫɩɟɱɢɜɚɹ ɷɬɢɦ ɫɨɤɪɚɳɟɧɢɟ ɡɚɬɪɚɬ ɜɪɟɦɟɧɢ ɧɚ ɨɬɥɚɞɤɭ ɩɪɨɝɪɚɦɦ. ɉɪɢɦɟɧɟɧɢɟ ɩɪɨɝɪɚɦɦ ɜ ɫɚɦɵɯ ɪɚɡɧɵɯ ɨɛɥɚɫɬɹɯ ɱɟɥɨɜɟɱɟɫɤɨɣ ɞɟɹɬɟɥɶɧɨɫɬɢ ɩɪɢɜɟɥɨ ɤ ɧɟɨɛɯɨɞɢɦɨɫɬɢ ɩɨɜɵɲɟɧɢɹ ɧɚɞɟɠɧɨɫɬɢ ɜɫɟɝɨ ɩɪɨɝɪɚɦɦɧɨɝɨ ɨɛɟɫɩɟɱɟɧɢɹ. Ɉɞɧɢɦ ɢɡ ɧɚɩɪɚɜɥɟɧɢɣ ɫɨɜɟɪɲɟɧɫɬɜɨɜɚɧɢɹ ɹɡɵɤɨɜ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ ɫɬɚɥɨ ɩɨɜɵɲɟɧɢɟ ɭɪɨɜɧɹ ɬɢɩɢɡɚɰɢɢ ɞɚɧɧɵɯ. Ɍɟɨɪɢɹ ɬɢɩɨɜ ɞɚɧɧɵɯ ɢɫɯɨɞɢɬ ɢɡ ɬɨɝɨ, ɱɬɨ ɤɚɠɞɨɟ ɢɫɩɨɥɶɡɭɟɦɨɟ ɜ ɩɪɨɝɪɚɦɦɟ ɞɚɧɧɨɟ ɩɪɢɧɚɞɥɟɠɢɬ ɨɞɧɨɦɭ ɢ ɬɨɥɶɤɨ ɨɞɧɨɦɭ ɬɢɩɭ ɞɚɧɧɵɯ. Ɍɢɩ ɞɚɧɧɵɯ ɨɩɪɟɞɟɥɹɟɬ ɦɧɨɠɟɫɬɜɨ ɜɨɡɦɨɠɧɵɯ ɡɧɚɱɟɧɢɣ ɞɚɧɧɵɯ ɢ ɧɚɛɨɪ ɨɩɟɪɚɰɢɣ, ɞɨɩɭɫɬɢɦɵɯ ɧɚɞ ɷɬɢɦɢ ɞɚɧɧɵɦɢ. Ⱦɚɧɧɵɟ ɤɨɧɤɪɟɬɧɨɝɨ ɬɢɩɚ ɜ ɪɹɞɟ ɫɥɭɱɚɟɜ ɦɨɝɭɬ ɛɵɬɶ ɩɪɟɨɛɪɚɡɨɜɚɧɵ ɜ ɞɚɧɧɵɟ ɞɪɭɝɨɝɨ ɬɢɩɚ, ɧɨ ɬɚɤɨɟ ɩɪɟɨɛɪɚɡɨɜɚɧɢɟ ɞɨɥɠɧɨ ɛɵɬɶ ɹɜɧɨ ɩɪɟɞɫɬɚɜɥɟɧɨ ɜ ɩɪɨɝɪɚɦɦɟ. ȼ ɡɚɜɢɫɢɦɨɫɬɢ ɨɬ ɫɬɟɩɟɧɢ ɜɵɩɨɥɧɟɧɢɹ ɩɟɪɟɱɢɫɥɟɧɧɵɯ ɬɪɟɛɨɜɚɧɢɣ ɦɨɠɧɨ ɝɨɜɨɪɢɬɶ ɨɛ ɭɪɨɜɧɟ ɬɢɩɢɡɚɰɢɢ ɬɨɝɨ ɢɥɢ ɢɧɨɝɨ ɹɡɵɤɚ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ. ɋɬɪɟɦɥɟɧɢɟ ɩɨɜɵɫɢɬɶ ɭɪɨɜɟɧɶ ɬɢɩɢɡɚɰɢɢ ɹɡɵɤɚ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ ɩɪɢɜɟɥɨ ɤ ɩɨɹɜɥɟɧɢɸ ɹɡɵɤɚ ɉɚɫɤɚɥɶ (PASCAL), ɤɨɬɨɪɵɣ ɫɱɢɬɚɟɬɫɹ ɫɬɪɨɝɨ ɬɢɩɢɡɢɪɨɜɚɧɧɵɦ ɹɡɵɤɨɦ, ɯɨɬɹ ɢ ɜ ɧɟɦ ɪɚɡɪɟɲɟɧɵ ɧɟɤɨɬɨɪɵɟ ɧɟɹɜɧɵɟ ɩɪɟɨɛɪɚɡɨɜɚɧɢɹ ɬɢɩɨɜ, ɧɚɩɪɢɦɟɪ, ɰɟɥɵɯ ɞɚɧɧɵɯ ɜ ɜɟɳɟɫɬɜɟɧɧɵɟ. ɉɪɢɦɟɧɟɧɢɟ ɫɬɪɨɝɨ ɬɢɩɢɡɢɪɨɜɚɧɧɨɝɨ ɹɡɵɤɚ ɩɪɢ ɧɚɩɢɫɚɧɢɢ ɩɪɨɝɪɚɦɦɵ ɩɨɡɜɨɥɹɟɬ ɟɳɟ ɩɪɢ ɬɪɚɧɫɥɹɰɢɢ ɢɫɯɨɞɧɨɝɨ ɬɟɤɫɬɚ ɜɵɹɜɢɬɶ ɦɧɨɝɢɟ ɨɲɢɛɤɢ ɢɫɩɨɥɶɡɨɜɚɧɢɹ ɞɚɧɧɵɯ ɢ ɷɬɢɦ ɩɨɜɵɫɢɬɶ ɧɚɞɟɠɧɨɫɬɶ ɩɪɨɝɪɚɦɦɵ. ȼɦɟɫɬɟ ɫ ɬɟɦ ɫɬɪɨɝɚɹ ɬɢɩɢɡɚɰɢɹ ɫɤɨɜɵɜɚɥɚ ɫɜɨɛɨɞɭ ɩɪɨɝɪɚɦɦɢɫɬɚ, ɡɚɬɪɭɞɧɹɥɚ ɩɪɢɦɟɧɟɧɢɟ ɧɟɤɨɬɨɪɵɯ ɩɪɢɟɦɨɜ ɩɪɟɨɛɪɚɡɨɜɚɧɢɹ ɞɚɧɧɵɯ, ɱɚɫɬɨ ɢɫɩɨɥɶɡɭɟɦɵɯ ɜ ɫɢɫɬɟɦɧɨɦ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɢ. ɉɪɚɤɬɢɱɟɫɤɢ ɨɞɧɨɜɪɟɦɟɧɧɨ ɫ ɉɚɫɤɚɥɟɦ ɛɵɥ ɪɚɡɪɚɛɨɬɚɧ ɹɡɵɤ ɋɢ (C), ɜ ɛɨɥɶɲɟɣ 4
ɫɬɟɩɟɧɢ ɨɪɢɟɧɬɢɪɨɜɚɧɧɵɣ ɧɚ ɫɢɫɬɟɦɧɨɟ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɟ ɢ ɨɬɧɨɫɹɳɢɣɫɹ ɤ ɫɥɚɛɨ ɬɢɩɢɡɢɪɨɜɚɧɧɵɦ ɹɡɵɤɚɦ. ȼɫɟ ɭɧɢɜɟɪɫɚɥɶɧɵɟ ɹɡɵɤɢ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ, ɧɟɫɦɨɬɪɹ ɧɚ ɪɚɡɥɢɱɢɹ ɜ ɫɢɧɬɚɤɫɢɫɟ ɢ ɢɫɩɨɥɶɡɭɟɦɵɯ ɤɥɸɱɟɜɵɯ ɫɥɨɜɚɯ, ɪɟɚɥɢɡɭɸɬ ɨɞɧɢ ɢ ɬɟ ɠɟ ɤɚɧɨɧɢɱɟɫɤɢɟ ɫɬɪɭɤɬɭɪɵ: ɨɩɟɪɚɬɨɪɵ ɩɪɢɫɜɚɢɜɚɧɢɹ, ɰɢɤɥɵ ɢ ɪɚɡɜɟɬɜɥɟɧɢɹ. ȼɨ ɜɫɟɯ ɫɨɜɪɟɦɟɧɧɵɯ ɹɡɵɤɚɯ ɩɪɢɫɭɬɫɬɜɭɸɬ ɩɪɟɞɨɩɪɟɞɟɥɟɧɧɵɟ (ɛɚɡɨɜɵɟ) ɬɢɩɵ ɞɚɧɧɵɯ (ɰɟɥɵɟ ɢ ɜɟɳɟɫɬɜɟɧɧɵɟ ɚɪɢɮɦɟɬɢɱɟɫɤɢɟ ɬɢɩɵ, ɫɢɦɜɨɥɶɧɵɣ ɢ, ɜɨɡɦɨɠɧɨ, ɫɬɪɨɤɨɜɵɣ ɬɢɩ), ɢɦɟɟɬɫɹ ɜɨɡɦɨɠɧɨɫɬɶ ɢɫɩɨɥɶɡɨɜɚɧɢɹ ɚɝɪɟɝɚɬɨɜ ɞɚɧɧɵɯ, ɜ ɬɨɦ ɱɢɫɥɟ ɦɚɫɫɢɜɨɜ ɢ ɫɬɪɭɤɬɭɪ (ɡɚɩɢɫɟɣ). Ⱦɥɹ ɚɪɢɮɦɟɬɢɱɟɫɤɢɯ ɞɚɧɧɵɯ ɪɚɡɪɟɲɟɧɵ ɨɛɵɱɧɵɟ ɚɪɢɮɦɟɬɢɱɟɫɤɢɟ ɨɩɟɪɚɰɢɢ, ɞɥɹ ɚɝɪɟɝɚɬɨɜ ɞɚɧɧɵɯ ɨɛɵɱɧɨ ɩɪɟɞɭɫɦɨɬɪɟɧɚ ɬɨɥɶɤɨ ɨɩɟɪɚɰɢɹ ɩɪɢɫɜɚɢɜɚɧɢɹ ɢ ɜɨɡɦɨɠɧɨɫɬɶ ɨɛɪɚɳɟɧɢɹ ɤ ɷɥɟɦɟɧɬɚɦ ɚɝɪɟɝɚɬɚ. ȼɦɟɫɬɟ ɫ ɬɟɦ ɩɪɢ ɪɚɡɪɚɛɨɬɤɟ ɩɪɨɝɪɚɦɦɵ ɞɥɹ ɪɟɲɟɧɢɹ ɤɨɧɤɪɟɬɧɨɣ ɩɪɢɤɥɚɞɧɨɣ ɡɚɞɚɱɢ ɠɟɥɚɬɟɥɶɧɚ, ɜɨɡɦɨɠɧɨ, ɛɨɥɶɲɚɹ ɤɨɧɰɟɩɬɭɚɥɶɧɚɹ ɛɥɢɡɨɫɬɶ ɬɟɤɫɬɚ ɩɪɨɝɪɚɦɦɵ ɤ ɨɩɢɫɚɧɢɸ ɡɚɞɚɱɢ. ɇɚɩɪɢɦɟɪ, ɟɫɥɢ ɪɟɲɟɧɢɟ ɡɚɞɚɱɢ ɬɪɟɛɭɟɬ ɜɵɩɨɥɧɟɧɢɹ ɨɩɟɪɚɰɢɣ ɧɚɞ ɤɨɦɩɥɟɤɫɧɵɦɢ ɱɢɫɥɚɦɢ ɢɥɢ ɤɜɚɞɪɚɬɧɵɦɢ ɦɚɬɪɢɰɚɦɢ, ɠɟɥɚɬɟɥɶɧɨ, ɱɬɨɛɵ ɜ ɩɪɨɝɪɚɦɦɟ ɹɜɧɨ ɩɪɢɫɭɬɫɬɜɨɜɚɥɢ ɨɩɟɪɚɬɨɪɵ ɫɥɨɠɟɧɢɹ, ɜɵɱɢɬɚɧɢɹ, ɭɦɧɨɠɟɧɢɹ ɢ ɞɟɥɟɧɢɹ ɞɚɧɧɵɯ ɬɢɩɚ «ɤɨɦɩɥɟɤɫɧɵɟ ɱɢɫɥɚ», ɫɥɨɠɟɧɢɹ, ɜɵɱɢɬɚɧɢɹ, ɭɦɧɨɠɟɧɢɹ ɢ ɨɛɪɚɳɟɧɢɹ ɞɚɧɧɵɯ ɬɢɩɚ «ɤɜɚɞɪɚɬɧɵɟ ɦɚɬɪɢɰɵ». Ɋɟɲɟɧɢɟ ɷɬɨɣ ɩɪɨɛɥɟɦɵ ɞɨɫɬɢɠɢɦɨ ɧɟɫɤɨɥɶɤɢɦɢ ɩɭɬɹɦɢ: x ɩɨɫɬɪɨɟɧɢɟɦ ɹɡɵɤɚ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ, ɫɨɞɟɪɠɚɳɟɝɨ ɤɚɤ ɦɨɠɧɨ ɛɨɥɶɲɟ ɬɢɩɨɜ ɞɚɧɧɵɯ, ɢ ɜɵɛɨɪɨɦ ɞɥɹ ɤɚɠɞɨɝɨ ɤɥɚɫɫɚ ɡɚɞɚɱ ɧɟɤɨɬɨɪɨɝɨ ɩɨɞɦɧɨɠɟɫɬɜɚ ɷɬɨɝɨ ɹɡɵɤɚ. Ɍɚɤɨɣ ɹɡɵɤ ɢɧɨɝɞɚ ɧɚɡɵɜɚɸɬ ɹɡɵɤɨɦ-ɨɛɨɥɨɱɤɨɣ. ɇɚ ɪɨɥɶ ɹɡɵɤɚ-ɨɛɨɥɨɱɤɢ ɩɪɟɬɟɧɞɨɜɚɥ ɹɡɵɤ ɉɅ/1 (PL/1), ɨɤɚɡɚɜɲɢɣɫɹ ɧɚɫɬɨɥɶɤɨ ɫɥɨɠɧɵɦ, ɱɬɨ ɬɚɤ ɢ ɧɟ ɭɞɚɥɨɫɶ ɩɨɫɬɪɨɢɬɶ ɟɝɨ ɮɨɪɦɚɥɢɡɨɜɚɧɧɨɟ ɨɩɢɫɚɧɢɟ. Ɉɬɫɭɬɫɬɜɢɟ ɮɨɪɦɚɥɢɡɨɜɚɧɧɨɝɨ ɨɩɢɫɚɧɢɹ, ɨɞɧɚɤɨ, ɧɟ ɩɨɦɟɲɚɥɨ ɲɢɪɨɤɨɦɭ ɩɪɢɦɟɧɟɧɢɸ ɉɅ/1 ɤɚɤ ɜ Ɂɚɩɚɞɧɨɣ ȿɜɪɨɩɟ, ɬɚɤ ɢ ɜ ɋɋɋɊ; x ɩɨɫɬɪɨɟɧɢɟɦ ɪɚɫɲɢɪɹɟɦɨɝɨ ɹɡɵɤɚ, ɫɨɞɟɪɠɚɳɟɝɨ ɧɟɛɨɥɶɲɨɟ ɹɞɪɨ ɢ ɞɨɩɭɫɤɚɸɳɟɝɨ ɪɚɫɲɢɪɟɧɢɟ, ɞɨɩɨɥɧɹɸɳɟɟ ɹɡɵɤ ɬɢɩɚɦɢ ɞɚɧɧɵɯ ɢ ɨɩɟɪɚɬɨɪɚɦɢ, ɨɬɪɚɠɚɸɳɢɦɢ ɤɨɧɰɟɩɬɭɚɥɶɧɭɸ ɫɭɳɧɨɫɬɶ ɤɨɧɤɪɟɬɧɨɝɨ ɤɥɚɫɫɚ ɡɚɞɚɱ. Ɍɚɤɨɣ ɹɡɵɤ ɧɚɡɵɜɚɸɬ ɹɡɵɤɨɦ-ɹɞɪɨɦ. Ʉɚɤ ɹɡɵɤ-ɹɞɪɨ ɛɵɥɢ ɪɚɡɪɚɛɨɬɚɧɵ ɹɡɵɤɢ ɋɢɦɭɥɚ (SIMULA) ɢ Ⱥɥɝɨɥ-68, ɧɟ ɩɨɥɭɱɢɜɲɢɟ ɲɢɪɨɤɨɝɨ ɪɚɫɩɪɨɫɬɪɚɧɟɧɢɹ, ɧɨ ɨɤɚɡɚɜɲɢɟ ɛɨɥɶɲɨɟ ɜɥɢɹɧɢɟ ɧɚ ɪɚɡɪɚɛɨɬɤɭ ɞɪɭɝɢɯ ɹɡɵɤɨɜ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ. Ⱦɚɥɶɧɟɣɲɢɦ ɪɚɡɜɢɬɢɟɦ ɜɬɨɪɨɝɨ ɩɭɬɢ ɹɜɢɥɫɹ ɨɛɴɟɤɬɧɨɨɪɢɟɧɬɢɪɨɜɚɧɧɵɣ ɩɨɞɯɨɞ ɤ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɸ, ɪɚɫɫɦɚɬɪɢɜɚɟɦɵɣ ɜ ɫɥɟɞɭɸɳɟɦ ɩɚɪɚɝɪɚɮɟ.
5
1.2. ɋɭɳɧɨɫɬɶ ɨɛɴɟɤɬɧɨ-ɨɪɢɟɧɬɢɪɨɜɚɧɧɨɝɨ ɩɨɞɯɨɞɚ ɤ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɸ Ɉɫɧɨɜɧɵɟ ɢɞɟɢ ɨɛɴɟɤɬɧɨ-ɨɪɢɟɧɬɢɪɨɜɚɧɧɨɝɨ ɩɨɞɯɨɞɚ ɨɩɢɪɚɸɬɫɹ ɧɚ ɫɥɟɞɭɸɳɢɟ ɩɨɥɨɠɟɧɢɹ: x ɩɪɨɝɪɚɦɦɚ ɩɪɟɞɫɬɚɜɥɹɟɬ ɫɨɛɨɣ ɦɨɞɟɥɶ ɧɟɤɨɬɨɪɨɝɨ ɪɟɚɥɶɧɨɝɨ ɩɪɨɰɟɫɫɚ, ɱɚɫɬɢ ɪɟɚɥɶɧɨɝɨ ɦɢɪɚ; x ɦɨɞɟɥɶ ɪɟɚɥɶɧɨɝɨ ɦɢɪɚ ɢɥɢ ɟɝɨ ɱɚɫɬɢ ɦɨɠɟɬ ɛɵɬɶ ɨɩɢɫɚɧɚ ɤɚɤ ɫɨɜɨɤɭɩɧɨɫɬɶ ɜɡɚɢɦɨɞɟɣɫɬɜɭɸɳɢɯ ɦɟɠɞɭ ɫɨɛɨɣ ɨɛɴɟɤɬɨɜ; x ɨɛɴɟɤɬ ɨɩɢɫɵɜɚɟɬɫɹ ɧɚɛɨɪɨɦ ɩɚɪɚɦɟɬɪɨɜ, ɡɧɚɱɟɧɢɹ ɤɨɬɨɪɵɯ ɨɩɪɟɞɟɥɹɸɬ ɫɨɫɬɨɹɧɢɟ ɨɛɴɟɤɬɚ, ɢ ɧɚɛɨɪɨɦ ɨɩɟɪɚɰɢɣ (ɞɟɣɫɬɜɢɣ), ɤɨɬɨɪɵɟ ɦɨɠɟɬ ɜɵɩɨɥɧɹɬɶ ɨɛɴɟɤɬ; x ɜɡɚɢɦɨɞɟɣɫɬɜɢɟ ɦɟɠɞɭ ɨɛɴɟɤɬɚɦɢ ɨɫɭɳɟɫɬɜɥɹɟɬɫɹ ɩɨɫɵɥɤɨɣ ɫɩɟɰɢɚɥɶɧɵɯ ɫɨɨɛɳɟɧɢɣ ɨɬ ɨɞɧɨɝɨ ɨɛɴɟɤɬɚ ɤ ɞɪɭɝɨɦɭ. ɋɨɨɛɳɟɧɢɟ, ɩɨɥɭɱɟɧɧɨɟ ɨɛɴɟɤɬɨɦ, ɦɨɠɟɬ ɩɨɬɪɟɛɨɜɚɬɶ ɜɵɩɨɥɧɟɧɢɹ ɨɩɪɟɞɟɥɟɧɧɵɯ ɞɟɣɫɬɜɢɣ, ɧɚɩɪɢɦɟɪ, ɢɡɦɟɧɟɧɢɹ ɫɨɫɬɨɹɧɢɹ ɨɛɴɟɤɬɚ; x ɨɛɴɟɤɬɵ, ɨɩɢɫɚɧɧɵɟ ɨɞɧɢɦ ɢ ɬɟɦ ɠɟ ɧɚɛɨɪɨɦ ɩɚɪɚɦɟɬɪɨɜ ɢ ɫɩɨɫɨɛɧɵɟ ɜɵɩɨɥɧɹɬɶ ɨɞɢɧ ɢ ɬɨɬ ɠɟ ɧɚɛɨɪ ɞɟɣɫɬɜɢɣ, ɩɪɟɞɫɬɚɜɥɹɸɬ ɫɨɛɨɣ ɤɥɚɫɫ ɨɞɧɨɬɢɩɧɵɯ ɨɛɴɟɤɬɨɜ. ɋ ɬɨɱɤɢ ɡɪɟɧɢɹ ɹɡɵɤɚ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ ɤɥɚɫɫ ɨɛɴɟɤɬɨɜ ɦɨɠɧɨ ɪɚɫɫɦɚɬɪɢɜɚɬɶ ɤɚɤ ɬɢɩ ɞɚɧɧɨɝɨ, ɚ ɨɬɞɟɥɶɧɵɣ ɨɛɴɟɤɬ – ɤɚɤ ɩɟɪɟɦɟɧɧɭɸ ɷɬɨɝɨ ɬɢɩɚ. Ɉɩɪɟɞɟɥɟɧɢɟ ɩɪɨɝɪɚɦɦɢɫɬɨɦ ɫɨɛɫɬɜɟɧɧɵɯ ɤɥɚɫɫɨɜ ɨɛɴɟɤɬɨɜ ɞɥɹ ɤɨɧɤɪɟɬɧɨɝɨ ɧɚɛɨɪɚ ɡɚɞɚɱ ɞɨɥɠɧɨ ɩɨɡɜɨɥɢɬɶ ɨɩɢɫɵɜɚɬɶ ɨɬɞɟɥɶɧɵɟ ɡɚɞɚɱɢ ɜ ɬɟɪɦɢɧɚɯ ɫɚɦɨɝɨ ɤɥɚɫɫɚ ɡɚɞɚɱ (ɩɪɢ ɫɨɨɬɜɟɬɫɬɜɭɸɳɟɦ ɜɵɛɨɪɟ ɢɦɟɧ ɬɢɩɨɜ ɢ ɢɦɟɧ ɨɛɴɟɤɬɨɜ, ɢɯ ɩɚɪɚɦɟɬɪɨɜ ɢ ɜɵɩɨɥɧɹɟɦɵɯ ɞɟɣɫɬɜɢɣ). Ɍɚɤɢɦ ɨɛɪɚɡɨɦ, ɨɛɴɟɤɬɧɨ-ɨɪɢɟɧɬɢɪɨɜɚɧɧɵɣ ɩɨɞɯɨɞ ɩɪɟɞɩɨɥɚɝɚɟɬ, ɱɬɨ ɩɪɢ ɪɚɡɪɚɛɨɬɤɟ ɩɪɨɝɪɚɦɦɵ ɞɨɥɠɧɵ ɛɵɬɶ ɨɩɪɟɞɟɥɟɧɵ ɤɥɚɫɫɵ ɢɫɩɨɥɶɡɭɟɦɵɯ ɜ ɩɪɨɝɪɚɦɦɟ ɨɛɴɟɤɬɨɜ ɢ ɩɨɫɬɪɨɟɧɵ ɢɯ ɨɩɢɫɚɧɢɹ, ɡɚɬɟɦ ɫɨɡɞɚɧɵ ɷɤɡɟɦɩɥɹɪɵ ɧɟɨɛɯɨɞɢɦɵɯ ɨɛɴɟɤɬɨɜ ɢ ɨɩɪɟɞɟɥɟɧɨ ɜɡɚɢɦɨɞɟɣɫɬɜɢɟ ɦɟɠɞɭ ɧɢɦɢ. Ʉɥɚɫɫɵ ɨɛɴɟɤɬɨɜ ɱɚɫɬɨ ɭɞɨɛɧɨ ɫɬɪɨɢɬɶ ɬɚɤ, ɱɬɨɛɵ ɨɧɢ ɨɛɪɚɡɨɜɵɜɚɥɢ ɢɟɪɚɪɯɢɱɟɫɤɭɸ ɫɬɪɭɤɬɭɪɭ. ɇɚɩɪɢɦɟɪ, ɤɥɚɫɫ «ɋɬɭɞɟɧɬ», ɨɩɢɫɵɜɚɸɳɢɣ ɚɛɫɬɪɚɤɬɧɨɝɨ ɫɬɭɞɟɧɬɚ, ɦɨɠɟɬ ɫɥɭɠɢɬɶ ɨɫɧɨɜɨɣ ɞɥɹ ɩɨɫɬɪɨɟɧɢɹ ɤɥɚɫɫɨɜ «ɋɬɭɞɟɧɬ 1-ɝɨ ɤɭɪɫɚ», «ɋɬɭɞɟɧɬ 2-ɝɨ ɤɭɪɫɚ» ɢ ɬɚɤ ɞɚɥɟɟ, ɤɨɬɨɪɵɟ ɨɛɥɚɞɚɸɬ ɜɫɟɦɢ ɫɜɨɣɫɬɜɚɦɢ ɫɬɭɞɟɧɬɚ ɜɨɨɛɳɟ ɢ ɧɟɤɨɬɨɪɵɦɢ ɞɨɩɨɥɧɢɬɟɥɶɧɵɦɢ ɫɜɨɣɫɬɜɚɦɢ, ɯɚɪɚɤɬɟɪɢɡɭɸɳɢɦɢ ɫɬɭɞɟɧɬɚ ɤɨɧɤɪɟɬɧɨɝɨ ɤɭɪɫɚ. ɉɪɢ ɪɚɡɪɚɛɨɬɤɟ ɢɧɬɟɪɮɟɣɫɚ ɫ ɩɨɥɶɡɨɜɚɬɟɥɟɦ ɩɪɨɝɪɚɦɦɵ ɦɨɝɭɬ ɢɫɩɨɥɶɡɨɜɚɬɶ ɨɛɴɟɤɬɵ ɨɛɳɟɝɨ ɤɥɚɫɫɚ «Ɉɤɧɨ» ɢ ɨɛɴɟɤɬɵ ɤɥɚɫɫɨɜ ɫɩɟɰɢɚɥɶɧɵɯ ɨɤɨɧ, ɧɚɩɪɢɦɟɪ, ɨɤɨɧ ɢɧɮɨɪɦɚɰɢɨɧɧɵɯ ɫɨɨɛɳɟɧɢɣ, ɨɤɨɧ ɜɜɨɞɚ ɞɚɧɧɵɯ ɢ ɬ.ɩ. ȼ ɬɚɤɢɯ ɢɟɪɚɪɯɢɱɟɫɤɢɯ ɫɬɪɭɤɬɭɪɚɯ ɨɞɢɧ ɤɥɚɫɫ ɦɨɠɟɬ ɪɚɫɫɦɚɬɪɢɜɚɬɶɫɹ ɤɚɤ ɛɚɡɨɜɵɣ ɞɥɹ ɞɪɭɝɢɯ, ɩɪɨɢɡɜɨɞɧɵɯ ɨɬ ɧɟɝɨ ɤɥɚɫɫɨɜ. Ɉɛɴɟɤɬ ɩɪɨɢɡɜɨɞɧɨɝɨ ɤɥɚɫɫɚ ɨɛɥɚɞɚɟɬ 6
ɜɫɟɦɢ ɫɜɨɣɫɬɜɚɦɢ ɛɚɡɨɜɨɝɨ ɤɥɚɫɫɚ ɢ ɧɟɤɨɬɨɪɵɦɢ ɫɨɛɫɬɜɟɧɧɵɦɢ ɫɜɨɣɫɬɜɚɦɢ, ɨɧ ɦɨɠɟɬ ɪɟɚɝɢɪɨɜɚɬɶ ɧɚ ɬɟ ɠɟ ɬɢɩɵ ɫɨɨɛɳɟɧɢɣ ɨɬ ɞɪɭɝɢɯ ɨɛɴɟɤɬɨɜ, ɱɬɨ ɢ ɨɛɴɟɤɬ ɛɚɡɨɜɨɝɨ ɤɥɚɫɫɚ, ɢ ɧɚ ɫɨɨɛɳɟɧɢɹ, ɢɦɟɸɳɢɟ ɫɦɵɫɥ ɬɨɥɶɤɨ ɞɥɹ ɩɪɨɢɡɜɨɞɧɨɝɨ ɤɥɚɫɫɚ. Ɉɛɵɱɧɨ ɝɨɜɨɪɹɬ, ɱɬɨ ɨɛɴɟɤɬ ɩɪɨɢɡɜɨɞɧɨɝɨ ɤɥɚɫɫɚ ɧɚɫɥɟɞɭɟɬ ɜɫɟ ɫɜɨɣɫɬɜɚ ɫɜɨɟɝɨ ɛɚɡɨɜɨɝɨ ɤɥɚɫɫɚ. ɇɟɤɨɬɨɪɵɟ ɩɚɪɚɦɟɬɪɵ ɨɛɴɟɤɬɚ ɦɨɝɭɬ ɛɵɬɶ ɥɨɤɚɥɢɡɨɜɚɧɵ ɜɧɭɬɪɢ ɨɛɴɟɤɬɚ ɢ ɧɟɞɨɫɬɭɩɧɵ ɞɥɹ ɩɪɹɦɨɝɨ ɜɨɡɞɟɣɫɬɜɢɹ ɢɡɜɧɟ ɧɚ ɨɛɴɟɤɬ. ɇɚɩɪɢɦɟɪ, ɜɨ ɜɪɟɦɹ ɞɜɢɠɟɧɢɹ ɨɛɴɟɤɬɚ-ɚɜɬɨɦɨɛɢɥɹ ɨɛɴɟɤɬ-ɜɨɞɢɬɟɥɶ ɦɨɠɟɬ ɜɨɡɞɟɣɫɬɜɨɜɚɬɶ ɬɨɥɶɤɨ ɧɚ ɨɝɪɚɧɢɱɟɧɧɵɣ ɧɚɛɨɪ ɨɪɝɚɧɨɜ ɭɩɪɚɜɥɟɧɢɹ (ɪɭɥɟɜɨɟ ɤɨɥɟɫɨ, ɩɟɞɚɥɢ ɝɚɡɚ, ɫɰɟɩɥɟɧɢɹ ɢ ɬɨɪɦɨɡɚ, ɪɵɱɚɝ ɩɟɪɟɤɥɸɱɟɧɢɹ ɩɟɪɟɞɚɱ) ɢ ɟɦɭ ɧɟɞɨɫɬɭɩɟɧ ɰɟɥɵɣ ɪɹɞ ɩɚɪɚɦɟɬɪɨɜ, ɯɚɪɚɤɬɟɪɢɡɭɸɳɢɯ ɫɨɫɬɨɹɧɢɟ ɞɜɢɝɚɬɟɥɹ ɢ ɚɜɬɨɦɨɛɢɥɹ ɜ ɰɟɥɨɦ. Ɉɱɟɜɢɞɧɨ, ɞɥɹ ɬɨɝɨ, ɱɬɨɛɵ ɩɪɨɞɭɤɬɢɜɧɨ ɩɪɢɦɟɧɹɬɶ ɨɛɴɟɤɬɧɵɣ ɩɨɞɯɨɞ ɞɥɹ ɪɚɡɪɚɛɨɬɤɢ ɩɪɨɝɪɚɦɦ, ɧɟɨɛɯɨɞɢɦɵ ɹɡɵɤɢ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ, ɩɨɞɞɟɪɠɢɜɚɸɳɢɟ ɷɬɨɬ ɩɨɞɯɨɞ, ɬ. ɟ. ɩɨɡɜɨɥɹɸɳɢɟ ɫɬɪɨɢɬɶ ɨɩɢɫɚɧɢɟ ɤɥɚɫɫɨɜ ɨɛɴɟɤɬɨɜ, ɨɛɪɚɡɨɜɵɜɚɬɶ ɞɚɧɧɵɟ ɨɛɴɟɤɬɧɵɯ ɬɢɩɨɜ, ɜɵɩɨɥɧɹɬɶ ɨɩɟɪɚɰɢɢ ɧɚɞ ɨɛɴɟɤɬɚɦɢ. Ɉɞɧɢɦ ɢɡ ɩɟɪɜɵɯ ɬɚɤɢɯ ɹɡɵɤɨɜ ɫɬɚɥ ɹɡɵɤ SmallTalk, ɜ ɤɨɬɨɪɨɦ ɜɫɟ ɞɚɧɧɵɟ ɹɜɥɹɸɬɫɹ ɨɛɴɟɤɬɚɦɢ ɧɟɤɨɬɨɪɵɯ ɤɥɚɫɫɨɜ, ɚ ɨɛɳɚɹ ɫɢɫɬɟɦɚ ɤɥɚɫɫɨɜ ɫɬɪɨɢɬɫɹ ɤɚɤ ɢɟɪɚɪɯɢɱɟɫɤɚɹ ɫɬɪɭɤɬɭɪɚ ɧɚ ɨɫɧɨɜɟ ɩɪɟɞɨɩɪɟɞɟɥɟɧɧɵɯ ɛɚɡɨɜɵɯ ɤɥɚɫɫɨɜ. Ɉɩɵɬ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ ɩɨɤɚɡɵɜɚɟɬ, ɱɬɨ ɥɸɛɨɣ ɦɟɬɨɞɨɥɨɝɢɱɟɫɤɢɣ ɩɨɞɯɨɞ ɜ ɬɟɯɧɨɥɨɝɢɢ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ ɧɟ ɞɨɥɠɟɧ ɩɪɢɦɟɧɹɬɶɫɹ ɫɥɟɩɨ ɫ ɢɝɧɨɪɢɪɨɜɚɧɢɟɦ ɞɪɭɝɢɯ ɩɨɞɯɨɞɨɜ. ɗɬɨ ɨɬɧɨɫɢɬɫɹ ɢ ɤ ɨɛɴɟɤɬɧɨɨɪɢɟɧɬɢɪɨɜɚɧɧɨɦɭ ɩɨɞɯɨɞɭ. ɋɭɳɟɫɬɜɭɟɬ ɪɹɞ ɬɢɩɨɜɵɯ ɩɪɨɛɥɟɦ, ɞɥɹ ɤɨɬɨɪɵɯ ɟɝɨ ɩɨɥɟɡɧɨɫɬɶ ɧɚɢɛɨɥɟɟ ɨɱɟɜɢɞɧɚ, ɤ ɬɚɤɢɦ ɩɪɨɛɥɟɦɚɦ ɨɬɧɨɫɹɬɫɹ, ɜ ɱɚɫɬɧɨɫɬɢ, ɡɚɞɚɱɢ ɢɦɢɬɚɰɢɨɧɧɨɝɨ ɦɨɞɟɥɢɪɨɜɚɧɢɹ, ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɟ ɞɢɚɥɨɝɨɜ ɫ ɩɨɥɶɡɨɜɚɬɟɥɟɦ. ɋɭɳɟɫɬɜɭɸɬ ɢ ɡɚɞɚɱɢ, ɜ ɤɨɬɨɪɵɯ ɩɪɢɦɟɧɟɧɢɟ ɨɛɴɟɤɬɧɨɝɨ ɩɨɞɯɨɞɚ ɧɢ ɤ ɱɟɦɭ, ɤɪɨɦɟ ɢɡɥɢɲɧɢɯ ɡɚɬɪɚɬ ɬɪɭɞɚ, ɧɟ ɩɪɢɜɟɞɟɬ. ȼ ɫɜɹɡɢ ɫ ɷɬɢɦ ɧɚɢɛɨɥɶɲɟɟ ɪɚɫɩɪɨɫɬɪɚɧɟɧɢɟ ɩɨɥɭɱɢɥɢ ɨɛɴɟɤɬɧɨɨɪɢɟɧɬɢɪɨɜɚɧɧɵɟ ɹɡɵɤɢ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ, ɩɨɡɜɨɥɹɸɳɢɟ ɫɨɱɟɬɚɬɶ ɨɛɴɟɤɬɧɵɣ ɩɨɞɯɨɞ ɫ ɞɪɭɝɢɦɢ ɦɟɬɨɞɨɥɨɝɢɹɦɢ. ȼ ɧɟɤɨɬɨɪɵɯ ɹɡɵɤɚɯ ɢ ɫɢɫɬɟɦɚɯ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ ɩɪɢɦɟɧɟɧɢɟ ɨɛɴɟɤɬɧɨɝɨ ɩɨɞɯɨɞɚ ɨɝɪɚɧɢɱɢɜɚɟɬɫɹ ɫɪɟɞɫɬɜɚɦɢ ɢɧɬɟɪɮɟɣɫɚ ɫ ɩɨɥɶɡɨɜɚɬɟɥɟɦ (ɧɚɩɪɢɦɟɪ, Visual FoxPro ɪɚɧɧɢɯ ɜɟɪɫɢɣ). ɇɚɢɛɨɥɟɟ ɢɫɩɨɥɶɡɭɟɦɵɦɢ ɜ ɧɚɫɬɨɹɳɟɟ ɜɪɟɦɹ ɨɛɴɟɤɬɧɨɨɪɢɟɧɬɢɪɨɜɚɧɧɵɦɢ ɹɡɵɤɚɦɢ ɹɜɥɹɸɬɫɹ ɉɚɫɤɚɥɶ ɫ ɨɛɴɟɤɬɚɦɢ ɢ ɋɢ++ (ɋ++), ɩɪɢɱɟɦ ɧɚɢɛɨɥɟɟ ɪɚɡɜɢɬɵɟ ɫɪɟɞɫɬɜɚ ɞɥɹ ɪɚɛɨɬɵ ɫ ɨɛɴɟɤɬɚɦɢ ɫɨɞɟɪɠɚɬɫɹ ɜ ɋɢ++. ɉɪɚɤɬɢɱɟɫɤɢ ɜɫɟ ɨɛɴɟɤɬɧɨ-ɨɪɢɟɧɬɢɪɨɜɚɧɧɵɟ ɹɡɵɤɢ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ ɹɜɥɹɸɬɫɹ ɪɚɡɜɢɜɚɸɳɢɦɢɫɹ ɹɡɵɤɚɦɢ, ɢɯ ɫɬɚɧɞɚɪɬɵ ɪɟɝɭɥɹɪɧɨ ɭɬɨɱɧɹɸɬɫɹ ɢ ɪɚɫɲɢɪɹɸɬɫɹ. ɋɥɟɞɫɬɜɢɟɦ ɷɬɨɝɨ ɪɚɡɜɢɬɢɹ ɹɜɥɹɸɬɫɹ ɧɟɢɡɛɟɠɧɵɟ ɪɚɡɥɢɱɢɹ ɜɨ ɜɯɨɞɧɵɯ ɹɡɵɤɚɯ ɤɨɦɩɢɥɹɬɨɪɨɜ ɪɚɡɥɢɱɧɵɯ ɫɢɫɬɟɦ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ. ɇɚɢɛɨɥɟɟ ɪɚɫɩɪɨɫɬɪɚɧɟɧɧɵɦɢ ɜ ɧɚɫɬɨɹɳɟɟ ɜɪɟɦɹ ɹɜɥɹɸɬɫɹ ɫɢɫɬɟɦɵ ɩɪɨ7
ɝɪɚɦɦɢɪɨɜɚɧɢɹ Microsoft C++ , Microsoft Visual C++ ɢ ɫɢɫɬɟɦɵ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ ɮɢɪɦɵ Borland International. Ⱦɚɥɶɧɟɣɲɢɣ ɦɚɬɟɪɢɚɥ ɜ ɞɚɧɧɨɦ ɩɨɫɨɛɢɢ ɢɡɥɚɝɚɟɬɫɹ ɩɪɢɦɟɧɢɬɟɥɶɧɨ ɤ ɫɢɫɬɟɦɟ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ Borland C++. ɗɬɨ ɫɜɹɡɚɧɨ, ɩɪɟɠɞɟ ɜɫɟɝɨ, ɫ ɧɚɥɢɱɢɟɦ ɜ ɷɬɨɣ ɫɢɫɬɟɦɟ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ ɪɚɡɜɢɬɨɣ ɢɧɬɟɝɪɢɪɨɜɚɧɧɨɣ ɫɪɟɞɵ, ɨɛɴɟɞɢɧɹɸɳɟɣ ɬɟɤɫɬɨɜɵɣ ɪɟɞɚɤɬɨɪ, ɤɨɦɩɢɥɹɬɨɪ, ɪɟɞɚɤɬɨɪ ɫɜɹɡɟɣ (ɤɨɦɩɨɧɨɜɳɢɤ) ɢ ɨɬɥɚɞɨɱɧɵɟ ɫɪɟɞɫɬɜɚ.
2. ɇɚɱɚɥɶɧɵɟ ɫɜɟɞɟɧɢɹ ɨ ɹɡɵɤɟ C++ 2.1. ɇɚɡɧɚɱɟɧɢɟ ɹɡɵɤɚ C++, ɢɫɬɨɪɢɱɟɫɤɢɟ ɫɜɟɞɟɧɢɹ əɡɵɤ ɋɢ ɛɵɥ ɪɚɡɪɚɛɨɬɚɧ ɜ 70-ɟ ɝɨɞɵ ɤɚɤ ɹɡɵɤ ɫɢɫɬɟɦɧɨɝɨ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ. ɉɪɢ ɷɬɨɦ ɫɬɚɜɢɥɚɫɶ ɡɚɞɚɱɚ ɩɨɥɭɱɢɬɶ ɹɡɵɤ, ɨɛɟɫɩɟɱɢɜɚɸɳɢɣ ɪɟɚɥɢɡɚɰɢɸ ɢɞɟɣ ɩɪɨɰɟɞɭɪɧɨɝɨ ɢ ɫɬɪɭɤɬɭɪɧɨɝɨ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ ɢ ɜɨɡɦɨɠɧɨɫɬɶ ɪɟɚɥɢɡɚɰɢɢ ɫɩɟɰɢɮɢɱɟɫɤɢɯ ɩɪɢɟɦɨɜ ɫɢɫɬɟɦɧɨɝɨ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ. Ɍɚɤɨɣ ɹɡɵɤ ɩɨɡɜɨɥɢɥ ɛɵ ɪɚɡɪɚɛɚɬɵɜɚɬɶ ɫɥɨɠɧɵɟ ɩɪɨɝɪɚɦɦɵ ɧɚ ɭɪɨɜɧɟ, ɫɪɚɜɧɢɦɨɦ ɫ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɟɦ ɧɚ Ⱥɫɫɟɦɛɥɟɪɟ, ɧɨ ɫɭɳɟɫɬɜɟɧɧɨ ɛɵɫɬɪɟɟ. ɗɬɢ ɰɟɥɢ ɜ ɨɫɧɨɜɧɨɦ ɛɵɥɢ ɞɨɫɬɢɝɧɭɬɵ. Ȼɨɥɶɲɢɧɫɬɜɨ ɤɨɦɩɢɥɹɬɨɪɨɜ ɞɥɹ ɋɢ ɧɚɩɢɫɚɧɵ ɧɚ ɹɡɵɤɟ ɋɢ. Ɉɩɟɪɚɰɢɨɧɧɚɹ ɫɢɫɬɟɦɚ UNIX ɬɚɤɠɟ ɩɨɱɬɢ ɩɨɥɧɨɫɬɶɸ ɧɚɩɢɫɚɧɚ ɧɚ ɋɢ. ɇɟɞɨɫɬɚɬɤɨɦ ɋɢ ɨɤɚɡɚɥɚɫɶ ɧɢɡɤɚɹ ɧɚɞɟɠɧɨɫɬɶ ɪɚɡɪɚɛɚɬɵɜɚɟɦɵɯ ɩɪɨɝɪɚɦɦ ɢɡ-ɡɚ ɨɬɫɭɬɫɬɜɢɹ ɤɨɧɬɪɨɥɹ ɬɢɩɨɜ. ɉɨɩɵɬɤɚ ɩɨɩɪɚɜɢɬɶ ɞɟɥɨ ɜɤɥɸɱɟɧɢɟɦ ɜ ɫɢɫɬɟɦɭ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ ɋɢ ɨɬɞɟɥɶɧɨɣ ɩɪɨɝɪɚɦɦɵ, ɤɨɧɬɪɨɥɢɪɭɸɳɟɣ ɧɟɹɜɧɵɟ ɩɪɟɨɛɪɚɡɨɜɚɧɢɹ ɬɢɩɨɜ, ɪɟɲɢɥɚ ɷɬɭ ɩɪɨɛɥɟɦɭ ɥɢɲɶ ɱɚɫɬɢɱɧɨ. ɇɚ ɨɫɧɨɜɟ ɋɢ ɜ 80-ɟ ɝɨɞɵ ɛɵɥ ɪɚɡɪɚɛɨɬɚɧ ɹɡɵɤ ɋɢ++, ɜɧɚɱɚɥɟ ɧɚɡɜɚɧɧɵɣ «ɋɢ ɫ ɤɥɚɫɫɚɦɢ». ɋɢ++ ɩɪɚɤɬɢɱɟɫɤɢ ɜɤɥɸɱɚɟɬ ɹɡɵɤ ɋɢ, ɤɨɬɨɪɵɣ ɞɨɩɨɥɧɟɧ ɫɪɟɞɫɬɜɚɦɢ ɨɛɴɟɤɬɧɨ-ɨɪɢɟɧɬɢɪɨɜɚɧɧɨɝɨ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ. Ɋɚɛɨɱɚɹ ɜɟɪɫɢɹ ɋɢ++ ɩɨɹɜɢɥɚɫɶ ɜ 1983ɝ. ɋ ɬɟɯ ɩɨɪ ɹɡɵɤ ɩɪɨɞɨɥɠɚɟɬ ɪɚɡɜɢɜɚɬɶɫɹ, ɢ ɨɩɭɛɥɢɤɨɜɚɧɨ ɧɟɫɤɨɥɶɤɨ ɜɟɪɫɢɣ ɩɪɨɟɤɬɚ ɫɬɚɧɞɚɪɬɨɜ ɋɢ ɢ ɋɢ++. Ɋɹɞɨɦ ɮɢɪɦ, ɩɪɨɢɡɜɨɞɹɳɢɯ ɩɪɨɝɪɚɦɦɧɨɟ ɨɛɟɫɩɟɱɟɧɢɟ, ɪɚɡɪɚɛɨɬɚɧɵ ɤɨɦɩɢɥɹɬɨɪɵ ɞɥɹ ɋɢ ɢ ɋɢ++. ɋɢɫɬɟɦɵ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ ɮɢɪɦɵ Borland International ɜɵɞɟɥɹɸɬɫɹ ɫɪɟɞɢ ɞɪɭɝɢɯ ɮɢɪɦ, ɩɪɟɠɞɟ ɜɫɟɝɨ, ɤɨɦɩɥɟɤɫɧɵɦ ɩɨɞɯɨɞɨɦ ɤ ɪɚɡɪɚɛɨɬɤɟ ɩɪɨɝɪɚɦɦ. Ɉɧɢ ɩɪɟɞɫɬɚɜɥɹɸɬ ɫɨɛɨɣ ɢɧɬɟɝɪɢɪɨɜɚɧɧɭɸ ɫɪɟɞɭ ɪɚɡɪɚɛɨɬɱɢɤɚ, ɨɛɴɟɞɢɧɹɸɳɭɸ ɩɨɞ ɨɛɳɢɦ ɭɩɪɚɜɥɟɧɢɟɦ ɬɟɤɫɬɨɜɵɣ ɪɟɞɚɤɬɨɪ ɞɥɹ ɜɜɨɞɚ ɢɫɯɨɞɧɵɯ ɬɟɤɫɬɨɜ ɩɪɨɝɪɚɦɦ, ɤɨɦɩɢɥɹɬɨɪ, ɪɟɞɚɤɬɨɪ ɫɜɹɡɟɣ ɢ ɧɚɛɨɪ ɨɬɥɚɞɨɱɧɵɯ ɫɪɟɞɫɬɜ. ȼ 1989ɝ. ɷɬɨɣ ɮɢɪɦɨɣ ɛɵɥɚ ɜɵɩɭɳɟɧɚ ɫɢɫɬɟɦɚ Turbo C++, ɜɤɥɸɱɚɸɳɚɹ ɜ ɫɟɛɹ ɤɨɦɩɢɥɹɬɨɪ ɋɢ++, ɪɚɛɨɬɚɸɳɢɣ ɜ ɨɩɟɪɚɰɢɨɧɧɨɣ ɫɢɫɬɟɦɟ MS DOS. ɋ 1992ɝ. ɜɵɩɭɫɤɚɸɬɫɹ ɫɢɫɬɟɦɵ Borland C++, ɫɨɞɟɪɠɚɳɢɟ ɤɨɦɩɢɥɹɬɨɪɵ ɋɢ++ ɞɥɹ MS DOS ɢ MS WINDOWS, ɫ 1997ɝ. ɩɨɫɬɚɜɥɹɟɬɫɹ ɜɟɪɫɢɹ Borland C 5.0, ɫɨɞɟɪɠɚɳɚɹ ɤɨɦɩɢɥɹɬɨɪɵ ɋɢ++ ɞɥɹ MS WINDOWS, ɩɪɢɱɟɦ ɞɚɧɧɵɣ ɤɨɦɩɢɥɹɬɨɪ ɞɥɹ MS WINDOWS ɩɨ8
ɡɜɨɥɹɟɬ ɪɚɡɪɚɛɚɬɵɜɚɬɶ ɤɚɤ 16-ɪɚɡɪɹɞɧɵɟ, ɬɚɤ ɢ 32-ɪɚɡɪɹɞɧɵɟ ɜɚɪɢɚɧɬɵ ɩɪɨɝɪɚɦɦ ɞɥɹ ɉɗȼɆ ɫ ɩɪɨɰɟɫɫɨɪɚɦɢ i486 ɢ Pentium. ɉɪɨɝɪɚɦɦɚ ɧɚ ɋɢ/ɋɢ++ ɩɪɟɞɫɬɚɜɥɹɟɬ ɫɨɛɨɣ ɨɞɢɧ ɢɥɢ ɧɟɫɤɨɥɶɤɨ ɢɫɯɨɞɧɵɯ ɮɚɣɥɨɜ, ɤɨɬɨɪɵɟ ɦɨɝɭɬ ɬɪɚɧɫɥɢɪɨɜɚɬɶɫɹ ɪɚɡɞɟɥɶɧɨ. Ɋɟɡɭɥɶɬɚɬɵ ɬɪɚɧɫɥɹɰɢɢ (ɨɛɴɟɤɬɧɵɟ ɮɚɣɥɵ) ɨɛɴɟɞɢɧɹɸɬɫɹ ɜ ɢɫɩɨɥɧɹɟɦɵɣ ɮɚɣɥ ɪɟɞɚɤɬɨɪɨɦ ɫɜɹɡɟɣ (ɤɨɦɩɨɧɨɜɳɢɤɨɦ). Ɉɛɵɱɧɨ ɪɚɡɥɢɱɚɸɬ ɞɜɚ ɬɢɩɚ ɢɫɯɨɞɧɵɯ ɮɚɣɥɨɜ: ɮɚɣɥɵ ɡɚɝɨɥɨɜɤɨɜ ɢ ɩɪɨɝɪɚɦɦɧɵɟ ɮɚɣɥɵ. Ɏɚɣɥɵ ɡɚɝɨɥɨɜɤɨɜ ɫɨɞɟɪɠɚɬ ɨɩɢɫɚɧɢɹ ɬɢɩɨɜ ɞɚɧɧɵɯ ɢ ɩɪɨɬɨɬɢɩɨɜ ɮɭɧɤɰɢɣ ɢ ɩɪɟɞɧɚɡɧɚɱɟɧɵ ɞɥɹ ɜɤɥɸɱɟɧɢɹ ɜ ɩɪɨɝɪɚɦɦɧɵɟ ɮɚɣɥɵ ɩɟɪɟɞ ɢɯ ɤɨɦɩɢɥɹɰɢɟɣ. ɂɯ ɢɦɟɧɚ, ɤɚɤ ɩɪɚɜɢɥɨ, ɢɦɟɸɬ ɪɚɫɲɢɪɟɧɢɟ .h, ɧɚɩɪɢɦɟɪ, stdio.h. ɉɪɨɝɪɚɦɦɧɵɟ ɮɚɣɥɵ ɫɨɞɟɪɠɚɬ ɨɩɢɫɚɧɢɹ ɮɭɧɤɰɢɣ ɢ, ɜɨɡɦɨɠɧɨ, ɝɥɨɛɚɥɶɧɵɯ ɩɟɪɟɦɟɧɧɵɯ ɢ ɤɨɧɫɬɚɧɬ, ɢɯ ɢɦɟɧɚ ɩɪɢɧɹɬɨ ɡɚɩɢɫɵɜɚɬɶ ɫ ɪɚɫɲɢɪɟɧɢɹɦɢ .c ɢɥɢ .cpp, ɧɚɩɪɢɦɟɪ, myprog.cpp. Ɉɞɢɧ ɢ ɬɨɬ ɠɟ ɮɚɣɥ ɡɚɝɨɥɨɜɤɨɜ ɦɨɠɟɬ ɜɤɥɸɱɚɬɶɫɹ ɜ ɧɟɫɤɨɥɶɤɨ ɩɪɨɝɪɚɦɦɧɵɯ ɮɚɣɥɨɜ. Ʉɚɠɞɵɣ ɮɚɣɥ ɫɨɞɟɪɠɢɬ ɩɨɫɥɟɞɨɜɚɬɟɥɶɧɨɫɬɶ ɬɚɤ ɧɚɡɵɜɚɟɦɵɯ «ɜɧɟɲɧɢɯ ɨɩɪɟɞɟɥɟɧɢɣ», ɨɩɢɫɵɜɚɸɳɢɯ ɬɢɩɵ ɞɚɧɧɵɯ, ɩɟɪɟɦɟɧɧɵɟ, ɤɨɧɫɬɚɧɬɵ ɢ ɮɭɧɤɰɢɢ. ȼ ɩɨɫɥɟɞɭɸɳɢɯ ɩɚɪɚɝɪɚɮɚɯ ɷɬɨɝɨ ɪɚɡɞɟɥɚ ɩɪɢɜɟɞɟɧ ɨɛɡɨɪ ɫɪɟɞɫɬɜ ɋɢ/ɋɢ++, ɧɟ ɫɜɹɡɚɧɧɵɯ ɫ ɨɛɴɟɤɬɧɨɣ ɨɪɢɟɧɬɚɰɢɟɣ ɋɢ++.
2.2. Ⱥɥɮɚɜɢɬ, ɛɚɡɨɜɵɟ ɬɢɩɵ ɢ ɨɩɢɫɚɧɢɟ ɞɚɧɧɵɯ Ⱥɥɮɚɜɢɬ ɹɡɵɤɚ ɜɤɥɸɱɚɟɬ ɩɪɚɤɬɢɱɟɫɤɢ ɜɫɟ ɫɢɦɜɨɥɵ, ɢɦɟɸɳɢɟɫɹ ɧɚ ɫɬɚɧɞɚɪɬɧɨɣ ɤɥɚɜɢɚɬɭɪɟ ɉɗȼɆ: - ɥɚɬɢɧɫɤɢɟ ɛɭɤɜɵ A...Z, a...z; - ɰɢɮɪɵ 0...9; - ɡɧɚɤɢ ɨɩɟɪɚɰɢɣ ɢ ɪɚɡɞɟɥɢɬɟɥɢ: { } [ ] ( ) . , -> & * + - ~ ! / % ? : ; = < > | # ^
ɇɟɤɨɬɨɪɵɟ ɨɩɟɪɚɰɢɢ ɨɛɨɡɧɚɱɚɸɬɫɹ ɤɨɦɛɢɧɚɰɢɹɦɢ ɫɢɦɜɨɥɨɜ, ɡɧɚɱɟɧɢɹ ɫɢɦɜɨɥɨɜ ɨɩɟɪɚɰɢɣ ɜ ɪɹɞɟ ɫɥɭɱɚɟɜ ɡɚɜɢɫɹɬ ɨɬ ɤɨɧɬɟɤɫɬɚ, ɜ ɤɨɬɨɪɨɦ ɨɧɢ ɭɩɨɬɪɟɛɥɟɧɵ. Ȼɚɡɨɜɵɟ (ɩɪɟɞɨɩɪɟɞɟɥɟɧɧɵɟ) ɬɢɩɵ ɞɚɧɧɵɯ ɨɛɴɟɞɢɧɟɧɵ ɜ ɞɜɟ ɝɪɭɩɩɵ: ɞɚɧɧɵɟ ɰɟɥɵɯ ɬɢɩɨɜ ɢ ɞɚɧɧɵɟ ɜɟɳɟɫɬɜɟɧɧɵɯ ɬɢɩɨɜ. Ⱦɚɧɧɵɟ ɰɟɥɵɯ ɬɢɩɨɜ ɦɨɝɭɬ ɛɵɬɶ ɨɛɵɱɧɵɦɢ ɰɟɥɵɦɢ ɫɨ ɡɧɚɤɨɦ (signed) ɢ ɰɟɥɵɦɢ ɛɟɡ ɡɧɚɤɚ (unsigned). ɉɨ ɱɢɫɥɭ ɪɚɡɪɹɞɨɜ, ɢɫɩɨɥɶɡɭɟɦɵɯ ɞɥɹ ɩɪɟɞɫɬɚɜɥɟɧɢɹ ɞɚɧɧɵɯ (ɞɢɚɩɚɡɨɧɭ ɡɧɚɱɟɧɢɣ), ɪɚɡɥɢɱɚɸɬ ɨɛɵɱɧɵɟ ɰɟɥɵɟ (int), ɤɨɪɨɬɤɢɟ ɰɟɥɵɟ (short int) ɢ ɞɥɢɧɧɵɟ ɰɟɥɵɟ (long int). ɋɢɦɜɨɥɶɧɵɟ ɞɚɧɧɵɟ (char) ɬɚɤɠɟ ɪɚɫɫɦɚɬɪɢɜɚɸɬɫɹ ɤɚɤ ɰɟɥɵɟ. Ʉɨɧɫɬɚɧɬɵ ɰɟɥɨɝɨ ɬɢɩɚ ɡɚɩɢɫɵɜɚɸɬɫɹ ɤɚɤ ɩɨɫɥɟɞɨɜɚɬɟɥɶɧɨɫɬɢ ɞɟɫɹɬɢɱɧɵɯ ɰɢɮɪ, ɬɢɩ ɤɨɧɫɬɚɧɬɵ ɡɚɜɢɫɢɬ ɨɬ ɱɢɫɥɚ ɰɢɮɪ ɜ ɡɚɩɢɫɢ ɤɨɧɫɬɚɧɬɵ ɢ ɦɨɠɟɬ ɛɵɬɶ ɭɬɨɱɧɟɧ ɞɨɛɚɜɥɟɧɢɟɦ ɜ ɤɨɧɰɟ ɤɨɧɫɬɚɧɬɵ ɛɭɤɜ L ɢɥɢ l (long), U ɢɥɢ u (unsigned) ɢɥɢ ɢɯ ɫɨɱɟɬɚɧɢɹ: 9
321 – ɤɨɧɫɬɚɧɬɚ ɬɢɩɚ int, 5326u – ɤɨɧɫɬɚɧɬɚ ɬɢɩɚ unsigned int, 45637778 – ɤɨɧɫɬɚɧɬɚ ɬɢɩɚ long int, 2746L – ɤɨɧɫɬɚɧɬɚ ɬɢɩɚ long int.
ɐɟɥɵɟ ɤɨɧɫɬɚɧɬɵ ɦɨɝɭɬ ɡɚɩɢɫɵɜɚɬɶɫɹ ɜ ɜɨɫɶɦɟɪɢɱɧɨɣ ɫɢɫɬɟɦɟ ɫɱɢɫɥɟɧɢɹ, ɜ ɷɬɨɦ ɫɥɭɱɚɟ ɩɟɪɜɨɣ ɰɢɮɪɨɣ ɞɨɥɠɧɚ ɛɵɬɶ ɰɢɮɪɚ 0, ɱɢɫɥɨ ɦɨɠɟɬ ɫɨɞɟɪɠɚɬɶ ɬɨɥɶɤɨ ɰɢɮɪɵ 0 ... 7: 0777 – ɤɨɧɫɬɚɧɬɚ ɬɢɩɚ int, 0453377 – ɤɨɧɫɬɚɧɬɚ ɬɢɩɚ long int. ɐɟɥɵɟ ɤɨɧɫɬɚɧɬɵ ɦɨɠɧɨ ɡɚɩɢɫɵɜɚɬɶ ɢ ɜ ɲɟɫɬɧɚɞɰɚɬɟɪɢɱɧɨɣ ɫɢɫɬɟɦɟ ɫɱɢɫɥɟɧɢɹ, ɜ ɷɬɨɦ ɫɥɭɱɚɟ ɡɚɩɢɫɶ ɤɨɧɫɬɚɧɬɵ ɧɚɱɢɧɚɟɬɫɹ ɫ ɫɢɦɜɨɥɨɜ 0x ɢɥɢ 0X: 0x45F – ɤɨɧɫɬɚɧɬɚ ɬɢɩɚ int, 0xFFFFFFFF – ɤɨɧɫɬɚɧɬɚ ɬɢɩɚ unsigned long int. Ʉɨɧɫɬɚɧɬɵ ɬɢɩɚ char ɜɫɟɝɞɚ ɡɚɤɥɸɱɚɸɬɫɹ ɜ ɨɞɢɧɨɱɧɵɟ ɤɚɜɵɱɤɢ, ɡɧɚ-
ɱɟɧɢɟ ɤɨɧɫɬɚɧɬɵ ɡɚɞɚɟɬɫɹ ɥɢɛɨ ɡɧɚɤɨɦ ɢɡ ɢɫɩɨɥɶɡɭɟɦɨɝɨ ɧɚɛɨɪɚ ɫɢɦɜɨɥɨɜ, ɥɢɛɨ ɰɟɥɨɣ ɤɨɧɫɬɚɧɬɨɣ, ɤɨɬɨɪɨɣ ɩɪɟɞɲɟɫɬɜɭɟɬ ɨɛɪɚɬɧɚɹ ɤɨɫɚɹ ɱɟɪɬɚ: 'A', '\33', '\042', '\x1B'. ɂɦɟɟɬɫɹ ɬɚɤɠɟ ɪɹɞ ɫɩɟɰɢɚɥɶɧɵɯ ɫɢɦɜɨɥɨɜ, ɤɨɬɨɪɵɟ ɦɨɝɭɬ ɭɤɚɡɵɜɚɬɶɫɹ ɜ ɤɚɱɟɫɬɜɟ ɡɧɚɱɟɧɢɣ ɤɨɧɫɬɚɧɬɵ ɬɢɩɚ char: '\n' – ɧɨɜɚɹ ɫɬɪɨɤɚ, '\t' – ɝɨɪɢɡɨɧɬɚɥɶɧɚɹ ɬɚɛɭɥɹɰɢɹ, '\v' – ɜɟɪɬɢɤɚɥɶɧɚɹ ɬɚɛɭɥɹɰɢɹ, '\r' – ɩɟɪɟɜɨɞ ɤɚɪɟɬɤɢ, '\f' – ɩɟɪɟɜɨɞ ɫɬɪɚɧɢɰɵ, '\a' – ɡɜɭɤɨɜɨɣ ɫɢɝɧɚɥ, '\'' – ɨɞɢɧɨɱɧɚɹ ɤɚɜɵɱɤɚ (ɚɩɨɫɬɪɨɮ), '\"' – ɞɜɨɣɧɚɹ ɤɚɜɵɱɤɚ, '\\' – ɨɛɪɚɬɧɚɹ ɤɨɫɚɹ ɱɟɪɬɚ. ȼɟɳɟɫɬɜɟɧɧɵɟ ɱɢɫɥɚ ɦɨɝɭɬ ɛɵɬɶ ɡɧɚɱɟɧɢɹɦɢ ɨɞɧɨɝɨ ɢɡ ɬɪɟɯ ɬɢɩɨɜ: float, double, long double. Ⱦɢɚɩɚɡɨɧ ɡɧɚɱɟɧɢɣ ɤɚɠɞɨɝɨ ɢɡ ɷɬɢɯ ɬɢɩɨɜ ɡɚɜɢɫɢɬ ɨɬ ɢɫɩɨɥɶɡɭɟɦɵɯ ɗȼɆ ɢ ɤɨɦɩɢɥɹɬɨɪɚ. Ʉɨɧɫɬɚɧɬɵ ɜɟɳɟɫɬɜɟɧɧɵɯ ɬɢɩɨɜ ɦɨɝɭɬ ɡɚɩɢɫɵɜɚɬɶɫɹ ɤɚɤ ɜ ɮɨɪɦɟ ɫ ɮɢɤɫɢɪɨɜɚɧɧɨɣ ɬɨɱɤɨɣ, ɬɚɤ ɢ ɜ ɷɤɫɩɨɧɟɧɰɢɚɥɶɧɨɣ ɮɨɪɦɟ. ɉɨ ɭɦɨɥɱɚɧɢɸ ɨɧɢ ɢɦɟɸɬ ɬɢɩ double, ɧɚɩɪɢɦɟɪ, 15.31, 1.43E-3, 2345.1e4. ɉɪɢ ɧɟɨɛɯɨɞɢɦɨɫɬɢ ɬɢɩ ɤɨɧɫɬɚɧɬɵ ɦɨɠɧɨ ɭɬɨɱɧɢɬɶ, ɡɚɩɢɫɚɜ ɜ ɤɨɧɰɟ ɫɭɮɮɢɤɫ f ɢɥɢ F ɞɥɹ ɬɢɩɚ float, ɫɭɮɮɢɤɫ l ɢɥɢ L ɞɥɹ ɬɢɩɚ long double. ȼɧɟɲɧɟɟ ɨɩɪɟɞɟɥɟɧɢɟ, ɨɛɴɹɜɥɹɸɳɟɟ ɩɟɪɟɦɟɧɧɵɟ, ɫɨɫɬɨɢɬ ɢɡ ɧɟɨɛɹɡɚɬɟɥɶɧɨɝɨ ɫɩɟɰɢɮɢɤɚɬɨɪɚ ɤɥɚɫɫɚ ɩɚɦɹɬɢ, ɫɩɟɰɢɮɢɤɚɬɨɪɨɜ ɬɢɩɚ ɢ ɫɩɢɫɤɚ ɞɟɤɥɚɪɚɬɨɪɨɜ-ɢɧɢɰɢɚɥɢɡɚɬɨɪɨɜ, ɤɚɠɞɵɣ ɢɡ ɤɨɬɨɪɵɯ ɨɛɴɹɜɥɹɟɬ ɢɞɟɧɬɢɮɢɤɚɬɨɪ ɨɞɧɨɣ ɩɟɪɟɦɟɧɧɨɣ ɢ, ɜɨɡɦɨɠɧɨ, ɡɧɚɱɟɧɢɟ, ɩɪɢɫɜɚɢɜɚɟɦɨɟ ɩɟɪɟɦɟɧɧɨɣ ɩɪɢ ɟɟ ɨɛɴɹɜɥɟɧɢɢ. ȼɧɟɲɧɟɟ ɨɩɪɟɞɟɥɟɧɢɟ ɡɚɤɚɧɱɢɜɚɟɬɫɹ ɬɨɱɤɨɣ ɫ ɡɚɩɹɬɨɣ: 10
/* Ɍɪɢ ɩɟɪɟɦɟɧɧɵɯ ɬɢɩɚ int ɛɟɡ ɹɜɧɨɣ ɢɧɢɰɢɚɥɢɡɚɰɢɢ */ double x=1, y=2; /* Ⱦɜɟ ɩɟɪɟɦɟɧɧɵɯ ɬɢɩɚ double ɫ ɧɚɱɚɥɶɧɵɦɢ ɡɧɚɱɟɧɢɹɦɢ 1 ɢ 2 */ char c1='0'; /* ɉɟɪɟɦɟɧɧɚɹ ɬɢɩɚ char, ɟɟ ɡɧɚɱɟɧɢɟ – ɤɨɞ ɥɢɬɟɪɵ 0 */ Ɍɟɤɫɬ, ɡɚɩɢɫɚɧɧɵɣ ɜ ɷɬɢɯ ɩɪɢɦɟɪɚɯ ɩɨɫɥɟ ɡɧɚɤɨɜ //, ɹɜɥɹɟɬɫɹ ɤɨɦint i, j, k;
ɦɟɧɬɚɪɢɟɦ ɢ ɫɥɭɠɢɬ ɬɨɥɶɤɨ ɞɥɹ ɞɨɤɭɦɟɧɬɢɪɨɜɚɧɢɹ ɩɪɨɝɪɚɦɦɵ. Ɍɚɤɨɣ ɤɨɦɦɟɧɬɚɪɢɣ ɦɨɠɟɬ ɡɚɧɢɦɚɬɶ ɬɨɥɶɤɨ ɨɞɧɭ ɫɬɪɨɤɭ ɬɟɤɫɬɚ ɢ ɞɨɩɭɫɤɚɟɬɫɹ ɜ ɬɟɤɫɬɚɯ ɩɪɨɝɪɚɦɦ ɧɚ ɋɢ++. Ʉɨɦɦɟɧɬɚɪɢɣ, ɡɚɧɢɦɚɸɳɢɣ ɧɟɫɤɨɥɶɤɨ ɫɬɪɨɤ, ɡɚɤɥɸɱɚɟɬɫɹ ɜ ɫɩɟɰɢɚɥɶɧɵɟ ɫɤɨɛɤɢ /* ɢ */. ȼ ɤɚɱɟɫɬɜɟ ɫɩɟɰɢɮɢɤɚɬɨɪɨɜ ɤɥɚɫɫɚ ɩɚɦɹɬɢ ɜɨ ɜɧɟɲɧɟɦ ɨɩɪɟɞɟɥɟɧɢɢ ɦɨɠɟɬ ɭɤɚɡɵɜɚɬɶɫɹ ɨɞɧɨ ɢɡ ɤɥɸɱɟɜɵɯ ɫɥɨɜ extern, static ɢɥɢ typedef. ɋɩɟɰɢɮɢɤɚɬɨɪ extern ɨɡɧɚɱɚɟɬ, ɱɬɨ ɨɛɴɹɜɥɹɟɦɵɣ ɨɛɴɟɤɬ ɩɪɢɧɚɞɥɟɠɢɬ ɞɪɭɝɨɦɭ ɩɪɨɝɪɚɦɦɧɨɦɭ ɮɚɣɥɭ, ɚ ɜ ɞɚɧɧɨɦ ɮɚɣɥɟ ɫɨɞɟɪɠɢɬɫɹ ɬɨɥɶɤɨ ɢɧɮɨɪɦɚɰɢɹ ɨ ɟɝɨ ɬɢɩɟ ɢ ɢɦɟɧɢ ɢ ɧɟ ɞɨɥɠɧɨ ɩɪɢɫɭɬɫɬɜɨɜɚɬɶ ɢɧɢɰɢɚɥɢɡɢɪɭɸɳɟɟ ɜɵɪɚɠɟɧɢɟ. ɋɩɟɰɢɮɢɤɚɬɨɪ static ɨɝɪɚɧɢɱɢɜɚɟɬ ɨɛɥɚɫɬɶ ɞɟɣɫɬɜɢɹ ɨɛɴɹɜɥɹɟɦɨɝɨ ɢɦɟɧɢ ɞɚɧɧɵɦ ɮɚɣɥɨɦ ɢɥɢ ɛɥɨɤɨɦ, ɟɫɥɢ ɨɛɴɹɜɥɟɧɢɟ ɫɨɞɟɪɠɢɬɫɹ ɜ ɛɥɨɤɟ. ȿɫɥɢ ɨɛɴɹɜɥɟɧɢɟ ɞɚɧɧɨɝɨ ɫɨɞɟɪɠɢɬɫɹ ɜɧɭɬɪɢ ɬɟɥɚ ɮɭɧɤɰɢɢ (ɥɨɤɚɥɶɧɨɟ ɨɛɴɹɜɥɟɧɢɟ), ɬɨ ɦɨɠɧɨ ɭɤɚɡɵɜɚɬɶ ɫɩɟɰɢɮɢɤɚɬɨɪɵ ɤɥɚɫɫɚ ɩɚɦɹɬɢ register ɢɥɢ auto. ɋɩɟɰɢɮɢɤɚɬɨɪ register ɧɨɫɢɬ ɪɟɤɨɦɟɧɞɚɬɟɥɶɧɵɣ ɯɚɪɚɤɬɟɪ, ɤɨɦɩɢɥɹɬɨɪ ɩɵɬɚɟɬɫɹ ɪɚɡɦɟɫɬɢɬɶ ɞɚɧɧɵɟ ɷɬɨɝɨ ɤɥɚɫɫɚ ɜ ɪɟɝɢɫɬɪɟ ɩɪɨɰɟɫɫɨɪɚ, ɟɫɥɢ ɜ ɞɚɧɧɵɣ ɦɨɦɟɧɬ ɢɦɟɸɬɫɹ ɫɜɨɛɨɞɧɵɟ ɪɟɝɢɫɬɪɵ. ɋɩɟɰɢɮɢɤɚɬɨɪ auto ɩɪɢɧɢɦɚɟɬɫɹ ɩɨ ɭɦɨɥɱɚɧɢɸ ɢ ɩɨɷɬɨɦɭ ɹɜɧɨ ɧɟ ɭɤɚɡɵɜɚɟɬɫɹ, ɨɧ ɨɡɧɚɱɚɟɬ, ɱɬɨ ɞɚɧɧɵɟ ɤɥɚɫɫɚ auto ɞɨɥɠɧɵ ɪɚɡɦɟɳɚɬɶɫɹ ɜ ɩɪɨɝɪɚɦɦɧɨɦ ɫɬɟɤɟ ɩɪɢ ɜɵɡɨɜɟ ɮɭɧɤɰɢɢ. ɋɩɟɰɢɮɢɤɚɬɨɪ typedef ɫɥɭɠɢɬ ɞɥɹ ɩɪɢɫɜɨɟɧɢɹ ɢɦɟɧɢ ɨɩɢɫɵɜɚɟɦɨɦɭ ɬɢɩɭ ɞɚɧɧɵɯ ɢ ɛɭɞɟɬ ɪɚɫɫɦɨɬɪɟɧ ɩɨɞɪɨɛɧɟɟ ɜ ɫɥɟɞɭɸɳɟɦ ɩɚɪɚɝɪɚɮɟ. ɇɚɪɹɞɭ ɫ ɩɨɤɚɡɚɧɧɵɦɢ ɜɵɲɟ ɤɨɧɫɬɚɧɬɚɦɢ-ɥɢɬɟɪɚɥɚɦɢ, ɡɧɚɱɟɧɢɹ ɤɨɬɨɪɵɯ ɨɩɪɟɞɟɥɹɸɬɫɹ ɢɯ ɩɪɟɞɫɬɚɜɥɟɧɢɟɦ ɜ ɩɪɨɝɪɚɦɦɟ, ɜ ɋɢ ɢ ɋɢ++ ɩɪɟɞɭɫɦɨɬɪɟɧɵ ɤɨɧɫɬɚɧɬɵ, ɤɨɬɨɪɵɦ ɩɪɢɫɜɚɢɜɚɸɬɫɹ ɫɨɛɫɬɜɟɧɧɵɟ ɢɦɟɧɚ - ɢɦɟɧɨɜɚɧɧɵɟ ɤɨɧɫɬɚɧɬɵ. ȼ ɨɩɢɫɚɧɢɢ ɢɦɟɧɨɜɚɧɧɨɣ ɤɨɧɫɬɚɧɬɵ ɩɪɢɫɭɬɫɬɜɭɟɬ ɨɩɢɫɚɬɟɥɶ const, ɧɚɩɪɢɦɟɪ, const double Pi=3.141592653;
ɉɟɪɟɦɟɧɧɨɣ, ɢɞɟɧɬɢɮɢɤɚɬɨɪ ɤɨɬɨɪɨɣ ɨɛɴɹɜɥɟɧ ɫ ɨɩɢɫɚɬɟɥɟɦ const, ɧɟɥɶɡɹ ɩɪɢɫɜɨɢɬɶ ɢɧɨɟ ɡɧɚɱɟɧɢɟ, ɱɟɦ ɛɵɥɨ ɭɫɬɚɧɨɜɥɟɧɨ ɩɪɢ ɨɛɴɹɜɥɟɧɢɢ ɢɞɟɧɬɢɮɢɤɚɬɨɪɚ. ɂɧɢɰɢɚɥɢɡɢɪɭɸɳɟɟ ɡɧɚɱɟɧɢɟ ɩɪɢ ɨɛɴɹɜɥɟɧɢɢ ɤɨɧɫɬɚɧɬɵ ɹɜɥɹɟɬɫɹ ɨɛɹɡɚɬɟɥɶɧɵɦ. ɇɚɪɹɞɭ ɫ ɛɚɡɨɜɵɦɢ ɰɟɥɵɦɢ ɢ ɜɟɳɟɫɬɜɟɧɧɵɦɢ ɬɢɩɚɦɢ ɪɚɡɥɢɱɧɵɯ ɪɚɡɦɟɪɨɜ ɜ ɩɪɨɝɪɚɦɦɟ ɦɨɝɭɬ ɨɛɴɹɜɥɹɬɶɫɹ ɢ ɢɫɩɨɥɶɡɨɜɚɬɶɫɹ ɞɚɧɧɵɟ ɬɢɩɨɜ, ɨɩɪɟɞɟɥɹɟɦɵɯ ɩɪɨɝɪɚɦɦɢɫɬɨɦ: ɭɤɚɡɚɬɟɥɢ, ɫɫɵɥɤɢ, ɚɝɪɟɝɚɬɵ ɞɚɧɧɵɯ ɢ ɞɚɧɧɵɟ ɩɟɪɟɱɢɫɥɢɦɨɝɨ ɬɢɩɚ. 11
ɉɟɪɟɱɢɫɥɟɧɧɵɣ ɬɢɩ ɩɪɢɦɟɧɹɟɬɫɹ ɞɥɹ ɞɚɧɧɵɯ ɰɟɥɨɝɨ ɬɢɩɚ, ɤɨɬɨɪɵɟ ɦɨɝɭɬ ɩɪɢɧɢɦɚɬɶ ɨɝɪɚɧɢɱɟɧɧɵɣ ɧɚɛɨɪ ɡɧɚɱɟɧɢɣ. Ʉɚɠɞɨɦɭ ɡɧɚɱɟɧɢɸ ɫɨɨɬɜɟɬɫɬɜɭɟɬ ɫɨɛɫɬɜɟɧɧɨɟ ɢɦɹ-ɢɞɟɧɬɢɮɢɤɚɬɨɪ ɢ ɰɟɥɨɟ ɱɢɫɥɨ, ɡɧɚɱɟɧɢɟ ɷɬɨɝɨ ɢɦɟɧɢ. Ɉɛɴɹɜɥɟɧɢɟ ɩɟɪɟɱɢɫɥɟɧɧɨɝɨ ɬɢɩɚ ɫɬɪɨɢɬɫɹ ɩɨ ɫɯɟɦɟ: enum ɢɞɟɧɬɢɮɢɤɚɬɨɪ {ɫɩɢɫɨɤ ɩɟɪɟɱɢɫɥɟɧɢɹ} ɞɟɤɥɚɪɚɬɨɪɵ-ɢɧɢɰɢɚɥɢɡɚɬɨɪɵ;
Ɂɞɟɫɶ ɢɞɟɧɬɢɮɢɤɚɬɨɪ ɡɚɞɚɟɬ ɢɦɹ ɩɟɪɟɱɢɫɥɟɧɧɨɝɨ ɬɢɩɚ, ɫɩɢɫɨɤ ɩɟɪɟɱɢɫɥɟɧɢɹ ɫɨɫɬɨɢɬ ɢɡ ɩɟɪɟɱɢɫɥɢɬɟɥɟɣ, ɪɚɡɞɟɥɟɧɧɵɯ ɡɚɩɹɬɵɦɢ. Ʉɚɠɞɵɣ ɩɟɪɟɱɢɫɥɢɬɟɥɶ ɡɚɞɚɟɬɫɹ ɢɞɟɧɬɢɮɢɤɚɬɨɪɨɦ ɢ, ɜɨɡɦɨɠɧɨ, ɰɟɥɵɦ ɡɧɚɱɟɧɢɟɦ ɬɢɩɚ char ɢɥɢ int, ɧɚɩɪɢɦɟɪ, enum color {RED, GREEN, BLUE} en_color; enum lex_type {CNST, VAR, OPER=3, FUNC};
ȿɫɥɢ ɡɧɚɱɟɧɢɟ ɩɟɪɟɱɢɫɥɢɬɟɥɹ ɧɟ ɡɚɞɚɧɨ, ɩɟɪɜɵɣ ɢɡ ɧɢɯ ɩɨɥɭɱɚɟɬ ɡɧɚɱɟɧɢɟ 0, ɚ ɤɚɠɞɵɣ ɫɥɟɞɭɸɳɢɣ - ɡɧɚɱɟɧɢɟ, ɛɨɥɶɲɟɟ ɧɚ 1. ȼɨɨɛɳɟ ɥɸɛɨɣ ɩɟɪɟɱɢɫɥɢɬɟɥɶ ɩɨ ɭɦɨɥɱɚɧɢɸ ɢɦɟɟɬ ɡɧɚɱɟɧɢɟ ɧɚ 1 ɛɨɥɶɲɟ ɩɪɟɞɵɞɭɳɟɝɨ. ȼ ɋɢ/ɋɢ++ ɩɪɢɧɹɬɨ ɡɚɩɢɫɵɜɚɬɶ ɢɞɟɧɬɢɮɢɤɚɬɨɪɵ ɩɟɪɟɱɢɫɥɢɬɟɥɟɣ ɩɪɨɩɢɫɧɵɦɢ ɛɭɤɜɚɦɢ. ɂɦɟɧɚ ɩɟɪɟɱɢɫɥɢɬɟɥɟɣ ɢɫɩɨɥɶɡɭɸɬɫɹ ɥɢɛɨ ɤɚɤ ɢɦɟɧɨɜɚɧɧɵɟ ɤɨɧɫɬɚɧɬɵ, ɥɢɛɨ ɞɥɹ ɩɪɢɫɜɚɢɜɚɧɢɹ ɩɟɪɟɦɟɧɧɵɦ ɩɟɪɟɱɢɫɥɢɦɨɝɨ ɬɢɩɚ. ȼ ɋɢ/ɋɢ++ ɞɥɹ ɫɫɵɥɨɤ ɧɚ ɩɟɪɟɦɟɧɧɭɸ ɬɨɝɨ ɢɥɢ ɢɧɨɝɨ ɬɢɩɚ ɫɥɭɠɚɬ ɭɤɚɡɚɬɟɥɢ. ɍɤɚɡɚɬɟɥɶ - ɷɬɨ ɬɢɩ ɞɚɧɧɵɯ, ɡɧɚɱɟɧɢɹɦɢ ɤɨɬɨɪɵɯ ɹɜɥɹɸɬɫɹ ɚɞɪɟɫɚ ɞɪɭɝɢɯ ɞɚɧɧɵɯ. ɉɪɢ ɨɛɴɹɜɥɟɧɢɢ ɭɤɚɡɚɬɟɥɹ ɩɟɪɟɞ ɢɞɟɧɬɢɮɢɤɚɬɨɪɨɦ ɡɚɩɢɫɵɜɚɟɬɫɹ ɡɧɚɤ *. ɍɤɚɡɚɬɟɥɶ ɦɨɠɟɬ ɢɧɢɰɢɚɥɢɡɢɪɨɜɚɬɶɫɹ ɚɞɪɟɫɨɦ ɬɨɝɨ ɢɥɢ ɢɧɨɝɨ ɞɚɧɧɨɝɨ, ɞɥɹ ɩɨɥɭɱɟɧɢɹ ɚɞɪɟɫɚ ɫɥɭɠɢɬ ɨɩɟɪɚɰɢɹ & (ɚɦɩɟɪɫɟɧɞ): double y; double *px, *py=&y;
Ⱦɥɹ ɭɤɚɡɚɬɟɥɟɣ ɨɩɪɟɞɟɥɟɧɵ ɨɩɟɪɚɰɢɢ ɫɪɚɜɧɟɧɢɹ, ɫɥɨɠɟɧɢɹ ɭɤɚɡɚɬɟɥɹ ɫ ɰɟɥɵɦ ɱɢɫɥɨɦ, ɜɵɱɢɬɚɧɢɹ ɞɜɭɯ ɭɤɚɡɚɬɟɥɟɣ, ɚ ɬɚɤɠɟ ɨɩɟɪɚɰɢɹ ɢɧɞɟɤɫɢɪɨɜɚɧɢɹ (ɨɩɟɪɚɰɢɹ «[]»). Ⱦɥɹ ɨɛɪɚɳɟɧɢɹ ɤ ɩɟɪɟɦɟɧɧɨɣ ɩɨ ɭɤɚɡɚɬɟɥɸ ɜɵɩɨɥɧɹɟɬɫɹ ɨɩɟɪɚɰɢɹ ɪɚɡɵɦɟɧɨɜɚɧɢɹ, ɨɛɨɡɧɚɱɚɟɦɚɹ ɡɧɚɤɨɦ * (ɡɜɟɡɞɨɱɤɚ), ɧɚɩɪɢɦɟɪ, *py=7.5;
ɉɪɢ ɨɛɴɹɜɥɟɧɢɢ ɭɤɚɡɚɬɟɥɹ ɦɨɠɟɬ ɢɫɩɨɥɶɡɨɜɚɬɶɫɹ ɨɩɢɫɚɬɟɥɶ const, ɧɚɩɪɢɦɟɪ, const int cc=20; const int *pc=&cc; double
*const delta=0.001;
// Ɇɨɠɧɨ ɢɧɢɰɢɚɥɢɡɢɪɨɜɚɬɶ // ɚɞɪɟɫɨɦ ɤɨɧɫɬɚɧɬɵ // ɍɤɚɡɚɬɟɥɶ-ɤɨɧɫɬɚɧɬɚ
Ʉɪɨɦɟ ɨɛɵɱɧɵɯ ɩɟɪɟɦɟɧɧɵɯ ɢ ɭɤɚɡɚɬɟɥɟɣ ɜ ɋɢ++ ɢɦɟɟɬɫɹ ɬɢɩ «ɫɫɵɥɤɚ ɧɚ ɩɟɪɟɦɟɧɧɭɸ», ɡɚɞɚɸɳɢɣ ɞɥɹ ɩɟɪɟɦɟɧɧɨɣ ɞɨɩɨɥɧɢɬɟɥɶɧɨɟ ɢɦɹ (ɩɫɟɜɞɨɧɢɦ). ȼɧɭɬɪɟɧɧɟɟ ɩɪɟɞɫɬɚɜɥɟɧɢɟ ɫɫɵɥɤɢ ɹɜɥɹɟɬɫɹ ɬɚɤɢɦ ɠɟ, ɤɚɤ ɞɥɹ ɭɤɚɡɚɬɟɥɹ, ɬɨ ɟɫɬɶ ɜ ɜɢɞɟ ɚɞɪɟɫɚ ɩɟɪɟɦɟɧɧɨɣ, ɧɨ ɨɛɪɚɳɟɧɢɟ ɤ ɩɟɪɟɦɟɧɧɨɣ ɩɨ ɫɫɵɥɤɟ ɡɚɩɢɫɵɜɚɟɬɫɹ ɜ ɬɨɣ ɠɟ ɮɨɪɦɟ, ɱɬɨ ɢ ɨɛɪɚɳɟɧɢɟ ɩɨ ɨɫɧɨɜɧɨɦɭ ɢɦɟɧɢ. ɉɟɪɟɦɟɧɧɚɹ ɬɢɩɚ «ɫɫɵɥɤɚ» ɜɫɟɝɞɚ ɢɧɢɰɢɚɥɢɡɢɪɭɟɬɫɹ ɡɚɞɚɧɢɟɦ ɢɦɟɧɢ
12
ɩɟɪɟɦɟɧɧɨɣ, ɤ ɤɨɬɨɪɨɣ ɨɬɧɨɫɢɬɫɹ ɫɫɵɥɤɚ. ɉɪɢ ɨɛɴɹɜɥɟɧɢɢ ɫɫɵɥɤɢ ɡɚ ɢɦɟɧɟɦ ɬɢɩɚ ɡɚɩɢɫɵɜɚɟɬɫɹ ɡɧɚɤ «&» (ɚɦɩɟɪɫɟɧɞ): int ii; int& aii=ii;
ɉɪɢ ɬɚɤɨɦ ɨɩɢɫɚɧɢɢ ɨɩɟɪɚɬɨɪɵ aii=5; ɢ ii=5; ɷɤɜɢɜɚɥɟɧɬɧɵ. ɂɡ ɩɟɪɟɦɟɧɧɵɯ ɥɸɛɨɝɨ ɬɢɩɚ ɦɨɝɭɬ ɨɛɪɚɡɨɜɵɜɚɬɶɫɹ ɦɚɫɫɢɜɵ. ɉɪɢ ɨɛɴɹɜɥɟɧɢɢ ɦɚɫɫɢɜɚ ɜ ɞɟɤɥɚɪɚɬɨɪɟ-ɢɧɢɰɢɚɥɢɡɚɬɨɪɟ ɡɚ ɢɞɟɧɬɢɮɢɤɚɬɨɪɨɦ ɦɚɫɫɢɜɚ ɡɚɞɚɟɬɫɹ ɱɢɫɥɨ ɷɥɟɦɟɧɬɨɜ ɦɚɫɫɢɜɚ ɜ ɤɜɚɞɪɚɬɧɵɯ ɫɤɨɛɤɚɯ: int a[5];
// Ɇɚɫɫɢɜ ɢɡ ɩɹɬɢ ɷɥɟɦɟɧɬɨɜ ɬɢɩɚ int
ɂɧɞɟɤɫɵ ɷɥɟɦɟɧɬɨɜ ɦɚɫɫɢɜɚ ɜɫɟɝɞɚ ɧɚɱɢɧɚɸɬɫɹ ɫ 0, ɢɧɞɟɤɫ ɩɨɫɥɟɞɧɟɝɨ ɷɥɟɦɟɧɬɚ ɧɚ ɟɞɢɧɢɰɭ ɦɟɧɶɲɟ ɱɢɫɥɚ ɷɥɟɦɟɧɬɨɜ ɜ ɦɚɫɫɢɜɟ. Ɇɚɫɫɢɜ ɦɨɠɟɬ ɢɧɢɰɢɚɥɢɡɢɪɨɜɚɬɶɫɹ ɫɩɢɫɤɨɦ ɡɧɚɱɟɧɢɣ ɜ ɮɢɝɭɪɧɵɯ ɫɤɨɛɤɚɯ: int b[4]={1, 2, 3, 4};
ɉɪɢ ɧɚɥɢɱɢɢ ɫɩɢɫɤɚ ɢɧɢɰɢɚɥɢɡɚɰɢɢ, ɨɯɜɚɬɵɜɚɸɳɟɝɨ ɜɫɟ ɷɥɟɦɟɧɬɵ ɦɚɫɫɢɜɚ, ɦɨɠɧɨ ɧɟ ɭɤɚɡɵɜɚɬɶ ɱɢɫɥɨ ɷɥɟɦɟɧɬɨɜ ɦɚɫɫɢɜɚ, ɨɧɨ ɛɭɞɟɬ ɨɩɪɟɞɟɥɟɧɨ ɤɨɦɩɢɥɹɬɨɪɨɦ: int c[]={1, 2, 3};
// Ɇɚɫɫɢɜ ɢɡ ɬɪɟɯ ɷɥɟɦɟɧɬɨɜ ɬɢɩɚ int
Ɇɧɨɝɨɦɟɪɧɵɟ ɦɚɫɫɢɜɵ ɪɚɫɫɦɚɬɪɢɜɚɸɬɫɹ ɤɚɤ ɦɚɫɫɢɜɵ ɦɚɫɫɢɜɨɜ, ɢ ɞɥɹ ɤɚɠɞɨɝɨ ɢɡɦɟɪɟɧɢɹ ɭɤɚɡɵɜɚɟɬɫɹ ɱɢɫɥɨ ɷɥɟɦɟɧɬɨɜ: double aa[2][2]={1, 2, 3, 4};
// Ɇɚɬɪɢɰɚ 2*2
Ɇɚɫɫɢɜɵ ɬɢɩɚ char ɦɨɝɭɬ ɢɧɢɰɢɚɥɢɡɢɪɨɜɚɬɶɫɹ ɫɬɪɨɤɨɜɵɦ ɥɢɬɟɪɚɥɨɦ. ɋɬɪɨɤɨɜɵɣ ɥɢɬɟɪɚɥ - ɷɬɨ ɩɨɫɥɟɞɨɜɚɬɟɥɶɧɨɫɬɶ ɥɸɛɵɯ ɫɢɦɜɨɥɨɜ, ɤɪɨɦɟ ɤɚɜɵɱɟɤ ɢ ɨɛɪɚɬɧɨɣ ɤɨɫɨɣ ɱɟɪɬɵ, ɡɚɤɥɸɱɟɧɧɚɹ ɜ ɤɚɜɵɱɤɢ. ȿɫɥɢ ɫɬɪɨɤɨɜɵɣ ɥɢɬɟɪɚɥ ɧɟ ɭɦɟɳɚɟɬɫɹ ɧɚ ɨɞɧɨɣ ɫɬɪɨɤɟ, ɟɝɨ ɦɨɠɧɨ ɩɪɟɪɜɚɬɶ ɫɢɦɜɨɥɨɦ «\» ɢ ɩɪɨɞɨɥɠɢɬɶ ɫ ɧɚɱɚɥɚ ɫɥɟɞɭɸɳɟɣ ɫɬɪɨɤɢ. ȼ ɫɬɚɧɞɚɪɬɟ C++ ɩɪɟɞɭɫɦɨɬɪɟɧɚ ɢ ɞɪɭɝɚɹ ɜɨɡɦɨɠɧɨɫɬɶ ɡɚɩɢɫɢ ɞɥɢɧɧɵɯ ɥɢɬɟɪɚɥɨɜ ɜ ɜɢɞɟ ɧɟɫɤɨɥɶɤɢɯ ɡɚɩɢɫɚɧɧɵɯ ɩɨɞɪɹɞ ɫɬɪɨɤɨɜɵɯ ɥɢɬɟɪɚɥɨɜ. ȿɫɥɢ ɦɟɠɞɭ ɫɬɪɨɤɨɜɵɦɢ ɥɢɬɟɪɚɥɚɦɢ ɧɟɬ ɫɢɦɜɨɥɨɜ, ɨɬɥɢɱɧɵɯ ɨɬ ɩɪɨɛɟɥɨɜ, ɬɚɤɢɟ ɥɢɬɟɪɚɥɵ ɫɥɢɜɚɸɬɫɹ ɤɨɦɩɢɥɹɬɨɪɨɦ ɜ ɨɞɢɧ. ɉɪɢ ɪɚɡɦɟɳɟɧɢɢ ɜ ɩɚɦɹɬɢ ɜ ɤɨɧɰɟ ɫɬɪɨɤɨɜɨɝɨ ɥɢɬɟɪɚɥɚ ɞɨɛɚɜɥɹɟɬɫɹ ɫɢɦɜɨɥ '\0', ɬɨ ɟɫɬɶ ɧɭɥɟɜɨɣ ɛɚɣɬ. ɋɬɪɨɤɨɜɵɣ ɥɢɬɟɪɚɥ ɦɨɠɟɬ ɩɪɢɦɟɧɹɬɶɫɹ ɢ ɞɥɹ ɢɧɢɰɢɚɥɢɡɚɰɢɢ ɭɤɚɡɚɬɟɥɹ ɧɚ ɬɢɩ char: char str1[11]="ɗɬɨ ɫɬɪɨɤɚ", char str2[]="Ɋɚɡɦɟɪ ɷɬɨɝɨ ɦɚɫɫɢɜɚ ɨɩɪɟɞɟɥɹɟɬɫɹ" " ɱɢɫɥɨɦ ɡɧɚɤɨɜ ɜ ɥɢɬɟɪɚɥɟ + 1"; char *pstr="ɍɤɚɡɚɬɟɥɶ ɫ ɢɧɢɰɢɚɥɢɡɚɰɢɟɣ ɫɬɪɨɤɨɣ";
ɂɦɹ ɦɚɫɫɢɜɚ ɜ ɋɢ/ɋɢ++ ɹɜɥɹɟɬɫɹ ɭɤɚɡɚɬɟɥɟɦ-ɤɨɧɫɬɚɧɬɨɣ, ɫɫɵɥɚɸɳɢɦɫɹ ɧɚ ɩɟɪɜɵɣ ɷɥɟɦɟɧɬ ɦɚɫɫɢɜɚ, ɢɦɟɸɳɢɣ ɢɧɞɟɤɫ, ɪɚɜɧɵɣ ɧɭɥɸ. Ⱦɥɹ ɨɛɪɚɳɟɧɢɹ ɤ ɷɥɟɦɟɧɬɭ ɦɚɫɫɢɜɚ ɭɤɚɡɵɜɚɟɬɫɹ ɢɞɟɧɬɢɮɢɤɚɬɨɪ ɦɚɫɫɢɜɚ ɢ ɢɧɞɟɤɫ ɷɥɟɦɟɧɬɚ ɜ ɤɪɭɝɥɵɯ ɫɤɨɛɤɚɯ, ɧɚɩɪɢɦɟɪ, c[2], aa[0][1].
13
2.3. ɋɬɪɭɤɬɭɪɵ ɢ ɨɛɴɟɞɢɧɟɧɢɹ ɇɚɪɹɞɭ ɫ ɦɚɫɫɢɜɚɦɢ ɜ ɋɢ/ɋɢ++ ɢɦɟɸɬɫɹ ɚɝɪɟɝɚɬɵ ɞɚɧɧɵɯ ɬɢɩɚ ɫɬɪɭɤɬɭɪ ɢ ɨɛɴɟɞɢɧɟɧɢɣ. Ɍɢɩ ɫɬɪɭɤɬɭɪɵ ɩɪɟɞɫɬɚɜɥɹɟɬ ɫɨɛɨɣ ɭɩɨɪɹɞɨɱɟɧɧɭɸ ɫɨɜɨɤɭɩɧɨɫɬɶ ɞɚɧɧɵɯ ɪɚɡɥɢɱɧɵɯ ɬɢɩɨɜ, ɤ ɤɨɬɨɪɨɣ ɦɨɠɧɨ ɨɛɪɚɳɚɬɶɫɹ ɤɚɤ ɤ ɟɞɢɧɨɦɭ ɰɟɥɨɦɭ. Ɉɩɢɫɚɧɢɟ ɫɬɪɭɤɬɭɪɧɨɝɨ ɬɢɩɚ ɫɬɪɨɢɬɫɹ ɩɨ ɫɯɟɦɟ: struct ɢɞɟɧɬɢɮɢɤɚɬɨɪ {ɞɟɤɥɚɪɚɬɨɪɵ ɱɥɟɧɨɜ} ɞɟɤɥɚɪɚɬɨɪɵ_ɢɧɢɰɢɚɥɢɡɚɬɨɪɵ;
Ɍɚɤɨɟ ɨɛɴɹɜɥɟɧɢɟ ɜɵɩɨɥɧɹɟɬ ɞɜɟ ɮɭɧɤɰɢɢ: ɜɨ-ɩɟɪɜɵɯ, ɨɛɴɹɜɥɹɟɬɫɹ ɫɬɪɭɤɬɭɪɧɵɣ ɬɢɩ, ɜɨ-ɜɬɨɪɵɯ, ɨɛɴɹɜɥɹɸɬɫɹ ɩɟɪɟɦɟɧɧɵɟ ɷɬɨɝɨ ɬɢɩɚ. ɂɞɟɧɬɢɮɢɤɚɬɨɪ ɩɨɫɥɟ ɤɥɸɱɟɜɨɝɨ ɫɥɨɜɚ struct ɹɜɥɹɟɬɫɹ ɢɦɟɧɟɦ ɫɬɪɭɤɬɭɪɧɨɝɨ ɬɢɩɚ. ɂɦɹ ɬɢɩɚ ɦɨɠɟɬ ɨɬɫɭɬɫɬɜɨɜɚɬɶ, ɬɨɝɞɚ ɬɢɩ ɛɭɞɟɬ ɛɟɡɵɦɹɧɧɵɦ, ɢ ɜ ɞɪɭɝɢɯ ɱɚɫɬɹɯ ɩɪɨɝɪɚɦɦɵ ɧɟɥɶɡɹ ɛɭɞɟɬ ɨɛɴɹɜɥɹɬɶ ɞɚɧɧɵɟ ɷɬɨɝɨ ɬɢɩɚ. Ⱦɟɤɥɚɪɚɬɨɪɵ_ɢɧɢɰɢɚɥɢɡɚɬɨɪɵ ɨɛɴɹɜɥɹɸɬ ɤɨɧɤɪɟɬɧɵɟ ɩɟɪɟɦɟɧɧɵɟ ɫɬɪɭɤɬɭɪɧɨɝɨ ɬɢɩɚ, ɬ.ɟ. ɞɚɧɧɵɟ ɨɩɢɫɚɧɧɨɝɨ ɬɢɩɚ, ɭɤɚɡɚɬɟɥɢ ɧɚ ɷɬɨɬ ɬɢɩ ɢ ɦɚɫɫɢɜɵ ɞɚɧɧɵɯ. Ⱦɟɤɥɚɪɚɬɨɪɵ_ɢɧɢɰɢɚɥɢɡɚɬɨɪɵ ɦɨɝɭɬ ɨɬɫɭɬɫɬɜɨɜɚɬɶ, ɜ ɷɬɨɦ ɫɥɭɱɚɟ ɨɛɴɹɜɥɟɧɢɟ ɨɩɢɫɵɜɚɟɬ ɬɨɥɶɤɨ ɬɢɩ ɫɬɪɭɤɬɭɪɵ. ɋɬɪɭɤɬɭɪɚ, ɨɩɢɫɵɜɚɸɳɚɹ ɬɨɱɤɭ ɧɚ ɩɥɨɫɤɨɫɬɢ, ɦɨɠɟɬ ɛɵɬɶ ɨɩɪɟɞɟɥɟɧɚ ɬɚɤ: struct Point_struct // ɂɦɹ ɫɬɪɭɤɬɭɪɵ {int x, y;} // Ⱦɟɤɥɚɪɚɬɨɪɵ ɱɥɟɧɨɜ ɫɬɪɭɤɬɭɪɵ point1, *ptr_to_point, arpoint[3]; * Ⱦɚɧɧɵɟ ɫɬɪɭɤɬɭɪɧɨɝɨ ɬɢɩɚ */
ɑɥɟɧɵ (ɤɨɦɩɨɧɟɧɬɵ) ɫɬɪɭɤɬɭɪɵ ɨɩɢɫɵɜɚɸɬɫɹ ɚɧɚɥɨɝɢɱɧɨ ɞɚɧɧɵɦ ɫɨɨɬɜɟɬɫɬɜɭɸɳɟɝɨ ɬɢɩɚ ɢ ɦɨɝɭɬ ɛɵɬɶ ɫɤɚɥɹɪɧɵɦɢ ɞɚɧɧɵɦɢ, ɭɤɚɡɚɬɟɥɹɦɢ, ɦɚɫɫɢɜɚɦɢ ɢɥɢ ɞɚɧɧɵɦɢ ɞɪɭɝɨɝɨ ɫɬɪɭɤɬɭɪɧɨɝɨ ɬɢɩɚ. ɇɚɩɪɢɦɟɪ, ɞɥɹ ɨɩɢɫɚɧɢɹ ɫɬɪɭɤɬɭɪɧɨɝɨ ɬɢɩɚ «ɩɪɹɦɨɭɝɨɥɶɧɢɤ ɫɨ ɫɬɨɪɨɧɚɦɢ, ɩɚɪɚɥɥɟɥɶɧɵɦɢ ɨɫɹɦ ɤɨɨɪɞɢɧɚɬ» ɦɨɠɧɨ ɩɪɟɞɥɨɠɢɬɶ ɧɟɫɤɨɥɶɤɨ ɜɚɪɢɚɧɬɨɜ: struct Rect1 { Point p1; Point p2; }; struct Rect2 { Point p[2]; }; struct Rect3 { Point p; int width; int high; };
// Ʉɨɨɪɞɢɧɚɬɵ ɥɟɜɨɝɨ ɜɟɪɯɧɟɝɨ ɭɝɥɚ // Ʉɨɨɪɞɢɧɚɬɵ ɩɪɚɜɨɝɨ ɧɢɠɧɟɝɨ ɭɝɥɚ
// Ʌɟɜɵɣ ɜɟɪɯɧɢɣ ɭɝɨɥ // ɒɢɪɢɧɚ // ȼɵɫɨɬɚ ɩɪɹɦɨɭɝɨɥɶɧɢɤɚ
14
ɉɨɫɤɨɥɶɤɭ ɩɪɢ ɨɩɢɫɚɧɢɢ ɱɥɟɧɨɜ ɫɬɪɭɤɬɭɪɵ ɞɨɥɠɧɵ ɢɫɩɨɥɶɡɨɜɚɬɶɫɹ ɬɨɥɶɤɨ ɪɚɧɟɟ ɨɩɪɟɞɟɥɟɧɧɵɟ ɢɦɟɧɚ ɬɢɩɨɜ, ɩɪɟɞɭɫɦɨɬɪɟɧ ɜɚɪɢɚɧɬ ɩɪɟɞɜɚɪɢɬɟɥɶɧɨɝɨ ɨɛɴɹɜɥɟɧɢɹ ɫɬɪɭɤɬɭɪɵ, ɡɚɞɚɸɳɢɣ ɬɨɥɶɤɨ ɢɦɹ ɫɬɪɭɤɬɭɪɧɨɝɨ ɬɢɩɚ. ɇɚɩɪɢɦɟɪ, ɱɬɨɛɵ ɨɩɢɫɚɬɶ ɷɥɟɦɟɧɬ ɞɜɨɢɱɧɨɝɨ ɞɟɪɟɜɚ, ɫɨɞɟɪɠɚɳɢɣ ɭɤɚɡɚɬɟɥɢ ɧɚ ɥɟɜɭɸ ɢ ɩɪɚɜɭɸ ɜɟɬɜɢ ɞɟɪɟɜɚ, ɢ ɭɤɚɡɚɬɟɥɶ ɧɚ ɧɟɤɨɬɨɪɭɸ ɫɬɪɭɤɬɭɪɭ ɬɢɩɚ Value, ɫɨɞɟɪɠɚɳɭɸ ɡɧɚɱɟɧɢɟ ɞɚɧɧɨɝɨ ɜ ɭɡɥɟ, ɦɨɠɧɨ ɩɨɫɬɭɩɢɬɶ ɬɚɤ: struct Value; struct Tree_element { Value *val; Tree_element *left, *right; };
ɑɥɟɧɚɦɢ ɫɬɪɭɤɬɭɪ ɦɨɝɭɬ ɛɵɬɶ ɬɚɤ ɧɚɡɵɜɚɟɦɵɟ ɛɢɬɨɜɵɟ ɩɨɥɹ, ɤɨɝɞɚ ɜ ɩɨɥɟ ɩɚɦɹɬɢ ɩɟɪɟɦɟɧɧɨɣ ɰɟɥɨɝɨ ɬɢɩɚ (int ɢɥɢ unsigned int) ɪɚɡɦɟɳɚɟɬɫɹ ɧɟɫɤɨɥɶɤɨ ɰɟɥɵɯ ɞɚɧɧɵɯ ɦɟɧɶɲɟɣ ɞɥɢɧɵ. ɉɭɫɬɶ, ɧɚɩɪɢɦɟɪ, ɜ ɧɟɤɨɬɨɪɨɣ ɩɪɨɝɪɚɦɦɟ ɫɢɧɬɚɤɫɢɱɟɫɤɨɝɨ ɪɚɡɛɨɪɚ ɨɩɢɫɚɧɢɟ ɥɟɤɫɟɦɵ ɫɨɞɟɪɠɢɬ ɬɢɩ ɥɟɤɫɟɦɵ (ɞɨ ɲɟɫɬɢ ɡɧɚɱɟɧɢɣ) ɢ ɩɨɪɹɞɤɨɜɵɣ ɧɨɦɟɪ ɥɟɤɫɟɦɵ ɜ ɬɚɛɥɢɰɟ ɫɨɨɬɜɟɬɫɬɜɭɸɳɟɝɨ ɬɢɩɚ (ɞɨ 2000 ɡɧɚɱɟɧɢɣ). Ⱦɥɹ ɩɪɟɞɫɬɚɜɥɟɧɢɹ ɡɧɚɱɟɧɢɹ ɬɢɩɚ ɥɟɤɫɟɦɵ ɞɨɫɬɚɬɨɱɧɨ ɬɪɟɯ ɞɜɨɢɱɧɵɯ ɪɚɡɪɹɞɨɜ (ɬɪɟɯ ɛɢɬ), ɚ ɞɥɹ ɩɪɟɞɫɬɚɜɥɟɧɢɹ ɱɢɫɟɥ ɨɬ 0 ɞɨ 2000 – ɨɞɢɧɧɚɞɰɚɬɢ ɞɜɨɢɱɧɵɯ ɪɚɡɪɹɞɨɜ (11 ɛɢɬ). Ɉɩɢɫɚɧɢɟ ɫɬɪɭɤɬɭɪɵ, ɫɨɞɟɪɠɚɳɟɣ ɫɜɟɞɟɧɢɹ ɨ ɥɟɤɫɟɦɟ, ɦɨɠɟɬ ɜɵɝɥɹɞɟɬɶ ɬɚɤ: struct Lexema { unsigned int type_lex:3; unsigned int num_lex:11; }
Ⱦɜɨɟɬɨɱɢɟ ɫ ɰɟɥɵɦ ɱɢɫɥɨɦ ɩɨɫɥɟ ɢɦɟɧɢ ɱɥɟɧɚ ɫɬɪɭɤɬɭɪɵ ɭɤɚɡɵɜɚɟɬ, ɱɬɨ ɷɬɨ ɛɢɬɨɜɨɟ ɩɨɥɟ, ɚ ɰɟɥɨɟ ɱɢɫɥɨ ɡɚɞɚɟɬ ɪɚɡɦɟɪ ɩɨɥɹ ɜ ɛɢɬɚɯ. Ɉɛɴɟɞɢɧɟɧɢɟ ɦɨɠɧɨ ɨɩɪɟɞɟɥɢɬɶ ɤɚɤ ɫɬɪɭɤɬɭɪɭ, ɜɫɟ ɤɨɦɩɨɧɟɧɬɵ ɤɨɬɨɪɨɣ ɪɚɡɦɟɳɚɸɬɫɹ ɜ ɩɚɦɹɬɢ ɫ ɨɞɧɨɝɨ ɢ ɬɨɝɨ ɠɟ ɚɞɪɟɫɚ. Ɍɚɤɢɦ ɨɛɪɚɡɨɦ, ɨɛɴɟɞɢɧɟɧɢɟ ɜ ɤɚɠɞɵɣ ɦɨɦɟɧɬ ɜɪɟɦɟɧɢ ɫɨɞɟɪɠɢɬ ɨɞɢɧ ɢɡ ɜɨɡɦɨɠɧɵɯ ɜɚɪɢɚɧɬɨɜ ɡɧɚɱɟɧɢɣ. Ⱦɥɹ ɪɚɡɦɟɳɟɧɢɹ ɨɛɴɟɞɢɧɟɧɢɹ ɜ ɩɚɦɹɬɢ ɜɵɞɟɥɹɟɬɫɹ ɭɱɚɫɬɨɤ, ɞɨɫɬɚɬɨɱɧɵɣ ɞɥɹ ɪɚɡɦɟɳɟɧɢɹ ɱɥɟɧɚ ɨɛɴɟɞɢɧɟɧɢɹ ɫɚɦɨɝɨ ɛɨɥɶɲɨɝɨ ɪɚɡɦɟɪɚ. ɉɪɢɦɟɧɟɧɢɟ ɨɛɴɟɞɢɧɟɧɢɹ ɬɚɤɠɟ ɩɨɡɜɨɥɹɟɬ ɨɛɪɚɳɚɬɶɫɹ ɤ ɨɞɧɨɦɭ ɢ ɬɨɦɭ ɠɟ ɩɨɥɸ ɩɚɦɹɬɢ ɩɨ ɪɚɡɧɵɦ ɢɦɟɧɚɦ ɢ ɢɧɬɟɪɩɪɟɬɢɪɨɜɚɬɶ ɤɚɤ ɡɧɚɱɟɧɢɹ ɪɚɡɧɵɯ ɬɢɩɨɜ. Ɉɩɢɫɚɧɢɟ ɨɛɴɟɞɢɧɟɧɢɹ ɫɬɪɨɢɬɫɹ ɩɨ ɬɨɣ ɠɟ ɫɯɟɦɟ, ɱɬɨ ɢ ɨɩɢɫɚɧɢɟ ɫɬɪɭɤɬɭɪɵ, ɧɨ ɜɦɟɫɬɨ ɤɥɸɱɟɜɨɝɨ ɫɥɨɜɚ struct ɢɫɩɨɥɶɡɭɟɬɫɹ ɫɥɨɜɨ union, ɧɚɩɪɢɦɟɪ, ɨɛɴɟɞɢɧɟɧɢɟ uword ɩɨɡɜɨɥɹɟɬ ɢɧɬɟɪɩɪɟɬɢɪɨɜɚɬɶ ɩɨɥɟ ɩɚɦɹɬɢ ɥɢɛɨ ɤɚɤ unsigned int, ɥɢɛɨ ɤɚɤ ɦɚɫɫɢɜ ɢɡ ɞɜɭɯ ɷɥɟɦɟɧɬɨɜ ɬɢɩɚ unsigned char. union uword { unsigned int u; unsigned char b[2]; } 15
Ɉɩɢɫɚɧɢɹ ɬɢɩɨɜ, ɨɛɴɹɜɥɹɟɦɵɯ ɩɪɨɝɪɚɦɦɢɫɬɨɦ, ɜ ɬɨɦ ɱɢɫɥɟ ɫɬɪɭɤɬɭɪ ɢ ɨɛɴɟɞɢɧɟɧɢɣ, ɦɨɝɭɬ ɛɵɬɶ ɞɨɫɬɚɬɨɱɧɨ ɛɨɥɶɲɢɦɢ, ɩɨɷɬɨɦɭ ɜ ɋɢ/ɋɢ++ ɩɪɟɞɭɫɦɨɬɪɟɧɚ ɜɨɡɦɨɠɧɨɫɬɶ ɩɪɢɫɜɚɢɜɚɧɢɹ ɬɢɩɚɦ ɫɨɛɫɬɜɟɧɧɵɯ ɢɦɟɧ (ɫɢɧɨɧɢɦɨɜ), ɞɨɫɬɢɝɚɹ ɩɪɢ ɷɬɨɦ ɩɨɜɵɲɟɧɢɹ ɧɚɝɥɹɞɧɨɫɬɢ ɩɪɨɝɪɚɦɦɧɵɯ ɬɟɤɫɬɨɜ. ɋɢɧɨɧɢɦ ɢɦɟɧɢ ɬɢɩɚ ɜɜɨɞɢɬɫɹ ɫ ɤɥɸɱɟɜɵɦ ɫɥɨɜɨɦ typedef ɢ ɫɬɪɨɢɬɫɹ ɤɚɤ ɨɛɵɱɧɨɟ ɨɛɴɹɜɥɟɧɢɟ, ɧɨ ɢɞɟɧɬɢɮɢɤɚɬɨɪɵ ɜ ɞɟɤɥɚɪɚɬɨɪɚɯ ɜ ɷɬɨɦ ɫɥɭɱɚɟ ɢɧɬɟɪɩɪɟɬɢɪɭɸɬɫɹ ɤɚɤ ɫɢɧɨɧɢɦɵ ɨɩɢɫɚɧɧɵɯ ɬɢɩɨɜ. ɋɢɧɨɧɢɦɵ ɢɦɟɧ ɬɢɩɨɜ ɩɪɢɧɹɬɨ ɡɚɩɢɫɵɜɚɬɶ ɩɪɨɩɢɫɧɵɦɢ ɛɭɤɜɚɦɢ, ɱɬɨɛɵ ɨɬɥɢɱɚɬɶ ɢɯ ɨɬ ɢɞɟɧɬɢɮɢɤɚɬɨɪɨɜ ɩɟɪɟɦɟɧɧɵɯ. ɇɢɠɟ ɩɪɢɜɟɞɟɧɨ ɧɟɫɤɨɥɶɤɨ ɩɪɢɦɟɪɨɜ ɨɛɴɹɜɥɟɧɢɹ ɫɢɧɨɧɢɦɨɜ ɢɦɟɧ ɬɢɩɨɜ. typedef struct {double re, im} COMPLEX; typedef int *PINT;
ɉɨɫɥɟ ɬɚɤɢɯ ɨɛɴɹɜɥɟɧɢɣ ɫɢɧɨɧɢɦ ɢɦɟɧɢ ɦɨɠɟɬ ɢɫɩɨɥɶɡɨɜɚɬɶɫɹ ɤɚɤ ɫɩɟɰɢɮɢɤɚɬɨɪ ɬɢɩɚ: COMPLEX ca, *pca; PINT pi;
/* ɩɟɪɟɦɟɧɧɚɹ ɬɢɩɚ COMPLEX ɢ ɭɤɚɡɚɬɟɥɶ ɧɚ COMPLEX */ // ɭɤɚɡɚɬɟɥɶ ɧɚ int
ɉɪɢɜɟɞɟɧɧɨɟ ɜɵɲɟ ɨɩɢɫɚɧɢɟ ɫɬɪɭɤɬɭɪ ɢ ɨɛɴɟɞɢɧɟɧɢɣ ɜ ɨɫɧɨɜɧɨɦ ɫɨɨɬɜɟɬɫɬɜɭɟɬ ɢɯ ɩɨɫɬɪɨɟɧɢɸ ɜ ɹɡɵɤɟ ɋɢ. ȼ ɋɢ++ ɫɬɪɭɤɬɭɪɵ ɢ ɨɛɴɟɞɢɧɟɧɢɹ ɹɜɥɹɸɬɫɹ ɱɚɫɬɧɵɦɢ ɫɥɭɱɚɹɦɢ ɨɛɴɟɤɬɧɵɯ ɬɢɩɨɜ ɞɚɧɧɵɯ. Ⱦɨɩɨɥɧɢɬɟɥɶɧɵɟ ɫɜɟɞɟɧɢɹ ɨɛ ɷɬɨɦ ɛɭɞɭɬ ɩɪɢɜɟɞɟɧɵ ɩɪɢ ɪɚɫɫɦɨɬɪɟɧɢɢ ɨɛɴɟɤɬɧɨɨɪɢɟɧɬɢɪɨɜɚɧɧɵɯ ɫɪɟɞɫɬɜ ɋɢ++.
2.4. Ɉɩɟɪɚɰɢɢ ɢ ɜɵɪɚɠɟɧɢɹ ɇɟɫɦɨɬɪɹ ɧɚ ɨɝɪɚɧɢɱɟɧɧɵɣ ɧɚɛɨɪ ɛɚɡɨɜɵɯ ɬɢɩɨɜ ɞɚɧɧɵɯ (ɰɟɥɵɟ ɢ ɜɟɳɟɫɬɜɟɧɧɵɟ ɚɪɢɮɦɟɬɢɱɟɫɤɢɟ ɞɚɧɧɵɟ ɢ ɫɬɪɨɤɨɜɵɟ ɥɢɬɟɪɚɥɵ) ɜ ɹɡɵɤɟ ɋɢ++ ɨɩɪɟɞɟɥɟɧ ɨɛɲɢɪɧɵɣ ɧɚɛɨɪ ɨɩɟɪɚɰɢɣ ɧɚɞ ɞɚɧɧɵɦɢ, ɱɚɫɬɶ ɢɡ ɤɨɬɨɪɵɯ ɧɟɩɨɫɪɟɞɫɬɜɟɧɧɨ ɫɨɨɬɜɟɬɫɬɜɭɟɬ ɦɚɲɢɧɧɵɦ ɤɨɦɚɧɞɚɦ. Ʉɚɤ ɢ ɜɨ ɜɫɟɯ ɹɡɵɤɚɯ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ, ɨɩɟɪɚɰɢɢ ɫɥɭɠɚɬ ɞɥɹ ɩɨɫɬɪɨɟɧɢɹ ɜɵɪɚɠɟɧɢɣ. ȼɵɪɚɠɟɧɢɟ ɩɪɟɞɫɬɚɜɥɹɟɬ ɫɨɛɨɣ ɩɨɫɥɟɞɨɜɚɬɟɥɶɧɨɫɬɶ ɨɩɟɪɚɧɞɨɜ ɢ ɡɧɚɤɨɜ ɨɩɟɪɚɰɢɣ ɢ ɫɥɭɠɢɬ ɞɥɹ ɜɵɱɢɫɥɟɧɢɹ ɧɟɤɨɬɨɪɨɝɨ ɡɧɚɱɟɧɢɹ. ȼ ɤɚɱɟɫɬɜɟ ɨɩɟɪɚɧɞɨɜ ɜ ɜɵɪɚɠɟɧɢɢ ɜɵɫɬɭɩɚɸɬ ɢɞɟɧɬɢɮɢɤɚɬɨɪɵ ɩɟɪɟɦɟɧɧɵɯ, ɤɨɧɫɬɚɧɬɵ ɢ ɫɬɪɨɤɨɜɵɟ ɥɢɬɟɪɚɥɵ, ɹɜɥɹɸɳɢɟɫɹ ɩɟɪɜɢɱɧɵɦɢ ɜɵɪɚɠɟɧɢɹɦɢ. ȼɵɪɚɠɟɧɢɟ, ɡɚɤɥɸɱɟɧɧɨɟ ɜ ɤɪɭɝɥɵɟ ɫɤɨɛɤɢ, ɬɚɤɠɟ ɪɚɫɫɦɚɬɪɢɜɚɟɬɫɹ ɤɚɤ ɩɟɪɜɢɱɧɨɟ. Ʉɚɠɞɚɹ ɨɩɟɪɚɰɢɹ ɩɪɟɞɩɨɥɚɝɚɟɬ ɢɫɩɨɥɶɡɨɜɚɧɢɟ ɨɩɪɟɞɟɥɟɧɧɵɯ ɬɢɩɨɜ ɨɩɟɪɚɧɞɨɜ (ɰɟɥɵɯ, ɜɟɳɟɫɬɜɟɧɧɵɯ, ɭɤɚɡɚɬɟɥɟɣ). Ɉɩɟɪɚɰɢɹ ɩɪɢɫɜɚɢɜɚɧɢɹ ɜ ɋɢ++ ɬɚɤɠɟ ɹɜɥɹɟɬɫɹ ɜɵɪɚɠɟɧɢɟɦ, ɜ ɫɜɹɡɢ ɫ ɷɬɢɦ ɪɚɡɥɢɱɚɸɬɫɹ ɨɩɟɪɚɧɞɵ, ɤɨɬɨɪɵɦ ɦɨɠɧɨ ɩɪɢɫɜɨɢɬɶ ɧɨɜɨɟ ɡɧɚɱɟɧɢɟ, ɢ ɨɩɟɪɚɧɞɵ, ɡɧɚɱɟɧɢɟ ɤɨɬɨɪɵɯ ɧɟ ɦɨɠɟɬ ɦɟɧɹɬɶɫɹ. ɑɬɨɛɵ ɨɩɟɪɚɧɞɭ ɦɨɠɧɨ ɛɵɥɨ ɩɪɢɫɜɨɢɬɶ ɡɧɚɱɟɧɢɟ, ɟɦɭ ɞɨɥɠɧɚ ɫɨɨɬɜɟɬɫɬɜɨɜɚɬɶ ɨɛɥɚɫɬɶ ɩɚɦɹɬɢ ɢ ɤɨɦɩɢɥɹɬɨɪɭ ɞɨɥɠɟɧ ɛɵɬɶ ɢɡɜɟɫɬɟɧ ɚɞɪɟɫ ɷɬɨɣ ɩɚɦɹɬɢ. Ɍɚɤɢɟ ɨɩɟɪɚɧɞɵ ɧɚɡɵɜɚɸɬ 16
1
::
Ⱦɨɫɬɭɩ ɤ ɝɥɨɛɚɥɶɧɨɦɭ ɢɦɟɧɢ ɢɥɢ ɢɦɟɧɢ ɢɡ ɞɪɭɝɨɣ ɨɛɥɚɫɬɢ
ɋɯɟɦɚ
ɇɚɡɧɚɱɟɧɢɟ
ɉɪɢɨɪɢɬɟɬ
Ɂɧɚɤ ɨɩɟɪɚɰɢɢ
L-ɜɵɪɚɠɟɧɢɹɦɢ (ɨɬ ɚɧɝɥɢɣɫɤɨɝɨ left – ɥɟɜɵɣ), ɬɚɤ ɤɚɤ ɨɧɢ ɦɨɝɭɬ ɛɵɬɶ ɡɚɩɢɫɚɧɵ ɜ ɥɟɜɨɣ ɱɚɫɬɢ ɨɩɟɪɚɬɨɪɚ ɩɪɢɫɜɚɢɜɚɧɢɹ. Ɋɟɡɭɥɶɬɚɬ ɜɵɱɢɫɥɟɧɢɹ ɜɵɪɚɠɟɧɢɹ ɡɚɜɢɫɢɬ ɨɬ ɩɪɢɨɪɢɬɟɬɨɜ ɨɩɟɪɚɰɢɣ. ȼ ɋɢ++ ɫɥɨɠɧɚɹ ɫɢɫɬɟɦɚ ɩɪɢɨɪɢɬɟɬɨɜ ɨɩɟɪɚɰɢɣ, ɜɤɥɸɱɚɸɳɚɹ 16 ɭɪɨɜɧɟɣ. ɇɢɠɟ ɜ ɬɚɛɥɢɰɟ ɩɪɢɜɟɞɟɧ ɩɟɪɟɱɟɧɶ ɨɩɟɪɚɰɢɣ ɋɢ++ ɫ ɭɤɚɡɚɧɢɟɦ ɢɯ ɩɪɢɨɪɢɬɟɬɨɜ, ɧɚɡɧɚɱɟɧɢɹ ɢ ɫɯɟɦɵ ɡɚɩɢɫɢ.
::ɝɥɨɛɚɥɶɧɵɣ_ɢɞɟɧɬɢɮɢɤɚɬɨɪ
ɂɅɂ ɢɦɹ_ɨɛɥɚɫɬɢ::ɢɦɹ_ɱɥɟɧɚ_ɫɬɪɭɤɬɭɪɵ
->
Ɉɛɪɚɳɟɧɢɟ ɤ ɱɥɟɧɭ ɫɬɪɭɤɬɭɪɵ ɩɨ ɭɤɚɡɚɬɟɥɸ ɧɚ ɫɬɪɭɤɬɭɪɭ
ɍɤɚɡɚɬɟɥɶ->ɢɦɹ_ɱɥɟɧɚ_ɫɬɪɭɤɬɭɪɵ
1
.
Ɉɛɪɚɳɟɧɢɟ ɤ ɱɥɟɧɭ ɫɬɪɭɤɬɭɪɵ ɩɨ ɢɦɟɧɢ ɫɬɪɭɤɬɭɪɵ
ɢɦɹ_ɫɬɪɭɤɬɭɪɵ.ɢɦɹ_ɱɥɟɧɚ_ɫɬɪɭɤɬɭɪɵ
1
[ ]
Ɉɛɪɚɳɟɧɢɟ ɤ ɷɥɟɦɟɧɬɭ ɦɚɫɫɢɜɚ
ɍɤɚɡɚɬɟɥɶ[ɢɧɞɟɤɫ]
1
( )
ɉɪɟɨɛɪɚɡɨɜɚɧɢɟ ɬɢɩɚ ɞɚɧɧɨɝɨ
1
ɢɦɹ_ɬɢɩɚ(ɜɵɪɚɠɟɧɢɟ)
ɢɥɢ (ɬɢɩ)ɜɵɪɚɠɟɧɢɟ
17
1
( )
ȼɵɡɨɜ ɮɭɧɤɰɢɢ
++
Ⱥɜɬɨɭɜɟɥɢɱɟɧɢɟ
++L-ɡɧɚɱɟɧɢɟ
2
Ⱥɜɬɨɭɦɟɧɶɲɟɧɢɟ
--L-ɡɧɚɱɟɧɢɟ
2
--
ɮɭɧɤɰɢɹ (ɚɪɝɭɦɟɧɬɵ)
ɢɥɢ L-ɡɧɚɱɟɧɢɟ++
ɢɥɢ L-ɡɧɚɱɟɧɢɟ--
2
~
Ȼɢɬɨɜɨɟ ɢɧɜɟɪɬɢɪɨɜɚɧɢɟ
~ɰɟɥɨɟ_ɜɵɪɚɠɟɧɢɟ
2
!
Ʌɨɝɢɱɟɫɤɨɟ ɨɬɪɢɰɚɧɢɟ
!ɜɵɪɚɠɟɧɢɟ
2
-
Ɉɞɧɨɦɟɫɬɧɵɣ ɦɢɧɭɫ
-ɜɵɪɚɠɟɧɢɟ
2
+
Ɉɞɧɨɦɟɫɬɧɵɣ ɩɥɸɫ
+ɜɵɪɚɠɟɧɢɟ
2
&
ɉɨɥɭɱɟɧɢɟ ɚɞɪɟɫɚ
&L-ɡɧɚɱɟɧɢɟ
2
*
Ɋɚɡɵɦɟɧɨɜɚɧɢɟ ɭɤɚɡɚɬɟɥɹ
*ɭɤɚɡɚɬɟɥɶ
2
new
ȼɵɞɟɥɟɧɢɟ ɞɢɧɚɦɢɱɟɫɤɨɣ ɩɚɦɹɬɢ
new ɬɢɩ_ɞɚɧɧɨɝɨ
2
delete
Ɉɫɜɨɛɨɠɞɟɧɢɟ ɩɚɦɹɬɢ
delete ɭɤɚɡɚɬɟɥɶ
2
delete []
Ɉɫɜɨɛɨɠɞɟɧɢɟ ɩɚɦɹɬɢ ɞɥɹ ɦɚɫɫɢɜɚ
delete [] ɭɤɚɡɚɬɟɥɶ
18
2
sizeof
2
Ɋɚɡɦɟɪ ɞɚɧɧɨɝɨ
sizeof ɜɵɪɚɠɟɧɢɟ
Ɋɚɡɦɟɪ ɬɢɩɚ ɞɚɧɧɨɝɨ
sizeof(ɢɦɹ ɬɢɩɚ )
3
*
ɍɦɧɨɠɟɧɢɟ
ɜɵɪɚɠɟɧɢɟ*ɜɵɪɚɠɟɧɢɟ
3
/
Ⱦɟɥɟɧɢɟ
ɜɵɪɚɠɟɧɢɟ/ɜɵɪɚɠɟɧɢɟ
3
%
Ɉɫɬɚɬɨɤ ɨɬ ɞɟɥɟɧɢɹ ɧɚɰɟɥɨ
ɜɵɪɚɠɟɧɢɟ%ɜɵɪɚɠɟɧɢɟ
->*
Ɉɛɪɚɳɟɧɢɟ ɤ ɱɥɟɧɭ ɫɬɪɭɤɬɭɪɵ ɩɨ ɭɤɚɡɚɬɟɥɸ
ɭɤɚɡɚɬɟɥɶ_ɧɚ_ɫɬɪɭɤɬɭɪɭ->* ɢɦɹ_ɱɥɟɧɚ_ɫɬɪɭɤɬɭɪɵ-ɭɤɚɡɚɬɟɥɹ
4
.*
Ɉɛɪɚɳɟɧɢɟ ɤ ɱɥɟɧɭ ɫɬɪɭɤɬɭɪɵ ɩɨ ɢɦɟɧɢ ɫɬɪɭɤɬɭɪɵ
ɢɦɹ_ɫɬɪɭɤɬɭɪɵ.* ɢɦɹ_ɱɥɟɧɚ_ɫɬɪɭɤɬɭɪɵ-ɭɤɚɡɚɬɟɥɹ
5
+
ɋɥɨɠɟɧɢɟ
ɜɵɪɚɠɟɧɢɟ+ɜɵɪɚɠɟɧɢɟ
5
-
ȼɵɱɢɬɚɧɢɟ
ɜɵɪɚɠɟɧɢɟ-ɜɵɪɚɠɟɧɢɟ
6
ɰɟɥɨɟ_ɜɵɪɚɠɟɧɢɟ
7
=ɜɵɪɚɠɟɧɢɟ
4
19
ɪɚɜɧɨ 8
==
Ɋɚɜɧɨ
ɜɵɪɚɠɟɧɢɟ==ɜɵɪɚɠɟɧɢɟ
8
!=
ɇɟ ɪɚɜɧɨ
ɜɵɪɚɠɟɧɢɟ!=ɜɵɪɚɠɟɧɢɟ
9
&
ɉɨɪɚɡɪɹɞɧɚɹ ɤɨɧɴɸɧɤɰɢɹ
ɜɵɪɚɠɟɧɢɟ&ɜɵɪɚɠɟɧɢɟ
10
^
Ɉɬɪɢɰɚɧɢɟ ɪɚɜɧɨɡɧɚɱɧɨɫɬɢ
ɜɵɪɚɠɟɧɢɟ^ɜɵɪɚɠɟɧɢɟ
11
|
ɉɨɪɚɡɪɹɞɧɚɹ ɞɢɡɴɸɧɤɰɢɹ
ɜɵɪɚɠɟɧɢɟ|ɜɵɪɚɠɟɧɢɟ
12
&&
Ʌɨɝɢɱɟɫɤɨɟ "ɂ"
ɜɵɪɚɠɟɧɢɟ&&ɜɵɪɚɠɟɧɢɟ
13
| |
Ʌɨɝɢɱɟɫɤɨɟ "ɂɅɂ"
ɜɵɪɚɠɟɧɢɟ||ɜɵɪɚɠɟɧɢɟ
14
? :
ɍɫɥɨɜɧɨɟ ɜɵɪɚɠɟɧɢɟ
ɜɵɪɚɠɟɧɢɟ?ɜɵɪɚɠɟɧɢɟ1:ɜɵɪɚɠɟɧɢɟ2
15
=
ɉɪɨɫɬɨɟ ɩɪɢɫɜɚɢɜɚɧɢɟ
ɜɵɪɚɠɟɧɢɟ=ɜɵɪɚɠɟɧɢɟ
15
@=
ɋɨɫɬɚɜɧɨɟ ɩɪɢɫɜɚɢɜɚɧɢɟ, ɡɧɚɤ @ ɨɞɢɧ ɢɡ ɡɧɚɤɨɜ ɨɩɟɪɚɰɢɣ
ɜɵɪɚɠɟɧɢɟ@=ɜɵɪɚɠɟɧɢɟ
* / % + > & ^ | 16
,
Ɉɩɟɪɚɰɢɹ ɫɥɟɞɨɜɚɧɢɹ
ɜɵɪɚɠɟɧɢɟ,ɜɵɪɚɠɟɧɢɟ
Ɋɚɫɫɦɨɬɪɢɦ ɨɫɨɛɟɧɧɨɫɬɢ ɩɪɢɦɟɧɟɧɢɹ ɧɟɤɨɬɨɪɵɯ ɢɡ ɨɩɟɪɚɰɢɣ, ɩɟɪɟɱɢɫɥɟɧɧɵɯ ɜɵɲɟ. 20
Ɉɩɟɪɚɰɢɹ «::» (ɞɜɚ ɞɜɨɟɬɨɱɢɹ) ɩɪɢɦɟɧɹɟɬɫɹ ɞɥɹ ɭɬɨɱɧɟɧɢɹ ɢɦɟɧɢ ɨɛɴɟɤɬɚ ɩɪɨɝɪɚɦɦɵ ɜ ɫɥɭɱɚɟ, ɤɨɝɞɚ ɜ ɷɬɨɦ ɦɟɫɬɟ ɩɪɨɝɪɚɦɦɵ ɢɡɜɟɫɬɧɵ ɞɜɚ ɨɞɢɧɚɤɨɜɵɯ ɢɦɟɧɢ, ɧɚɩɪɢɦɟɪ, ɤɨɝɞɚ ɨɞɧɨ ɢɦɹ ɨɛɴɹɜɥɟɧɨ ɝɥɨɛɚɥɶɧɨ, ɚ ɞɪɭɝɨɟ ɡɚɞɚɧɨ ɜ ɬɟɥɟ ɮɭɧɤɰɢɢ. ȿɫɥɢ ɢɦɟɧɢ ɩɪɟɞɲɟɫɬɜɭɸɬ ɞɜɚ ɞɜɨɟɬɨɱɢɹ, ɬɨ ɷɬɨ ɝɥɨɛɚɥɶɧɨɟ ɢɦɹ. Ⱦɥɹ ɨɛɪɚɳɟɧɢɹ ɤ ɱɥɟɧɚɦ ɫɬɪɭɤɬɭɪɵ ɢɥɢ ɨɛɴɟɞɢɧɟɧɢɹ ɦɨɠɧɨ ɜɨɫɩɨɥɶɡɨɜɚɬɶɫɹ ɥɢɛɨ ɢɦɟɧɟɦ ɫɬɪɭɤɬɭɪɧɨɝɨ ɞɚɧɧɨɝɨ, ɥɢɛɨ ɭɤɚɡɚɬɟɥɟɦ ɧɚ ɫɬɪɭɤɬɭɪɧɨɟ ɞɚɧɧɨɟ. ȼ ɩɟɪɜɨɦ ɫɥɭɱɚɟ ɩɨɥɧɨɟ ɢɦɹ ɱɥɟɧɚ ɫɬɪɭɤɬɭɪɵ ɫɨɫɬɨɢɬ ɢɡ ɢɦɟɧɢ ɫɚɦɨɣ ɫɬɪɭɤɬɭɪɵ ɢ ɢɦɟɧɢ ɱɥɟɧɚ ɫɬɪɭɤɬɭɪɵ, ɪɚɡɞɟɥɟɧɧɵɯ ɬɨɱɤɨɣ. ȼɨ ɜɬɨɪɨɦ ɫɥɭɱɚɟ ɡɚ ɢɦɟɧɟɦ ɭɤɚɡɚɬɟɥɹ ɧɚ ɫɬɪɭɤɬɭɪɭ ɫɬɚɜɢɬɫɹ ɡɧɚɤ «->» (ɫɬɪɟɥɤɚ), ɚ ɡɚ ɧɢɦ ɢɦɹ ɱɥɟɧɚ ɫɬɪɭɤɬɭɪɵ. ɉɭɫɬɶ ɜ ɩɪɨɝɪɚɦɦɟ ɨɛɴɹɜɥɟɧ ɫɬɪɭɤɬɭɪɧɵɣ ɬɢɩ AnyStruct, ɫɨɞɟɪɠɚɳɢɣ ɤɨɦɩɨɧɟɧɬɭ ɫ ɢɦɟɧɟɦ member ɬɢɩɚ int, ɢ ɨɛɴɹɜɥɟɧɵ ɩɟɪɟɦɟɧɧɵɟ // Ⱦɚɧɧɨɟ s1 ɬɢɩɚ AnyStruct /* ɍɤɚɡɚɬɟɥɶ ɧɚ ɞɚɧɧɨɟ ɬɢɩɚ AnyStruct */ Ɍɨɝɞɚ ɤ ɱɥɟɧɭ ɫɬɪɭɤɬɭɪɵ member ɢɡ s1 ɦɨɠɧɨ ɨɛɪɚɬɢɬɶɫɹ ɤɚɤ ɤ s1.member ɢɥɢ ɤɚɤ ɤ ps1->member. AnyStruct s1; AnyStruct *ps1 = &s1;
ɉɨɫɤɨɥɶɤɭ ɱɥɟɧɨɦ ɫɬɪɭɤɬɭɪɵ ɦɨɠɟɬ ɛɵɬɶ ɭɤɚɡɚɬɟɥɶ, ɜ ɋɢ++ ɢɦɟɸɬɫɹ ɫɩɟɰɢɚɥɶɧɵɟ ɨɩɟɪɚɰɢɢ ɪɚɡɵɦɟɧɨɜɚɧɢɹ ɬɚɤɨɝɨ ɭɤɚɡɚɬɟɥɹ, ɨɩɟɪɚɰɢɢ «.*» ɢ «->*». ɉɭɫɬɶ ɨɞɧɢɦ ɢɡ ɱɥɟɧɨɜ ɫɬɪɭɤɬɭɪɵ AnyStruct ɹɜɥɹɟɬɫɹ ɭɤɚɡɚɬɟɥɶ pp1 ɧɚ ɞɚɧɧɨɟ ɬɢɩɚ int. Ɍɨɝɞɚ ɜɵɪɚɠɟɧɢɹ s1.*pp1 ɢ ps1->*pp1 ɨɛɟɫɩɟɱɚɬ ɞɨɫɬɭɩ ɤ ɡɧɚɱɟɧɢɸ ɞɚɧɧɨɝɨ, ɧɚ ɤɨɬɨɪɨɟ ɭɤɚɡɵɜɚɟɬ pp1 ɢɡ s1. ȼɵɲɟ ɨɬɦɟɱɚɥɨɫɶ, ɱɬɨ ɢɦɹ ɦɚɫɫɢɜɚ ɜ ɋɢ/ɋɢ++ ɢɧɬɟɪɩɪɟɬɢɪɭɟɬɫɹ ɤɚɤ ɭɤɚɡɚɬɟɥɶ-ɤɨɧɫɬɚɧɬɚ ɧɚ ɩɟɪɜɵɣ ɷɥɟɦɟɧɬ ɦɚɫɫɢɜɚ. Ⱦɥɹ ɪɚɡɵɦɟɧɨɜɚɧɢɹ ɭɤɚɡɚɬɟɥɹ, ɬ. ɟ. ɞɥɹ ɞɨɫɬɭɩɚ ɤ ɞɚɧɧɨɦɭ ɩɨ ɭɤɚɡɚɬɟɥɸ ɧɚ ɷɬɨ ɞɚɧɧɨɟ, ɫɥɭɠɢɬ ɨɩɟɪɚɰɢɹ «*» (ɡɜɟɡɞɨɱɤɚ). ɋɥɟɞɨɜɚɬɟɥɶɧɨ, ɟɫɥɢ ɜ ɩɪɨɝɪɚɦɦɟ ɨɛɴɹɜɥɟɧ ɦɚɫɫɢɜ int Array1[10];
ɬɨ ɜɵɪɚɠɟɧɢɟ *Array1=0 ɫɥɭɠɢɬ ɞɥɹ ɩɪɢɫɜɨɟɧɢɹ ɧɭɥɟɜɨɝɨ ɡɧɚɱɟɧɢɹ ɩɟɪɜɨɦɭ ɷɥɟɦɟɧɬɭ ɦɚɫɫɢɜɚ. ɑɬɨɛɵ ɨɛɪɚɬɢɬɶɫɹ ɤ ɩɪɨɢɡɜɨɥɶɧɨɦɭ ɷɥɟɦɟɧɬɭ ɦɚɫɫɢɜɚ, ɧɭɠɧɨ ɭɤɚɡɚɬɶ ɢɧɞɟɤɫ ɷɥɟɦɟɧɬɚ, ɧɚɩɪɢɦɟɪ, Array1[3]. ɗɬɨ ɜɵɪɚɠɟɧɢɟ ɷɤɜɢɜɚɥɟɧɬɧɨ ɜɵɪɚɠɟɧɢɸ *(Array1 + 3), ɬɨ ɟɫɬɶ ɬɪɟɛɭɟɬɫɹ ɫɧɚɱɚɥɚ ɭɜɟɥɢɱɢɬɶ ɭɤɚɡɚɬɟɥɶ Array1 ɧɚ 3 ɟɞɢɧɢɰɵ, ɚ ɡɚɬɟɦ ɪɚɡɵɦɟɧɨɜɚɬɶ ɩɨɥɭɱɟɧɧɵɣ ɭɤɚɡɚɬɟɥɶ. ɉɪɢ ɫɥɨɠɟɧɢɢ ɭɤɚɡɚɬɟɥɹ ɧɚ ɨɛɴɟɤɬ ɧɟɤɨɬɨɪɨɝɨ ɬɢɩɚ T ɫ ɰɟɥɵɦ ɱɢɫɥɨɦ N ɡɧɚɱɟɧɢɟ ɭɤɚɡɚɬɟɥɹ ɭɜɟɥɢɱɢɜɚɟɬɫɹ ɧɚ N, ɭɦɧɨɠɟɧɧɨɟ ɧɚ ɞɥɢɧɭ ɞɚɧɧɨɝɨ ɬɢɩɚ T. Ɉɬɦɟɬɢɦ, ɱɬɨ ɢɧɞɟɤɫ ɦɨɠɧɨ ɡɚɞɚɜɚɬɶ ɧɟ ɬɨɥɶɤɨ ɞɥɹ ɢɦɟɧ ɦɚɫɫɢɜɨɜ, ɧɨ ɢ ɞɥɹ ɥɸɛɨɝɨ ɬɢɩɚ ɭɤɚɡɚɬɟɥɹ, ɤɪɨɦɟ ɭɤɚɡɚɬɟɥɹ ɧɚ ɬɢɩ void: int *pint=&Array[4]; pint[2]=1;
21
ȼ ɷɬɨɦ ɩɪɢɦɟɪɟ ɭɤɚɡɚɬɟɥɶ pint ɢɧɢɰɢɚɥɢɡɢɪɨɜɚɧ ɚɞɪɟɫɨɦ ɩɹɬɨɝɨ ɷɥɟɦɟɧɬɚ ɦɚɫɫɢɜɚ Array, ɚ ɡɚɬɟɦ ɫɟɞɶɦɨɦɭ ɷɥɟɦɟɧɬɭ ɷɬɨɝɨ ɦɚɫɫɢɜɚ ɩɪɢɫɜɨɟɧɨ ɡɧɚɱɟɧɢɟ 1. ȼ ɤɚɱɟɫɬɜɟ ɢɧɞɟɤɫɚ ɦɨɠɟɬ ɡɚɞɚɜɚɬɶɫɹ ɥɸɛɨɟ ɜɵɪɚɠɟɧɢɟ ɫɨ ɡɧɚɱɟɧɢɟɦ ɰɟɥɨɝɨ ɬɢɩɚ. ɉɨɫɤɨɥɶɤɭ ɋɢ++ ɹɜɥɹɟɬɫɹ ɬɢɩɢɡɢɪɨɜɚɧɧɵɦ ɹɡɵɤɨɦ, ɜ ɧɟɦ ɨɩɪɟɞɟɥɟɧɵ ɹɜɧɵɟ ɢ ɧɟɹɜɧɵɟ ɩɪɟɨɛɪɚɡɨɜɚɧɢɹ ɬɢɩɨɜ ɞɚɧɧɵɯ. ɇɟɹɜɧɵɟ ɩɪɟɨɛɪɚɡɨɜɚɧɢɹ ɜɵɩɨɥɧɹɸɬɫɹ ɩɪɢ ɛɢɧɚɪɧɵɯ ɚɪɢɮɦɟɬɢɱɟɫɤɢɯ ɨɩɟɪɚɰɢɹɯ ɢ ɨɩɟɪɚɰɢɹɯ ɩɪɢɫɜɚɢɜɚɧɢɹ. ɗɬɢ ɩɪɟɨɛɪɚɡɨɜɚɧɢɹ, ɧɚɡɵɜɚɟɦɵɟ ɫɬɚɧɞɚɪɬɧɵɦɢ ɚɪɢɮɦɟɬɢɱɟɫɤɢɦɢ ɩɪɟɨɛɪɚɡɨɜɚɧɢɹɦɢ, ɜɵɩɨɥɧɹɸɬɫɹ ɜ ɫɥɟɞɭɸɳɟɣ ɩɨɫɥɟɞɨɜɚɬɟɥɶɧɨɫɬɢ: x ɟɫɥɢ ɨɞɢɧ ɨɩɟɪɚɧɞ ɢɦɟɟɬ ɬɢɩ long double, ɞɪɭɝɨɣ ɨɩɟɪɚɧɞ ɩɪɟɨɛɪɚɡɭɟɬɫɹ ɜ ɬɢɩ long double; x ɢɧɚɱɟ, ɟɫɥɢ ɨɞɢɧ ɨɩɟɪɚɧɞ ɢɦɟɟɬ ɬɢɩ double, ɞɪɭɝɨɣ ɨɩɟɪɚɧɞ ɩɪɟɨɛɪɚɡɭɟɬɫɹ ɜ ɬɢɩ double; x ɢɧɚɱɟ, ɟɫɥɢ ɨɞɢɧ ɨɩɟɪɚɧɞ ɢɦɟɟɬ ɬɢɩ float, ɞɪɭɝɨɣ ɨɩɟɪɚɧɞ ɩɪɟɨɛɪɚɡɭɟɬɫɹ ɜ ɬɢɩ float; x ɢɧɚɱɟ, ɟɫɥɢ ɨɞɢɧ ɨɩɟɪɚɧɞ ɢɦɟɟɬ ɬɢɩ unsigned long int, ɞɪɭɝɨɣ ɨɩɟɪɚɧɞ ɩɪɟɨɛɪɚɡɭɟɬɫɹ ɜ ɬɢɩ unsigned long int; x ɢɧɚɱɟ, ɟɫɥɢ ɨɞɢɧ ɨɩɟɪɚɧɞ ɢɦɟɟɬ ɬɢɩ long int, ɞɪɭɝɨɣ ɨɩɟɪɚɧɞ ɩɪɟɨɛɪɚɡɭɟɬɫɹ ɜ ɬɢɩ long int; x ɢɧɚɱɟ ɜɵɩɨɥɧɹɸɬɫɹ ɫɬɚɧɞɚɪɬɧɵɟ ɩɪɟɨɛɪɚɡɨɜɚɧɢɹ ɞɥɹ ɰɟɥɵɯ, ɩɪɢ ɷɬɨɦ ɬɢɩɵ char, short int ɢ ɛɢɬɨɜɵɟ ɩɨɥɹ ɬɢɩɚ int ɩɪɟɨɛɪɚɡɭɸɬɫɹ ɜ ɬɢɩ int; x ɜ ɨɫɬɚɥɶɧɵɯ ɫɥɭɱɚɹɯ ɨɩɟɪɚɧɞɵ ɢɦɟɸɬ ɬɢɩ int. əɜɧɨɟ ɩɪɟɨɛɪɚɡɨɜɚɧɢɟ ɬɢɩɨɜ ɦɨɠɟɬ ɛɵɬɶ ɡɚɞɚɧɨ ɜ ɞɜɭɯ ɮɨɪɦɚɯ. ɉɟɪɜɚɹ ɮɨɪɦɚ ɫɨɜɦɟɫɬɢɦɚ ɫ ɋɢ, ɜ ɧɟɣ ɡɚ ɢɦɟɧɟɦ ɬɢɩɚ ɜ ɤɪɭɝɥɵɯ ɫɤɨɛɤɚɯ ɡɚɩɢɫɵɜɚɟɬɫɹ ɩɪɟɨɛɪɚɡɭɟɦɨɟ ɡɧɚɱɟɧɢɟ, ɤɨɬɨɪɨɟ ɦɨɠɟɬ ɛɵɬɶ ɩɟɪɜɢɱɧɵɦ ɜɵɪɚɠɟɧɢɟɦ ɢɥɢ ɜɵɪɚɠɟɧɢɟɦ ɫ ɭɧɚɪɧɨɣ ɨɩɟɪɚɰɢɟɣ. ɂɦɹ ɬɢɩɚ ɜ ɷɬɨɦ ɫɥɭɱɚɟ ɦɨɠɟɬ ɛɵɬɶ ɩɪɟɞɫɬɚɜɥɟɧɨ ɩɨɫɥɟɞɨɜɚɬɟɥɶɧɨɫɬɶɸ ɨɩɢɫɚɬɟɥɟɣ, ɧɚɩɪɢɦɟɪ, (long int*)pp
ɢ ɨɩɪɟɞɟɥɹɟɬ ɩɪɟɨɛɪɚɡɨɜɚɧɢɟ ɧɟɤɨɬɨɪɨɝɨ ɞɚɧɧɨɝɨ pp ɜ ɬɢɩ ɭɤɚɡɚɬɟɥɹ ɧɚ long int. ȼɬɨɪɚɹ ɮɨɪɦɚ ɩɪɟɨɛɪɚɡɨɜɚɧɢɹ ɬɢɩɚ ɡɚɩɢɫɵɜɚɟɬɫɹ ɤɚɤ ɜɵɡɨɜ ɮɭɧɤɰɢɢ, ɩɪɢ ɷɬɨɦ ɢɦɹ ɬɢɩɚ ɞɨɥɠɧɨ ɡɚɞɚɜɚɬɶɫɹ ɢɞɟɧɬɢɮɢɤɚɬɨɪɨɦ, ɧɚɩɪɢɦɟɪ, int(x);
ɋɥɟɞɭɟɬ ɨɬɦɟɬɢɬɶ, ɱɬɨ ɪɟɡɭɥɶɬɚɬ ɹɜɧɨɝɨ ɩɪɟɨɛɪɚɡɨɜɚɧɢɹ ɧɟ ɹɜɥɹɟɬɫɹ L-ɡɧɚɱɟɧɢɟɦ.
Ɉɩɟɪɚɰɢɢ ɚɜɬɨɭɜɟɥɢɱɟɧɢɹ ɢ ɚɜɬɨɭɦɟɧɶɲɟɧɢɹ («++» ɢ «--») ɦɨɝɭɬ ɛɵɬɶ ɩɪɟɮɢɤɫɧɵɦɢ ɢ ɩɨɫɬɮɢɤɫɧɵɦɢ ɢ ɜɵɡɵɜɚɸɬ ɭɜɟɥɢɱɟɧɢɟ (ɭɦɟɧɶɲɟɧɢɟ) ɫɜɨɟɝɨ ɨɩɟɪɚɧɞɚ ɧɚ ɟɞɢɧɢɰɭ, ɬɨ ɟɫɬɶ ɜɵɪɚɠɟɧɢɟ ++x ɷɤɜɢɜɚɥɟɧɬɧɨ x=x+1, ɚ --x ɷɤɜɢɜɚɥɟɧɬɧɨ x=x-1. ɉɪɟɮɢɤɫɧɚɹ ɨɩɟɪɚɰɢɹ ɜɵɩɨɥɧɹɟɬɫɹ ɞɨ ɬɨɝɨ, ɤɚɤ ɟɟ ɨɩɟɪɚɧɞ ɛɭɞɟɬ ɢɫɩɨɥɶɡɨɜɚɧ ɜ ɜɵɱɢɫɥɟɧɢɢ ɜɵɪɚɠɟɧɢɹ, ɚ ɩɨɫɬ22
ɮɢɤɫɧɚɹ ɨɩɟɪɚɰɢɹ ɜɵɩɨɥɧɹɟɬɫɹ ɩɨɫɥɟ ɬɨɝɨ, ɤɚɤ ɟɟ ɨɩɟɪɚɧɞ ɛɭɞɟɬ ɢɫɩɨɥɶɡɨɜɚɧ ɜ ɜɵɪɚɠɟɧɢɢ, ɧɚɩɪɢɦɟɪ ɜ ɪɟɡɭɥɶɬɚɬɟ ɜɵɱɢɫɥɟɧɢɹ ɜɵɪɚɠɟɧɢɹ ++x*2+y--*3;
ɩɟɪɟɦɟɧɧɚɹ x ɫɧɚɱɚɥɚ ɭɜɟɥɢɱɢɜɚɟɬɫɹ ɧɚ 1, ɚ ɡɚɬɟɦ ɭɦɧɨɠɚɟɬɫɹ ɧɚ 2, ɚ ɩɟɪɟɦɟɧɧɚɹ y ɫɧɚɱɚɥɚ ɭɦɧɨɠɚɟɬɫɹ ɧɚ 3, ɡɚɬɟɦ ɭɦɟɧɶɲɚɟɬɫɹ ɧɚ 1. ȿɫɥɢ ɩɟɪɟɞ ɜɵɱɢɫɥɟɧɢɟɦ ɷɬɨɝɨ ɜɵɪɚɠɟɧɢɹ x ɢ y ɛɵɥɢ ɪɚɜɧɵ 1, ɬɨ ɪɟɡɭɥɶɬɚɬ ɜɵɪɚɠɟɧɢɹ ɛɭɞɟɬ ɪɚɜɟɧ 5. Ʉɪɨɦɟ ɬɨɝɨ, ɩɟɪɟɦɟɧɧɚɹ x ɩɨɥɭɱɢɬ ɡɧɚɱɟɧɢɟ 2, ɚ ɩɟɪɟɦɟɧɧɚɹ y - ɡɧɚɱɟɧɢɟ 0. Ɍɚɤɢɦ ɨɛɪɚɡɨɦ, ɨɩɟɪɚɰɢɢ ɚɜɬɨɭɜɟɥɢɱɟɧɢɹ ɢ ɚɜɬɨɭɦɟɧɶɲɟɧɢɹ ɜɫɟɝɞɚ ɞɚɸɬ ɩɨɛɨɱɧɵɣ ɷɮɮɟɤɬ, ɢɡɦɟɧɹɹ ɡɧɚɱɟɧɢɹ ɫɜɨɢɯ ɨɩɟɪɚɧɞɨɜ. Ɉɩɟɪɚɧɞɵ ɷɬɢɯ ɨɩɟɪɚɰɢɣ ɞɨɥɠɧɵ ɛɵɬɶ L-ɡɧɚɱɟɧɢɹɦɢ. Ɉɩɟɪɚɰɢɹ «~» (ɬɢɥɶɞɚ) ɩɪɢɦɟɧɹɟɬɫɹ ɬɨɥɶɤɨ ɤ ɰɟɥɨɦɭ ɡɧɚɱɟɧɢɸ ɢ ɡɚɦɟɧɹɟɬ ɜɫɟ ɛɢɬɵ ɫɜɨɟɝɨ ɨɩɟɪɚɧɞɚ ɫɨ ɡɧɚɱɟɧɢɟɦ 0 ɧɚ 1, ɚ ɛɢɬɵ ɫɨ ɡɧɚɱɟɧɢɟɦ 1 ɧɚ 0. Ʌɨɝɢɱɟɫɤɨɟ ɨɬɪɢɰɚɧɢɟ (ɨɩɟɪɚɰɢɹ «!») ɜɨɡɜɪɚɳɚɟɬ ɡɧɚɱɟɧɢɟ 0 ɰɟɥɨɝɨ ɬɢɩɚ, ɟɫɥɢ ɨɩɟɪɚɧɞ ɧɟ ɪɚɜɟɧ ɧɭɥɸ, ɢɥɢ ɡɧɚɱɟɧɢɟ 1, ɟɫɥɢ ɨɩɟɪɚɧɞ ɪɚɜɟɧ ɧɭɥɸ. Ɉɩɟɪɚɰɢɢ «ɭɧɚɪɧɵɣ +» ɢ «ɭɧɚɪɧɵɣ –» ɢɦɟɸɬ ɨɛɵɱɧɵɣ ɦɚɬɟɦɚɬɢɱɟɫɤɢɣ ɫɦɵɫɥ, ɡɧɚɤ «+» ɧɟ ɢɡɦɟɧɹɟɬ ɡɧɚɱɟɧɢɹ ɨɩɟɪɚɧɞɚ, ɡɧɚɤ «-» ɦɟɧɹɟɬ ɡɧɚɤ ɨɩɟɪɚɧɞɚ ɧɚ ɩɪɨɬɢɜɨɩɨɥɨɠɧɵɣ. Ⱦɥɹ ɩɨɥɭɱɟɧɢɹ ɚɞɪɟɫɚ ɨɩɟɪɚɧɞɚ, ɹɜɥɹɸɳɟɝɨɫɹ L-ɡɧɚɱɟɧɢɟɦ, ɩɪɢɦɟɧɹɟɬɫɹ ɨɩɟɪɚɰɢɹ «&» (ɚɦɩɟɪɫɚɧɞ). Ɋɟɡɭɥɶɬɚɬɨɦ ɞɟɣɫɬɜɢɹ ɷɬɨɣ ɨɩɟɪɚɰɢɢ ɹɜɥɹɟɬɫɹ ɭɤɚɡɚɬɟɥɶ ɧɚ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɣ ɬɢɩ ɞɚɧɧɵɯ. Ɋɚɡɵɦɟɧɨɜɚɧɢɟ ɭɤɚɡɚɬɟɥɹ, ɬɨ ɟɫɬɶ ɩɨɥɭɱɟɧɢɟ ɡɧɚɱɟɧɢɹ ɞɚɧɧɨɝɨ ɩɨ ɭɤɚɡɚɬɟɥɸ ɧɚ ɧɟɝɨ, ɨɛɟɫɩɟɱɢɜɚɟɬɫɹ ɨɩɟɪɚɰɢɟɣ «*» (ɡɜɟɡɞɨɱɤɚ). Ɋɟɡɭɥɶɬɚɬ ɨɩɟɪɚɰɢɢ ɪɚɡɵɦɟɧɨɜɚɧɢɹ ɹɜɥɹɟɬɫɹ L-ɡɧɚɱɟɧɢɟɦ. ȼ ɋɢ++ ɨɩɪɟɞɟɥɟɧɵ ɨɩɟɪɚɰɢɢ ɪɚɡɦɟɳɟɧɢɹ ɞɚɧɧɵɯ ɜ ɞɢɧɚɦɢɱɟɫɤɨɣ ɩɚɦɹɬɢ ɢ ɭɞɚɥɟɧɢɹ ɞɢɧɚɦɢɱɟɫɤɢɯ ɞɚɧɧɵɯ ɢɡ ɩɚɦɹɬɢ. Ɉɩɟɪɚɰɢɹ new ɬɪɟɛɭɟɬ ɜ ɤɚɱɟɫɬɜɟ ɨɩɟɪɚɧɞɚ ɢɦɹ ɬɢɩɚ ɢ ɩɪɟɞɧɚɡɧɚɱɟɧɚ ɞɥɹ ɪɚɡɦɟɳɟɧɢɹ ɞɚɧɧɵɯ ɭɤɚɡɚɧɧɨɝɨ ɬɢɩɚ ɜ ɞɢɧɚɦɢɱɟɫɤɨɣ ɩɚɦɹɬɢ. Ɋɟɡɭɥɶɬɚɬɨɦ ɨɩɟɪɚɰɢɢ ɹɜɥɹɟɬɫɹ ɭɤɚɡɚɬɟɥɶ ɧɚ ɞɚɧɧɵɟ. ɉɪɢ ɧɟɜɨɡɦɨɠɧɨɫɬɢ ɜɵɞɟɥɢɬɶ ɩɚɦɹɬɶ ɨɩɟɪɚɰɢɹ new ɜɨɡɜɪɚɳɚɟɬ ɡɧɚɱɟɧɢɟ NULL – ɩɪɟɞɨɩɪɟɞɟɥɟɧɧɭɸ ɤɨɧɫɬɚɧɬɭ, ɢɦɟɸɳɭɸ ɧɭɥɟɜɨɟ ɡɧɚɱɟɧɢɟ ɩɪɚɤɬɢɱɟɫɤɢ ɜɨ ɜɫɟɯ ɤɨɦɩɢɥɹɬɨɪɚɯ ɋɢ ɢ ɋɢ++. ɉɚɦɹɬɶ, ɜɵɞɟɥɹɟɦɭɸ ɨɩɟɪɚɰɢɟɣ new, ɦɨɠɧɨ ɢɧɢɰɢɚɥɢɡɢɪɨɜɚɬɶ, ɭɤɚɡɚɜ ɡɚ ɢɦɟɧɟɦ ɬɢɩɚ ɫɤɚɥɹɪɧɵɯ ɞɚɧɧɵɯ ɧɚɱɚɥɶɧɨɟ ɡɧɚɱɟɧɢɟ ɜ ɤɪɭɝɥɵɯ ɫɤɨɛɤɚɯ, ɡɚɞɚɧɢɟ ɧɚɱɚɥɶɧɵɯ ɡɧɚɱɟɧɢɣ ɞɥɹ ɚɝɪɟɝɚɬɨɜ ɞɚɧɧɵɯ ɛɭɞɟɬ ɪɚɫɫɦɨɬɪɟɧɨ ɩɨɡɠɟ. ɉɪɢɦɟɪɵ ɩɪɢɦɟɧɟɧɢɹ ɨɩɟɪɚɰɢɢ new: // ɫɨɡɞɚɧɢɟ ɨɛɴɟɤɬɚ ɬɢɩɚ int ɢ // ɩɨɥɭɱɟɧɢɟ ɭɤɚɡɚɬɟɥɹ ɧɚ ɧɟɝɨ int *ip2 = new int(2); /* ɬɨ ɠɟ ɫ ɭɫɬɚɧɨɜɤɨɣ ɧɚɱɚɥɶɧɨɝɨ ɡɧɚɱɟɧɢɹ, ɪɚɜɧɨɝɨ 2 */ inr *intArray = new int [10]; /* ɦɚɫɫɢɜ ɢɡ 10 ɷɥɟɦɟɧɬɨɜ ɬɢɩɚ int */ double **matr = new double [m][n]; /* ɦɚɬɪɢɰɚ ɢɡ m ɫɬɪɨɤ ɢ n ɫɬɨɥɛɰɨɜ */ int *ip = new int;
23
Ⱦɚɧɧɵɟ, ɪɚɡɦɟɳɟɧɧɵɟ ɜ ɞɢɧɚɦɢɱɟɫɤɨɣ ɩɚɦɹɬɢ ɨɩɟɪɚɰɢɟɣ new, ɭɞɚɥɹɸɬɫɹ ɢɡ ɩɚɦɹɬɢ ɨɩɟɪɚɰɢɟɣ delete ɫ ɨɩɟɪɚɧɞɨɦ-ɭɤɚɡɚɬɟɥɟɦ, ɡɧɚɱɟɧɢɟ ɤɨɬɨɪɨɝɨ ɩɨɥɭɱɟɧɨ ɨɩɟɪɚɰɢɟɣ new, ɧɚɩɪɢɦɟɪ, delete intArray; delete ip2; Ɉɩɟɪɚɰɢɹ delete ɬɨɥɶɤɨ ɨɫɜɨɛɨɠɞɚɟɬ ɞɢɧɚɦɢɱɟɫɤɭɸ ɩɚɦɹɬɶ, ɧɨ ɧɟ
ɢɡɦɟɧɹɟɬ ɡɧɚɱɟɧɢɟ ɭɤɚɡɚɬɟɥɹ-ɨɩɟɪɚɧɞɚ. ɉɪɨɝɪɚɦɦɢɫɬ ɞɨɥɠɟɧ ɩɨɦɧɢɬɶ, ɱɬɨ ɩɨɫɥɟ ɨɫɜɨɛɨɠɞɟɧɢɹ ɩɚɦɹɬɢ ɢɫɩɨɥɶɡɨɜɚɬɶ ɷɬɨɬ ɭɤɚɡɚɬɟɥɶ ɞɥɹ ɨɛɪɚɳɟɧɢɹ ɤ ɞɚɧɧɵɦ ɧɟɥɶɡɹ. Ɋɚɡɦɟɪ ɞɚɧɧɨɝɨ ɢɥɢ ɬɢɩɚ ɞɚɧɧɨɝɨ ɜ ɛɚɣɬɚɯ ɦɨɠɧɨ ɩɨɥɭɱɢɬɶ ɩɨ ɨɩɟɪɚɰɢɢ sizeof. Ɉɩɟɪɚɧɞ ɦɨɠɟɬ ɛɵɬɶ ɥɸɛɨɝɨ ɬɢɩɚ, ɤɪɨɦɟ ɬɢɩɚ ɮɭɧɤɰɢɢ ɢ ɛɢɬɨɜɨɝɨ ɩɨɥɹ. ȿɫɥɢ ɨɩɟɪɚɧɞɨɦ ɹɜɥɹɟɬɫɹ ɢɦɹ ɬɢɩɚ, ɨɧɨ ɞɨɥɠɧɨ ɡɚɤɥɸɱɚɬɶɫɹ ɜ ɫɤɨɛɤɢ. ȼɨɡɜɪɚɳɚɟɦɨɟ ɡɧɚɱɟɧɢɟ ɢɦɟɟɬ ɩɪɟɞɨɩɪɟɞɟɥɟɧɧɵɣ ɬɢɩ size_t ɰɟɥɵɣ ɬɢɩ, ɪɚɡɦɟɪ ɤɨɬɨɪɨɝɨ ɨɩɪɟɞɟɥɹɟɬɫɹ ɪɟɚɥɢɡɚɰɢɟɣ ɤɨɦɩɢɥɹɬɨɪɚ. Ɉɛɵɱɧɨ ɬɢɩɭ size_t ɫɨɨɬɜɟɬɫɬɜɭɟɬ unsigned int. Ɋɚɡɦɟɪ ɦɚɫɫɢɜɚ ɪɚɜɟɧ ɱɢɫɥɭ ɛɚɣɬ, ɡɚɧɢɦɚɟɦɵɯ ɦɚɫɫɢɜɨɦ ɜ ɩɚɦɹɬɢ, ɪɚɡɦɟɪ ɫɬɪɨɤɨɜɨɝɨ ɥɢɬɟɪɚɥɚ ɷɬɨ «ɱɢɫɥɨ ɡɧɚɤɨɜ ɜ ɥɢɬɟɪɚɥɟ + 1», ɬɨ ɟɫɬɶ ɡɚɜɟɪɲɚɸɳɢɣ ɧɭɥɟɜɨɣ ɛɚɣɬ ɭɱɢɬɵɜɚɟɬɫɹ ɩɪɢ ɨɩɪɟɞɟɥɟɧɢɢ ɞɥɢɧɵ ɥɢɬɟɪɚɥɚ. Ɂɧɚɱɟɧɢɟ, ɜɨɡɜɪɚɳɚɟɦɨɟ sizeof, ɹɜɥɹɟɬɫɹ ɤɨɧɫɬɚɧɬɨɣ. Ȼɢɧɚɪɧɵɟ ɚɪɢɮɦɟɬɢɱɟɫɤɢɟ ɨɩɟɪɚɰɢɢ ɭɦɧɨɠɟɧɢɹ («*»), ɞɟɥɟɧɢɹ («/»), ɩɨɥɭɱɟɧɢɹ ɨɫɬɚɬɤɚ ɨɬ ɞɟɥɟɧɢɹ ɧɚɰɟɥɨ («%»), ɫɥɨɠɟɧɢɹ («+») ɢ ɜɵɱɢɬɚɧɢɹ («-») ɢɦɟɸɬ ɨɛɵɱɧɵɣ ɫɦɵɫɥ ɢ ɨɛɵɱɧɵɣ ɨɬɧɨɫɢɬɟɥɶɧɵɣ ɩɪɢɨɪɢɬɟɬ. ȿɫɥɢ ɨɩɟɪɚɧɞɵ ɚɪɢɮɦɟɬɢɱɟɫɤɨɣ ɨɩɟɪɚɰɢɢ ɢɦɟɸɬ ɪɚɡɧɵɟ ɬɢɩɵ, ɩɪɟɞɜɚɪɢɬɟɥɶɧɨ ɜɵɩɨɥɧɹɸɬɫɹ ɫɬɚɧɞɚɪɬɧɵɟ ɚɪɢɮɦɟɬɢɱɟɫɤɢɟ ɩɪɟɨɛɪɚɡɨɜɚɧɢɹ, ɢ ɬɢɩ ɪɟɡɭɥɶɬɚɬɚ ɨɩɟɪɚɰɢɢ ɨɩɪɟɞɟɥɹɟɬɫɹ ɨɛɳɢɦ ɬɢɩɨɦ ɨɩɟɪɚɧɞɨɜ ɩɨɫɥɟ ɫɬɚɧɞɚɪɬɧɵɯ ɩɪɟɨɛɪɚɡɨɜɚɧɢɣ. ɋɥɟɞɨɜɚɬɟɥɶɧɨ, ɜɵɪɚɠɟɧɢɟ 7/2 ɛɭɞɟɬ ɢɦɟɬɶ ɡɧɚɱɟɧɢɟ 3 ɬɢɩɚ int, ɬɚɤ ɤɚɤ ɨɛɚ ɨɩɟɪɚɧɞɚ ɢɦɟɸɬ ɬɢɩ int, ɚ ɜɵɪɚɠɟɧɢɟ 7.0/2 ɞɚɫɬ ɪɟɡɭɥɶɬɚɬ 3.5 ɬɢɩɚ double, ɩɨɫɤɨɥɶɤɭ ɷɬɨɬ ɬɢɩ ɢɦɟɟɬ ɩɟɪɜɵɣ ɨɩɟɪɚɧɞ. Ɉɩɟɪɚɰɢɢ ɨɬɧɨɲɟɧɢɹ ɞɜɭɯ ɜɵɪɚɠɟɧɢɣ («=») ɬɪɟɛɭɸɬ ɨɩɟɪɚɧɞɨɜ ɚɪɢɮɦɟɬɢɱɟɫɤɨɝɨ ɬɢɩɚ ɢɥɢ ɠɟ ɨɛɚ ɨɩɟɪɚɧɞɚ ɞɨɥɠɧɵ ɛɵɬɶ ɭɤɚɡɚɬɟɥɹɦɢ ɧɚ ɨɞɢɧɚɤɨɜɵɣ ɬɢɩ. ȼ ɫɥɭɱɚɟ ɨɩɟɪɚɧɞɨɜ ɚɪɢɮɦɟɬɢɱɟɫɤɨɝɨ ɬɢɩɚ ɜɵɱɢɫɥɹɸɬɫɹ ɡɧɚɱɟɧɢɹ ɨɩɟɪɚɧɞɨɜ, ɜɵɩɨɥɧɹɸɬɫɹ ɫɬɚɧɞɚɪɬɧɵɟ ɚɪɢɮɦɟɬɢɱɟɫɤɢɟ ɩɪɟɨɛɪɚɡɨɜɚɧɢɹ ɢ ɜɨɡɜɪɚɳɚɟɬɫɹ 1 ɬɢɩɚ int, ɟɫɥɢ ɨɬɧɨɲɟɧɢɟ ɜɵɩɨɥɧɹɟɬɫɹ (ɢɫɬɢɧɧɨ), ɢɥɢ 0, ɟɫɥɢ ɨɬɧɨɲɟɧɢɟ ɧɟ ɜɵɩɨɥɧɹɟɬɫɹ (ɥɨɠɧɨ). Ʉɨɝɞɚ ɫɪɚɜɧɢɜɚɸɬɫɹ ɞɜɚ ɭɤɚɡɚɬɟɥɹ, ɪɟɡɭɥɶɬɚɬ ɡɚɜɢɫɢɬ ɨɬ ɨɬɧɨɫɢɬɟɥɶɧɨɝɨ ɪɚɡɦɟɳɟɧɢɹ ɜ ɩɚɦɹɬɢ ɨɛɴɟɤɬɨɜ, ɧɚ ɤɨɬɨɪɵɟ ɫɫɵɥɚɸɬɫɹ ɭɤɚɡɚɬɟɥɢ. Ɉɩɟɪɚɰɢɢ ɫɪɚɜɧɟɧɢɹ «==» (ɪɚɜɧɨ) ɢ «!=» (ɧɟ ɪɚɜɧɨ) ɜɵɩɨɥɧɹɸɬɫɹ ɚɧɚɥɨɝɢɱɧɵɦ ɨɛɪɚɡɨɦ, ɧɨ ɢɦɟɸɬ ɦɟɧɶɲɢɣ ɩɪɢɨɪɢɬɟɬ. ȼɵɪɚɠɟɧɢɹ ɨɬɧɨɲɟɧɢɣ ɦɨɝɭɬ ɫɨɟɞɢɧɹɬɶɫɹ ɥɨɝɢɱɟɫɤɢɦɢ ɫɜɹɡɤɚɦɢ «&&» (ɤɨɧɴɸɧɤɰɢɹ, ɥɨɝɢɱɟɫɤɨɟ ɭɦɧɨɠɟɧɢɟ) ɢ «||» (ɞɢɡɴɸɧɤɰɢɹ, ɥɨɝɢɱɟɫɤɨɟ ɫɥɨɠɟɧɢɟ). ȼ ɨɛɳɟɦ ɫɥɭɱɚɟ ɨɩɟɪɚɧɞɚɦɢ ɥɨɝɢɱɟɫɤɢɯ ɫɜɹɡɨɤ ɦɨɝɭɬ ɛɵɬɶ ɥɸɛɵɟ ɫɤɚɥɹɪɧɵɟ ɡɧɚɱɟɧɢɹ ɢ ɨɩɟɪɚɰɢɹ «&&» ɞɚɟɬ ɪɟɡɭɥɶɬɚɬ, ɪɚɜɧɵɣ 1 ɬɢɩɚ 24
int, ɟɫɥɢ ɨɛɚ ɨɩɟɪɚɧɞɚ ɢɦɟɸɬ ɧɟɧɭɥɟɜɵɟ ɡɧɚɱɟɧɢɹ, ɚ ɨɩɟɪɚɰɢɹ «||» ɞɚɟɬ ɪɟɡɭɥɶɬɚɬ, ɪɚɜɧɵɣ 0, ɟɫɥɢ ɡɧɚɱɟɧɢɹ ɨɛɨɢɯ ɨɩɟɪɚɧɞɨɜ ɧɭɥɟɜɵɟ. ɉɪɢɦɟɧɹ-
ɟɬɫɹ ɫɨɤɪɚɳɟɧɧɚɹ ɮɨɪɦɚ ɜɵɱɢɫɥɟɧɢɹ ɡɧɚɱɟɧɢɹ ɥɨɝɢɱɟɫɤɢɯ ɫɜɹɡɨɤ: ɟɫɥɢ ɜ ɨɩɟɪɚɰɢɢ «&&» ɩɟɪɜɵɣ ɨɩɟɪɚɧɞ ɪɚɜɟɧ ɧɭɥɸ, ɬɨ ɜɬɨɪɨɣ ɨɩɟɪɚɧɞ ɧɟ ɜɵɱɢɫɥɹɟɬɫɹ ɢ ɜɨɡɜɪɚɳɚɟɬɫɹ 0, ɟɫɥɢ ɜ ɨɩɟɪɚɰɢɢ «||» ɩɟɪɜɵɣ ɨɩɟɪɚɧɞ ɧɟ ɪɚɜɟɧ ɧɭɥɸ, ɬɨ ɜɬɨɪɨɣ ɨɩɟɪɚɧɞ ɧɟ ɜɵɱɢɫɥɹɟɬɫɹ ɢ ɜɨɡɜɪɚɳɚɟɬɫɹ ɡɧɚɱɟɧɢɟ 1. Ʉɚɤ ɭɠɟ ɨɬɦɟɱɚɥɨɫɶ, ɩɪɢɫɜɚɢɜɚɧɢɟ, ɨɛɨɡɧɚɱɚɟɦɨɟ ɡɧɚɤɨɦ «=» ɜ ɋɢ/ɋɢ++ ɪɚɫɫɦɚɬɪɢɜɚɟɬɫɹ ɤɚɤ ɨɩɟɪɚɰɢɹ ɢ ɜɨɡɜɪɚɳɚɟɬ ɡɧɚɱɟɧɢɟ, ɤɨɬɨɪɨɟ ɛɵɥɨ ɩɪɢɫɜɨɟɧɨ ɥɟɜɨɦɭ ɨɩɟɪɚɧɞɭ. Ɉɩɟɪɚɰɢɹ ɩɪɢɫɜɚɢɜɚɧɢɹ ɜɵɱɢɫɥɹɟɬɫɹ ɫɩɪɚɜɚ ɧɚɥɟɜɨ, ɬɨ ɟɫɬɶ ɫɧɚɱɚɥɚ ɜɵɱɢɫɥɹɟɬɫɹ ɩɪɢɫɜɚɢɜɚɟɦɨɟ ɡɧɚɱɟɧɢɟ, ɡɚɬɟɦ ɜɵɩɨɥɧɹɟɬɫɹ ɩɪɢɫɜɚɢɜɚɧɢɟ. ɗɬɨ ɩɨɡɜɨɥɹɟɬ ɡɚɩɢɫɵɜɚɬɶ ɜɵɪɚɠɟɧɢɹ ɜɢɞɚ x=y=z=1;
ɞɥɹ ɭɫɬɚɧɨɜɤɢ ɨɞɢɧɚɤɨɜɵɯ ɡɧɚɱɟɧɢɣ ɧɟɫɤɨɥɶɤɢɦ ɩɟɪɟɦɟɧɧɵɦ. Ɇɨɠɧɨ, ɯɨɬɹ ɷɬɨ ɢ ɫɧɢɠɚɟɬ ɧɚɝɥɹɞɧɨɫɬɶ ɩɪɨɝɪɚɦɦɵ, ɫɬɪɨɢɬɶ ɢ ɜɵɪɚɠɟɧɢɹ ɫ ɩɨɛɨɱɧɵɦ ɷɮɮɟɤɬɨɦ ɜɢɞɚ (x=2)*(y=3)+(z=4);
Ɋɟɡɭɥɶɬɚɬɨɦ ɷɬɨɝɨ ɜɵɪɚɠɟɧɢɹ ɛɭɞɟɬ 24, ɧɨ ɨɞɧɨɜɪɟɦɟɧɧɨ ɩɟɪɟɦɟɧɧɵɟ x, y ɢ z ɩɨɥɭɱɚɬ ɧɨɜɵɟ ɡɧɚɱɟɧɢɹ. Ʉɪɨɦɟ ɩɪɨɫɬɨɝɨ ɩɪɢɫɜɚɢɜɚɧɢɹ ɢɦɟɟɬɫɹ ɧɚɛɨɪ ɫɨɫɬɚɜɧɵɯ ɨɩɟɪɚɰɢɣ ɩɪɢɫɜɚɢɜɚɧɢɹ, ɜ ɤɨɬɨɪɵɯ ɩɪɢɫɜɚɢɜɚɧɢɟ ɫɨɜɦɟɳɚɟɬɫɹ ɫ ɭɤɚɡɚɧɧɨɣ ɛɢɧɚɪɧɨɣ ɨɩɟɪɚɰɢɟɣ. Ɂɚɩɢɫɶ x+=y ɷɤɜɢɜɚɥɟɧɬɧɚ ɜɵɪɚɠɟɧɢɸ x=x+y. Ⱦɥɹ ɰɟɥɵɯ ɨɩɟɪɚɧɞɨɜ ɨɩɪɟɞɟɥɟɧɵ ɨɩɟɪɚɰɢɢ ɫɞɜɢɝɚ ɜɥɟɜɨ ɢ ɜɩɪɚɜɨ. ɉɪɢ ɜɵɩɨɥɧɟɧɢɢ ɨɩɟɪɚɰɢɢ e1>e2) ɟɫɥɢ e1 ɢɦɟɟɬ ɬɢɩ unsigned, ɨɫɜɨɛɨɠɞɚɸɳɢɟɫɹ ɥɟɜɵɟ ɪɚɡɪɹɞɵ ɡɚɩɨɥɧɹɸɬɫɹ ɧɭɥɹɦɢ, ɚ ɩɪɢ e1 ɬɢɩɚ signed ɜ ɨɫɜɨɛɨɠɞɚɸɳɢɯɫɹ ɥɟɜɵɯ ɪɚɡɪɹɞɚɯ ɩɨɜɬɨɪɹɟɬɫɹ ɡɧɚɤɨɜɵɣ ɪɚɡɪɹɞ. ɇɚɞ ɰɟɥɵɦɢ ɨɩɟɪɚɧɞɚɦɢ ɞɨɩɭɫɬɢɦɵ ɨɩɟɪɚɰɢɢ ɩɨɪɚɡɪɹɞɧɨɝɨ ɥɨɝɢɱɟɫɤɨɝɨ ɭɦɧɨɠɟɧɢɹ, ɥɨɝɢɱɟɫɤɨɝɨ ɫɥɨɠɟɧɢɹ ɢ ɢɫɤɥɸɱɚɸɳɟɝɨ «ɢɥɢ» (ɨɬɪɢɰɚɧɢɹ ɪɚɜɧɨɡɧɚɱɧɨɫɬɢ). ȼ ɷɬɢɯ ɨɩɟɪɚɰɢɹɯ ɨɩɟɪɚɧɞɵ ɪɚɫɫɦɚɬɪɢɜɚɸɬɫɹ ɤɚɤ ɩɨɫɥɟɞɨɜɚɬɟɥɶɧɨɫɬɢ ɛɢɬɨɜ, ɢ ɨɩɟɪɚɰɢɹ ɜɵɩɨɥɧɹɟɬɫɹ ɧɚɞ ɤɚɠɞɨɣ ɩɚɪɨɣ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɯ ɪɚɡɪɹɞɨɜ ɢɡ ɨɛɨɢɯ ɨɩɟɪɚɧɞɨɜ. ɇɚɩɪɢɦɟɪ, ɪɟɡɭɥɶɬɚɬɨɦ ɜɵɪɚɠɟɧɢɹ x>>(p-n+1))&(~(~0> x1; cin >> x2; cin >> st;
ȼ ɡɚɤɥɸɱɟɧɢɟ ɩɪɢɜɟɞɟɦ ɩɪɢɦɟɪ ɩɪɨɫɬɨɣ ɩɪɨɝɪɚɦɦɵ, ɡɚɩɪɚɲɢɜɚɸɳɟɣ ɭ ɩɨɥɶɡɨɜɚɬɟɥɹ ɞɜɚ ɰɟɥɵɯ ɱɢɫɥɚ ɢ ɜɵɜɨɞɹɳɟɣ ɧɚ ɷɤɪɚɧ ɢɯ ɫɭɦɦɭ: #include int x, y; int main() { coutx; couty; cout