ﳏﺘﻮﻳﺎﺕ ﺍﻟﻜﺘﺎﺏ ﺑﻨﻈﺮﺓ ﺳﺮﻳﻌﺔ
ﺣﻮﻝ ﺍﻟﻜﺘﺎﺏ ١٨............................................................................................. ﺍﳌﻘﺪﻣﺔ ١٩................................................................................................... ﺍﻟﻔﺼﻞ ﺍﻷﻭﻝ – ﺃﺳﺎﺳﻴﺎﺕ ﰲ ﻟﻐﺔ ........................................................................... C ١,١ﺍﻷﺩﻭﺍﺕ ﺍﻟﻼﺯﻣﺔ ٢٢................................................................................. ١,٢ﺍﻟﺒﺪﺀ ﻣﻊ ﻟﻐﺔ ٢٥.................................................................................. C ١,٣ﺍﳌﺘﻐﲑﺍﺕ ﻭ ﺍﻟﺜﻮﺍﺑﺖ ٣٤..................................................... Variables and Constants ١,٤ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ٤٥........................................................................... Comments ١,٥ﺍﻹﺩﺧﺎﻝ ٤٨.................................................................................. input ١,٦ﺍﳌﺆﺛﺮﺍﺕ ٥١............................................................................. Operators ١,٧ﺍﻟﻘﺮﺍﺭﺍﺕ ٦٠....................................................................... if, else, else…if ١,٨ﻋﻨﺎﺻﺮ ﻟﻐﺔ ٦٤.................................................................................... C ١,٩ﻣﻠﺨﺺ ﻟﻠﻔﺼﻞ ﺍﻷﻭﻝ ،ﻣﻊ ﺇﺿﺎﻓﺎﺕ ٦٩............................................................... ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﱐ – ﺃﺳﺎﺳﻴﺎﺕ ﰲ ﻟﻐﺔ ....................................................................... (٢) C ٢,١ﺍﻟﻘﺮﺍﺭ ٨١................................................................................... Switch ٢,٢ﺣﻠﻘﺎﺕ ﺍﻟﺘﻜﺮﺍﺭ ٨٦.................................................................. Repeated loop ٢,٣ﺍﳌﺼﻔﻮﻓﺎﺕ ١٠٠............................................................................. Arrays ٢,٤ﺍﳌﺆﺷﺮﺍﺕ ١١٤............................................................................ Pointers ٢,٥ﺍﻟﺪﻭﺍﻝ ١٢٥............................................................................. Functions ٢,٦ﺍﳌﻠﻔﺎﺕ ﺍﻟﺮﺃﺳﻴﺔ ١٣٥................................................................... Header files ٢,٧ﺍﻹﺩﺧﺎﻝ ﻭ ﺍﻹﺧﺮﺍﺝ ﰲ ﺍﳌﻠﻔﺎﺕ ١٣٨........................................................ Files I/O ٢,٨ﺍﻟﺘﺮﺍﻛﻴﺐ ١٤٧........................................................................... structures ٢,٩ﻣﻠﺨﺺ ﻟﻠﻔﺼﻞ ﺍﻟﺜﺎﱐ ،ﻣﻌﺎ ﺇﺿﺎﻓﺎﺕ ١٥٧.............................................................. ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﻟﺚ – ﺍﻟﺘﻘﺪﻡ ﰲ ﻟﻐﺔ .............................................................................. C ٣,١ﺍﳊﺴﺎﺏ ١٧٦......................................................................... Enumeration ٣,٢ﻭﺳﺎﺋﻂ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ١٨٢............................................... Command-line Arguments ٣,٣ﺍﻟﺘﻮﺟﻴﻬﺎﺕ )١٨٥.......................................................... Directives(Preprocessor ٣,٤ﺩﻭﺍﻝ ﺫﺍﺕ ﻭﺳﺎﺋﻂ ﻏﲑ ﳏﺪﺩﺓ ١٩٢................................................................... ٣,٥ﺍﳌﻜﺘﺒﺔ ﺍﻟﻘﻴﺎﺳﻴﺔ ١٩٥............................................................... Standard Library ﺍﳋﺎﲤﺔ ٢٤١..................................................................................................
ﺟﺪﻭﻝ ﺍﻷﺷﻜﺎﻝ )ﺍﻟﺼﻮﺭ( ..................................................................................... ﺟﺪﻭﻝ ﺍﳉﺪﺍﻭﻝ .............................................................................................. ﺟﺪﻭﻝ ﺍﻟﱪﺍﻣﺞ ............................................................................................... ﺃﻫﻢ ﺍﳌﺮﺍﺟﻊ ..................................................................................................
ﺟﺪﻭﻝ ﺍﶈﺘﻮﻳﺎﺕ
ﺣﻮﻝ ﺍﻟﻜﺘﺎﺏ ١٨............................................................................................. ﺍﳌﻘﺪﻣﺔ ١٩................................................................................................... ﺍﻟﻔﺼﻞ ﺍﻷﻭﻝ – ﺃﺳﺎﺳﻴﺎﺕ ﰲ ﻟﻐﺔ ........................................................................... C ١,١ﺍﻷﺩﻭﺍﺕ ﺍﻟﻼﺯﻣﺔ ٢٢..................................................................................... ١,١,١ﳏﺮﺭ ﻧﺼﻮﺹ ٢٢..................................................................... texts editor ١,١,٢ﻣﺘﺮﺟﻢ ٢٢............................................................................. compiler ١,١,٣ﺍﳌﺮﺑﻂ ٢٤................................................................................. linker ١,٢ﺍﻟﺒﺪﺀ ﻣﻊ ﻟﻐﺔ ٢٥...................................................................................... C ١,٢,١ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻷﻋﺪﺍﺩ ٢٩............................................................................ ١,٢,٢ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ٣٢.............................................................................. ١,٢,٣ﲤﺎﺭﻳﻦ ٣٣....................................................................................... ١,٣ﺍﳌﺘﻐﲑﺍﺕ ﻭ ﺍﻟﺜﻮﺍﺑﺖ ٣٤..................................................... Variables and Constants ١,٣,١ﻧﻮﻉ ﺍﳌﺘﻐﲑ ٣٥..................................................................... Variable Type ١,٣,١,١ﻣﺘﻐﲑ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ٣٥............................................................. int ١,٣,١,٢ﻣﺘﻐﲑ ﺍﻷﻋﺪﺍﺩ ﺍﳊﻘﻴﻘﻴﺔ ٣٥............................................................. float ١,٣,١,٣ﻣﺘﻐﲑ ﺍﻷﻋﺪﺍﺩ ﺍﳊﻘﻴﻘﻴﺔ ٣٦........................................................... double ١,٣,١,٤ﻣﺘﻐﲑ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ٣٦.......................................................... short ١,٣,١,٥ﻣﺘﻐﲑ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ٣٦........................................................... long ١,٣,١,٥ﻣﺘﻐﲑ ﺍﻟﺮﻣﻮﺯ ٣٧...................................................................... char ١,٣,٢ﺍﺳﻢ ﺍﳌﺘﻐﲑ ٣٧.................................................................... Variable Name ١,٣,٣ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ ٣٧.....................................................................Variable Value ١,٣,٤ﺃﻣﺜﻠﺔ ﺣﻮﻝ ﺍﳌﺘﻐﲑﺍﺕ ٣٧.......................................................................... ١,٣,٥ﺍﻷﻋﺪﺍﺩ ﺍﳌﻮﺟﺒﺔ ﻭ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺴﺎﻟﺒﺔ ٤٠............................................................... ١,٣,٦ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ٤٣.............................................................................. ١,٣,٧ﲤﺎﺭﻳﻦ ٤٤....................................................................................... ١,٤ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ٤٥........................................................................... Comments ١,٤,١ﻓﺎﺋﺪﺓ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ٤٥............................................................................... ١,٤,٢ﺃﻧﻮﺍﻉ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ٤٥.............................................................................. ١,٤,٢,١ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﺑﺎﻟﻨﺼﻮﺹ ﺍﻟﻄﻮﻳﻠﺔ ٤٥............................................................ ١,٤,٢,٢ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﺑﺎﻷﺳﻄﺮ ٤٥..................................................................... ١,٤,٣ﻛﻴﻒ ﻳﺴﺘﻌﻤﻞ ﺍﳌﱪﳎﻮﻥ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ٤٦.............................................................. ١,٤,٤ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ٤٦.............................................................................. ١,٤,٥ﲤﺎﺭﻳﻦ ٤٧....................................................................................... ١,٥ﺍﻹﺩﺧﺎﻝ ٤٨..................................................................................... Input ١,٥,١ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ٥٠..............................................................................
١,٥,٢ﲤﺎﺭﻳﻦ ٥٠....................................................................................... ١,٦ﺍﳌﺆﺛﺮﺍﺕ ٥١................................................................................ Operators ١,٦,١ﺍﳌﺆﺛﺮﺍﺕ ﺍﳊﺴﺎﺑﻴﺔ ٥١........................................................ arthimetic operators ١,٦,١,١ﻣﺆﺛﺮ ﺍﻟﺰﻳﺎﺩﺓ ٥١...........................................................(++) increment ١,٦,١,٢ﻣﺆﺛﺮ ﺍﻟﻨﻘﺼﺎﻥ ٥٢..........................................................(--) decrement ١,٦,١,٣ﻣﺆﺛﺮ ﺑﺎﻗﻲ ﺍﻟﻘﺴﻤﺔ )٥٣.................................................................(% ١,٦,٢ﺍﳌﺆﺛﺮﺍﺕ ﺍﻟﻌﻼﻗﻴﺔ ٥٣.......................................................... relational operators ١,٦,٣ﺍﳌﺆﺛﺮﺍﺕ ﺍﳌﻨﻄﻘﻴﺔ ٥٤............................................................. logical operators ١,٦,٤ﻣﺆﺛﺮﺍﺕ ﺃﺧﺮﻯ ٥٥............................................................................... ١,٦,٥ﻣﺆﺛﺮﺍﺕ ﺧﺎﺻﺔ ﺑﺎﻟﺒﺘﺎﺕ )٥٧.............................................................. (bitwize ١,٦,٦ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ٥٩.............................................................................. ١,٦,٧ﲤﺎﺭﻳﻦ ٥٩....................................................................................... ١,٧ﺍﻟﻘﺮﺍﺭﺍﺕ ٦٠.......................................................................... if, else, else…if ١,٧,١ﺍﺳﺘﻌﻤﺎﻝ ٦٠................................................................................... if ١,٧,٢ﺍﺳﺘﻌﻤﺎﻝ ٦١................................................................................ else ١,٧,٣ﺍﺳﺘﻌﻤﺎﻝ ٦٢............................................................................. else…if ١,٧,٤ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ٦٣.............................................................................. ١,٧,٥ﲤﺎﺭﻳﻦ ٦٣....................................................................................... ١,٨ﻋﻨﺎﺻﺮ ﻟﻐﺔ ٦٤........................................................................................ C ١,٨,١ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ٦٤......................................................................... Comments ١,٨,٢ﺍﻟﻜﻠﻤﺎﺕ ﺍﶈﺠﻮﺯﺓ ٦٤.................................................................. Keywords ١,٨,٣ﺍﳌﻌﺮﻓﺎﺕ ٦٤.......................................................................... Identifiers ٦٥............................................................................. Trigraphs ١,٨,٣,١ ١,٨,٤ﺍﻟﺜﻮﺍﺑﺖ ٦٥........................................................................... Constants ١,٨,٤,١ﺍﻟﺜﻮﺍﺑﺖ ﺍﻟﻨﺼﻴﺔ ٦٦......................................................................... ١,٨,٤,٢ﺍﻟﺜﻮﺍﺑﺖ ﺍﻟﺮﻗﻤﻴﺔ ٦٧........................................................................ ١,٨,٥ﺍﻟﺮﻣﻮﺯ ٦٨............................................................................... Tokens ١,٨,٦ﺍﻟﺴﻼﺳﻞ ﺍﻟﻨﺼﻴﺔ ٦٨................................................................ String literals ١,٨,٧ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ٦٨.............................................................................. ١,٨,٨ﲤﺎﺭﻳﻦ ٦٨....................................................................................... ١,٩ﻣﻠﺨﺺ ﻟﻠﻔﺼﻞ ﺍﻷﻭﻝ ،ﻣﻊ ﺇﺿﺎﻓﺎﺕ ٦٩.................................................................. ١,٩,١ﺑﺮﺍﻣﺞ ﺗﺪﺭﻳﺒﻴﺔ ٦٩................................................................................ ١,٩,١,١ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ،ﻋﻤﺮ ﺍﳌﺴﺘﺨﺪﻡ ٦٩.......................................................... ١,٩,١,٢ﺍﻟﱪﻧﺎﻣﺞ ﺍﻟﺜﺎﱐ ،ﺁﻟﺔ ﺣﺎﺳﺒﺔ ﺑﺴﻴﻄﺔ ٧٠........................................................ ١,٩,١,٣ﺍﻟﱪﻧﺎﻣﺞ ﺍﻟﺜﺎﻟﺚ ،ﺍﺳﺘﺨﺮﺍﺝ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻄﻠﻘﺔ ٧١................................................. ١,٩,١,٤ﺍﻟﱪﻧﺎﻣﺞ ﺍﻟﺮﺍﺑﻊ ،ﺃﺧﺬ ﺍﻟﻌﺪﺩ ﺍﻟﻜﺒﲑ ٧٢........................................................
١,٩,٢ﺍﻟﺪﺍﻟﺘﲔ putcharﻭ ٧٢................................................................... getchar ١,٩,٣ﺍﻟﺪﺍﻟﺘﲔ putsﻭ ٧٣.......................................................................... gets ١,٩,٤ﺍﻟﺪﺍﻟﺘﲔ wprintfﻭ ٧٤..................................................................... wscanf ١,٩,٥ﺍﻟﺪﺍﻟﺘﲔ putchﻭ getchﻭ ﺍﻟﺪﺍﻟﺔ ٧٤........................................................ getche ١,٩,٦ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ٧٦..................................................................... wchar_t ١,٩,٧ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ mainﻭ ٧٦................................................................. wmain ١,٩,٨ﺭﻣﻮﺯ ﺍﻹﺧﺮﺍﺝ ﻭ ﺍﻹﺩﺧﺎﻝ ٧٨..................................................................... ١,٩,٩ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ٧٩.............................................................................. ١,٩,١٠ﲤﺎﺭﻳﻦ ٧٩...................................................................................... ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﱐ – ﺃﺳﺎﺳﻴﺎﺕ ﰲ ﻟﻐﺔ ........................................................................ (٢) C ٢,١ﺍﻟﻘﺮﺍﺭ ٨١...................................................................................... Switch ٢,١,١ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ٨٣......................................................................... case ٢,١,٢ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ٨٤........................................................................ break ٢,١,٢ﺍﻟﻜﻠﻤﺔ ﺍﻮﺯﺓ ٨٤......................................................................... default ٢,٨,٧ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ٨٤.............................................................................. ٢,٨,٨ﲤﺎﺭﻳﻦ ٨٥....................................................................................... ٢,٢ﺣﻠﻘﺎﺕ ﺍﻟﺘﻜﺮﺍﺭ ٨٦.................................................................... Repeated loop ٢,٢,١ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ٨٦......................................................................... while ٢,٢,٢ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ٨٨.................................................................... do…while ٢,٢,٣ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ٩٠........................................................................... for ٢,٢,٤ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ٩٢......................................................................... goto ٢,٢,٥ﺍﳌﻔﻬﻮﻡ ﺍﻟﻌﺎﻡ ﳊﻠﻘﺎﺕ ﺍﻟﺘﻜﺮﺍﺭ ٩٣................................................................... ٢,٢,٧ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ٩٧..................................................................... continue ٢,٢,٨ﺟﺪﻭﻝ ٩٨................................................................................ ASCII ٢,٢,٩ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ٩٨.............................................................................. ٢,٢,١٠ﲤﺎﺭﻳﻦ ٩٨...................................................................................... ٢,٣ﺍﳌﺼﻔﻮﻓﺎﺕ ١٠٠................................................................................ Arrays ٢,٣,١ﺃﺳﺎﺳﻴﺎﺕ ﰲ ﺍﳌﺼﻔﻮﻓﺎﺕ ١٠١..................................................................... ٢,٣,٢ﺍﳌﺼﻔﻮﻓﺎﺕ ﺍﻟﺜﻨﺎﺋﻴﺔ ﺍﻷﺑﻌﺎﺩ ١٠٢.................................................................... ٢,٣,٢ﺍﳌﺼﻔﻮﻓﺎﺕ ﺍﻟﺜﻼﺛﻴﺔ ﺍﻷﺑﻌﺎﺩ ١٠٤.................................................................... ٢,٣,٣ﻣﺼﻔﻮﻓﺔ ﺫﺍﺕ ﺣﺠﻢ ﻏﲑ ﻣﻌﺮﻭﻑ ١٠٥............................................................. ٢,٣,٤ﺍﻟﺴﻼﺳﻞ ﺍﳊﺮﻓﻴﺔ )ﺍﻟﻨﺼﻮﺹ( ١٠٦................................................................. ٢,٣,٤,١ﺍﻟﺪﺍﻟﺔ ١٠٩........................................................................... gets ٢,٣,٤,٢ﺍﻟﺪﺍﻟﺔ strcpyﻭ ﺍﻟﺪﺍﻟﺔ ١٠٩......................................................... strncpy ٢,٣,٤,٣ﺍﻟﺪﺍﻟﺔ strcatﻭ ﺍﻟﺪﺍﻟﺔ ١١٠.......................................................... strncat ٢,٣,٥ﻃﺮﻕ ﺃﺧﺮﻯ ﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﺼﻔﻮﻓﺎﺕ ١١١...........................................................
٢,٣,٦ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ١١٢............................................................................. ٢,٣,٧ﲤﺎﺭﻳﻦ ١١٣...................................................................................... ٢,٤ﺍﳌﺆﺷﺮﺍﺕ ١١٤............................................................................... Pointers ٢,٤,١ﻧﻮﻉ ﺍﳌﺆﺷﺮ ١١٤................................................................... Pointer Type ٢,٤,٢ﺍﺳﻢ ﺍﳌﺆﺷﺮ ١١٤................................................................... Pointer Name ٢,٤,٣ﺍﳌﺆﺷﺮﺍﺕ ﻭ ﺍﳌﺼﻔﻮﻓﺎﺕ ١١٦...................................................................... ٢,٤,٤ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟﻨﺼﻮﺹ ١١٧........................................................................ ٢,٤,٥ﺍﳌﺮﺟﻊ ١٢٠........................................................................... reference ٢,٤,٦ﻣﺆﺷﺮ ﻟـ ١٢٠............................................................................. void ٢,٤,٧ﻣﺆﺷﺮ ﳌﺼﻔﻮﻓﺔ ١٢١.............................................................................. ٢,٤,٨ﻣﺆﺷﺮ ﳌﺆﺷﺮ ١٢٢................................................................................ ٢,٤,٩ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ١٢٣............................................................................. ٢,٤,١٠ﲤﺎﺭﻳﻦ ١٢٣.................................................................................... ٢,٥ﺍﻟﺪﻭﺍﻝ ١٢٥................................................................................ Functions ٢,٥,١ﻧﻮﻉ ﺍﻟﺪﺍﻟﺔ ١٢٨................................................................... Function Type ٢,٥,٢ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ ١٣١.................................................................. Function Name ٢,٥,٣ﻭﺳﺎﺋﻂ ﺍﻟﺪﺍﻟﺔ ١٣١.......................................................... Function Parameters ٢,٥,٤ﺍﻷﻭﺍﻣﺮ ١٣١..................................................................................... ٢,٥,٥ﺍﳌﺨﺘﺼﺮﺍﺕ ١٣٢......................................................................... macros ٢,٥,٦ﺍﻟﻔﺮﻕ ﺑﲔ ﺍﻹﺟﺮﺍﺀ ﻭ ﺍﻟﺪﺍﻟﺔ ١٣٢................................................................... ٢,٥,٧ﺩﻭﺍﻝ ﳍﺎ ﻭﺳﺎﺋﻂ ﻣﻦ ﻧﻮﻉ ﺩﻭﺍﻝ ١٣٢............................................................... ٢,٥,٨ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ١٣٣............................................................................. ٢,٥,٩ﲤﺎﺭﻳﻦ ١٣٤...................................................................................... ٢,٦ﺍﳌﻠﻔﺎﺕ ﺍﻟﺮﺃﺳﻴﺔ ١٣٥...................................................................... Header files ٢,٦,١ﺍﺳﻢ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ١٣٦.......................................................................... ٢,٦,٢ﻣﱴ ﻧﺴﺘﻌﻤﻞ ﺍﳌﻠﻔﺎﺕ ﺍﻟﺮﺃﺳﻴﺔ ١٣٦................................................................. ٢,٦,٣ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ١٣٦............................................................................. ٢,٦,٤ﲤﺎﺭﻳﻦ ١٣٧...................................................................................... ٢,٧ﺍﻹﺩﺧﺎﻝ ﻭ ﺍﻹﺧﺮﺍﺝ ﰲ ﺍﳌﻠﻔﺎﺕ ١٣٨.......................................................... Files I/O ٢,٧,١ﺍﻹﺧﺮﺍﺝ ﰲ ﺍﳌﻠﻔﺎﺕ ١٣٨......................................................................... ٢,٧,١,١ﺍﻟﺪﺍﻟﺔ ١٤٠......................................................................... fopen ٢,٧,١,٢ﺍﻟﺪﺍﻟﺔ ١٤١......................................................................... fclose ٢,٧,١,٣ﺍﻟﺪﺍﻟﺔ ١٤١........................................................................... exit ٢,٧,٢ﺇﺿﺎﻓﺔ ﻧﺺ ﰲ ﺎﻳﺔ ﺍﳌﻠﻒ ١٤١.................................................................... ٢,٧,٣ﺍﻹﺩﺧﺎﻝ ﰲ ﺍﳌﻠﻔﺎﺕ ١٤٢......................................................................... ٢,٧,٤ﺍﻟﻨﻤﻂ w+ﻭ a+ﻭ ١٤٣....................................................................... r+
٢,٧,٤,١ﺍﻟﻨﻤﻂ ١٤٣........................................................................... w+ ٢,٧,٤,٢ﺍﻟﻨﻤﻂ ١٤٣........................................................................... a+ ٢,٧,٤,٣ﺍﻟﻨﻤﻂ ١٤٣............................................................................ r+ ٢,٧,٥ﺩﻭﺍﻝ ﺃﺧﺮﻯ ﺧﺎﺻﺔ ﺑﺎﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﻠﻔﺎﺕ ١٤٣....................................................... ٢,٧,٥,١ﺍﻟﺪﺍﻟﺔ fprintfﻭ ﺍﻟﺪﺍﻟﺔ ١٤٣.......................................................... fscanf ٢,٧,٥,٢ﺍﻟﺪﺍﻟﺔ fgetsﻭ ﺍﻟﺪﺍﻟﺔ ١٤٤............................................................. fputs ٢,٧,٥,٣ﺍﻟﺪﺍﻟﺔ fgetcﻭ ﺍﻟﺪﺍﻟﺔ ١٤٥............................................................ fputc ٢,٧,٦ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ١٤٦............................................................................. ٢,٧,٧ﲤﺎﺭﻳﻦ ١٤٦...................................................................................... ٢,٨ﺍﻟﺘﺮﺍﻛﻴﺐ ١٤٧............................................................................. structures ٢,٨,١ﺍﺳﻢ ﺍﻟﺒﻨﻴﺔ ١٤٧..................................................................... Struct Name ٢,٨,٢ﺍﻟﺒﻨﻴﺎﺕ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٥١...................................................... union ٢,٨,٣ﺍﳌﺼﻔﻮﻓﺎﺕ ﻭ ﺍﳌﺆﺷﺮﺍﺕ ﻋﻠﻰ ﺍﻟﺒﻨﻴﺎﺕ ١٥٣.......................................................... ٣,٨,٤ﺇﻋﻼﻥ ﺑﻨﻴﺔ ﺩﺍﺧﻞ ﺑﻨﻴﺔ ١٥٥........................................................................ ٢,٨,٥ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ١٥٥............................................................................. ٢,٨,٦ﲤﺎﺭﻳﻦ ١٥٦...................................................................................... ٢,٩ﻣﻠﺨﺺ ﻟﻠﻔﺼﻞ ﺍﻟﺜﺎﱐ ،ﻣﻌﺎ ﺇﺿﺎﻓﺎﺕ ١٥٧................................................................. ٢,٩,١ﻣﻌﲎ ﺩﺍﻟﺔ ﺎ ﻭﺳﻴﻂ ١٥٧.................................................................... void ٢,٩,٢ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٥٨....................................................................... static ٢,٩,٣ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٥٩.................................................................... typedef ٢,٩,٤ﺑﺮﺍﻣﺞ ﺗﺪﺭﻳﺒﻴﺔ ١٦١............................................................................... ٢,٩,٤,١ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ،ﺍﻟﻨﺴﺦ ١٦١................................................................ ٢,٩,٤,٢ﺗﺒﺎﺩﻝ ﻗﻴﻢ ﺑﲔ ﻭﺳﻴﻄﲔ ١٦٢................................................................ ٢,٩,٤,٣ﺍﻟﺘﻐﲑ ﰲ ﻗﻴﻢ ﺛﻮﺍﺑﺖ ١٦٣................................................................... ٢,٩,٤,٤ﻋﻜﺲ ﺳﻠﺴﻠﺔ ﻧﺼﻴﺔ ١٦٣.................................................................. ٢,٩,٤,٥ﺍﻟﺘﺤﻮﻳﻞ ﻣﻦ ﺍﻟﻨﻈﺎﻡ ﺍﻟﻌﺸﺮﻱ ﺇﱃ ﺍﻟﻨﻈﺎﻡ ﺍﻟﺜﻨﺎﺋﻲ ١٦٤........................................... ٢,٩,٤,٦ﺍﻟﺘﺤﻮﻳﻞ ﻣﻦ ﺍﳊﺮﻭﻑ ﺍﻟﺼﻐﲑﺓ ﺇﱃ ﺍﳊﺮﻭﻑ ﺍﻟﻜﺒﲑﺓ ١٦٤....................................... ٢,٩,٥ﺍﻟﺪﺍﻟﺔ wcscpyﻭ ﺍﻟﺪﺍﻟﺔ ١٦٥.............................................................. wcsncpy ٢,٩,٦ﺍﻟﺪﺍﻟﺔ wcscatﻭ ﺍﻟﺪﺍﻟﺔ ١٦٦.............................................................. wcsncat ٢,٩,٧ﺍﻟﺪﺍﻟﺔ getwcharﻭ ١٦٦................................................................ putwchar ٢,٩,٨ﺍﻟﺪﺍﻟﺔ _getwsﻭ ١٦٧..................................................................... _putws ٢,٩,٩ﺟﺪﻭﻝ ) ASCIIﺻﻮﺭﺓ( ١٦٧...................................................................... ٢,٩,١٠ﻣﻌﻠﻮﻣﺎﺕ ﺃﻛﺜﺮ ﺣﻮﻝ ﺍﳌﺘﻐﲑﺍﺕ ١٦٨.............................................................. ٢,٩,١٠,١ﺍﳌﺘﻐﲑﺍﺕ ﺍﶈﻠﻴﺔ ١٦٨..................................................................... ٢,٩,١٠,٢ﺍﳌﺘﻐﲑﺍﺕ ﺍﳋﺎﺭﺟﻴﺔ )ﺍﻟﻌﺎﻣﺔ( ١٦٩.......................................................... ٢,٩,١٠,٣ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٦٩............................................................. extern
٢,٩,١٠,٤ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٧٠............................................................... auto ٢,٩,١٠,٥ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٧١............................................................ register ٢,٩,١١ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٧١..................................................................... sizeof ٢,٩,١٢ﺍﺳﺘﺪﻋﺎﺀ ﺩﺍﻟﺔ ﻟﻨﻔﺴﻬﺎ ١٧٢....................................................................... ٢,٩,١٣ﺍﻟﺘﺤﻜﻢ ﰲ ﻃﺒﺎﻋﺔ ﺍﻟﻨﺘﺎﺋﺞ ١٧٣................................................................... ٢,٩,١٤ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ١٧٣........................................................................... ٢,٩,١٥ﲤﺎﺭﻳﻦ ١٧٣.................................................................................... ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﻟﺚ – ﺍﻟﺘﻘﺪﻡ ﰲ ﻟﻐﺔ .............................................................................. C ٣,١ﺍﳊﺴﺎﺏ ١٧٦........................................................................... Enumeration ٣,١,١ﺍﺳﻢ ﺍﳊﺴﺎﺏ ١٨٦........................................................... Enumeration Name ٣,١,٢ﺛﻮﺍﺑﺖ ﺍﳊﺴﺎﺏ ١٨٦............................................................................. ٣,١,٣ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ١٨٠............................................................................. ٣,١,٤ﲤﺎﺭﻳﻦ ١٨٠...................................................................................... ٣,٢ﻭﺳﺎﺋﻂ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ١٨٢.............................................. Command-line Arguments ٣,٢,١ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ١٨٢................................................................. ٣,٢,٢ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ١٨٣.................................................................. ٣,٢,٣ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ١٨٤............................................................................. ٣,٢,٤ﲤﺎﺭﻳﻦ ١٨٤...................................................................................... ٣,٣ﺍﻟﺘﻮﺟﻴﻬﺎﺕ )١٨٥........................................................... Directives(Preprocessor ٣,٣,١ﺍﻟﺘﻮﺟﻴﻪ ١٨٥.......................................................................... #include ٣,٣,٢ﺍﻟﺘﻮﺟﻴﻪ ١٨٥........................................................................... #define ٣,٣,٣ﺍﻟﺘﻮﺟﻴﻪ ١٨٦............................................................................. #undef ٣,٣,٤ﺍﻟﺘﻮﺟﻴﻬﺎﺕ #else ،#elif ،#ifﻭ ١٨٧..................................................... #endif ٣,٣,٥ﺍﻟﺘﻮﺟﻴﻪ #ifdefﻭ ﺍﻟﺘﻮﺟﻴﻪ ١٨٧............................................................ #ifndef ٣,٣,٦ﺍﻟﺘﻮﺟﻴﻪ ١٨٩.............................................................................. #line ٣,٣,٧ﺍﻟﺘﻮﺟﻴﻪ ١٨٩............................................................................. #error ٣,٣,٨ﺍﻟﺘﻮﺟﻴﻪ ١٩٠.......................................................................... #pragma ٣,٣,٩ﺍﻷﲰﺎﺀ ﺍﳌﻌﺮﻓﺔ ١٩٠............................................................ Predefined Names ٣,٣,١٠ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ١٩٠........................................................................... ٣,٣,١١ﲤﺎﺭﻳﻦ ١٩١.................................................................................... ٣,٤ﺩﻭﺍﻝ ﺫﺍﺕ ﻭﺳﺎﺋﻂ ﻏﲑ ﳏﺪﺩﺓ ١٩٢...................................................................... ٣,٤,١ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ١٩٤............................................................................. ٣,٤,٢ﲤﺎﺭﻳﻦ ١٩٤...................................................................................... ٣,٥ﺍﳌﻜﺘﺒﺔ ﺍﻟﻘﻴﺎﺳﻴﺔ ١٩٥................................................................ Standard Library ٣,٥,١ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ١٩٥...................................................................... assert.h ٣,٥,٢ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ١٩٥...................................................................... ctype.h
٣,٥,٢,١ﺍﻟﺪﺍﻟﺔ ١٩٥....................................................................... isalnum ٣,٥,٢,٢ﺍﻟﺪﺍﻟﺔ ١٩٦....................................................................... isalpha ٣,٥,٢,٣ﺍﻟﺪﺍﻟﺔ ١٩٦......................................................................... iscntrl ٣,٥,٢,٤ﺍﻟﺪﺍﻟﺔ ١٩٧........................................................................ isdigit ٣,٥,٢,٥ﺍﻟﺪﺍﻟﺔ ١٩٧....................................................................... isgraph ٣,٥,٢,٦ﺍﻟﺪﺍﻟﺔ ١٩٨....................................................................... islower ٣,٥,٢,٧ﺍﻟﺪﺍﻟﺔ ١٩٨........................................................................ isprint ٣,٥,٢,٨ﺍﻟﺪﺍﻟﺔ ١٩٩....................................................................... ispunct ٣,٥,٢,٩ﺍﻟﺪﺍﻟﺔ ١٩٩....................................................................... isspace ٣,٥,٢,١٠ﺍﻟﺪﺍﻟﺔ ٢٠٠..................................................................... isupper ٣,٥,٢,١١ﺍﻟﺪﺍﻟﺔ ٢٠٠..................................................................... isxdigit ٣,٥,٢,١٢ﺍﻟﺪﺍﻟﺘﲔ toupperﻭ ٢٠١......................................................... tolower ٣,٥,٣ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢٠١...................................................................... errno.h ٣,٥,٣,١ﺍﻟﺪﺍﻟﺔ ٢٠١........................................................................ perror ٣,٥,٤ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢٠٤....................................................................... float.h ٣,٥,٥ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢٠٤...................................................................... limits.h ٣,٥,٦ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢٠٥...................................................................... locale.h ٣,٥,٧ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢٠٥...................................................................... math.h ٣,٥,٧,١ﺍﻟﺪﺍﻟﺔ ٢٠٦........................................................................... sin ٣,٥,٧,٢ﺍﻟﺪﺍﻟﺔ ٢٠٦........................................................................... cos ٣,٥,٧,٣ﺍﻟﺪﺍﻟﺔ ٢٠٧........................................................................... tan ٣,٥,٧,٤ﺍﻟﺪﺍﻟﺔ ٢٠٧........................................................................... exp ٣,٥,٧,٥ﺍﻟﺪﺍﻟﺔ ٢٠٧........................................................................... log ٣,٥,٧,٥ﺍﻟﺪﺍﻟﺔ ٢٠٨.......................................................................... pow ٣,٥,٧,٦ﺍﻟﺪﺍﻟﺔ ٢٠٨.......................................................................... sqrt ٣,٥,٧,٧ﺍﻟﺪﺍﻟﺔ ٢٠٨........................................................................... ceil ٣,٥,٧,٨ﺍﻟﺪﺍﻟﺔ ٢٠٩.......................................................................... floor ٣,٥,٧,٩ﺍﻟﺪﺍﻟﺔ ٢٠٩.......................................................................... fabs ٣,٥,٧,١٠ﺍﻟﺪﺍﻟﺔ ٢٠٩....................................................................... ldexp ٣,٥,٧,١١ﺍﻟﺪﺍﻟﺔ ٢٠٩....................................................................... fmod ٣,٥,٨ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢١٠..................................................................... setjmp.h ٣,٥,٩ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢١١...................................................................... signal.h ٣,٥,٩,١ﺍﻟﺪﺍﻟﺔ ٢١١......................................................................... raise ٣,٥,١٠ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢١١.................................................................... stdarg.h ٣,٥,١١ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢١٢.................................................................... stddef.h ٣,٥,١٢ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢١٣..................................................................... stdio.h
٣,٥,١٢,١ﺍﻟﺪﺍﻟﺔ ٢١٣....................................................................... printf ٣,٥,١٢,٢ﺍﻟﺪﺍﻟﺔ ٢١٤...................................................................... sprintf ٣,٥,١٢,٣ﺍﻟﺪﺍﻟﺔ ٢١٤...................................................................... vprintf ٣,٥,١٢,٤ﺍﻟﺪﺍﻟﺔ ٢١٥..................................................................... vfprintf ٣,٥,١٢,٥ﺍﻟﺪﺍﻟﺔ ٢١٥..................................................................... vsprintf ٣,٥,١٢,٦ﺍﻟﺪﺍﻟﺔ ٢١٦....................................................................... scanf ٣,٥,١٢,٧ﺍﻟﺪﺍﻟﺔ ٢١٦...................................................................... fscanf ٣,٥,١٢,٨ﺍﻟﺪﺍﻟﺔ ٢١٦...................................................................... sscanf ٣,٥,١٢,٩ﺍﻟﺪﺍﻟﺔ ٢١٧....................................................................... fgetc ٣,٥,١٢,١٠ﺍﻟﺪﺍﻟﺔ ٢١٧....................................................................... fgets ٣,٥,١٢,١١ﺍﻟﺪﺍﻟﺔ ٢١٨...................................................................... fputc ٣,٥,١٢,١٢ﺍﻟﺪﺍﻟﺔ ٢١٨...................................................................... fputs ٣,٥,١٢,١٣ﺍﻟﺪﺍﻟﺔ ٢١٨....................................................................... getc ٣,٥,١٢,١٤ﺍﻟﺪﺍﻟﺔ ٢١٩................................................................... getchar ٣,٥,١٢,١٥ﺍﻟﺪﺍﻟﺔ ٢١٩...................................................................... gets ٣,٥,١٢,١٦ﺍﻟﺪﺍﻟﺔ ٢١٩...................................................................... putc ٣,٥,١٢,١٧ﺍﻟﺪﺍﻟﺔ ٢٢٠................................................................... putchar ٣,٥,١٢,١٨ﺍﻟﺪﺍﻟﺔ ٢٢٠...................................................................... puts ٣,٥,١٢,١٩ﺍﻟﺪﺍﻟﺔ ٢٢٠.................................................................... ungetc ٣,٥,١٢,٢٠ﺍﻟﺪﺍﻟﺔ ٢٢٠..................................................................... fopen ٣,٥,١٢,٢١ﺍﻟﺪﺍﻟﺔ ٢٢١................................................................... freopen ٣,٥,١٢,٢٢ﺍﻟﺪﺍﻟﺔ ٢٢٢..................................................................... fclose ٣,٥,١٢,٢٣ﺍﻟﺪﺍﻟﺔ ٢٢٢................................................................... remove ٣,٥,١٢,٢٤ﺍﻟﺪﺍﻟﺔ ٢٢٢................................................................... rename ٣,٥,١٢,٢٥ﺍﻟﺪﺍﻟﺔ ٢٢٣.................................................................... tmpfile ٣,٥,١٢,٢٦ﺍﻟﺪﺍﻟﺔ ٢٢٣...................................................................... fread ٣,٥,١٢,٢٧ﺍﻟﺪﺍﻟﺔ ٢٢٣..................................................................... fwrite ٣,٥,١٢,٢٨ﺍﻟﺪﺍﻟﺔ ٢٢٤...................................................................... fseek ٣,٥,١٢,٢٩ﺍﻟﺪﺍﻟﺔ ٢٢٥....................................................................... ftell ٣,٥,١٢,٣٠ﺍﻟﺪﺍﻟﺔ ٢٢٥.................................................................... rewind ٣,٥,١٢,٣١ﺍﻟﺪﺍﻟﺔ ٢٢٦....................................................................... feof ٣,٥,١٣ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢٢٦..................................................................... stdlib.h ٣,٥,١٣,١ﺍﻟﺪﺍﻟﺔ ٢٢٦......................................................................... atof ٣,٥,١٣,٢ﺍﻟﺪﺍﻟﺔ ٢٢٧......................................................................... atoi ٣,٥,١٣,٣ﺍﻟﺪﺍﻟﺔ ٢٢٧......................................................................... atol ٣,٥,١٣,٤ﺍﻟﺪﺍﻟﺔ ٢٢٧........................................................................ rand
٣,٥,١٣,٥ﺍﻟﺪﺍﻟﺔ ٢٢٨....................................................................... srand ٣,٥,١٣,٦ﺍﻟﺪﺍﻟﺔ ٢٢٨....................................................................... abort ٣,٥,١٣,٧ﺍﻟﺪﺍﻟﺔ ٢٢٩......................................................................... exit ٣,٥,١٣,٨ﺍﻟﺪﺍﻟﺔ ٢٢٩....................................................................... atexit ٣,٥,١٣,٩ﺍﻟﺪﺍﻟﺔ ٢٢٩..................................................................... system ٣,٥,١٣,١٠ﺍﻟﺪﺍﻟﺔ ٢٣٠....................................................................... abs ٣,٥,١٣,١١ﺍﻟﺪﺍﻟﺔ ٢٣٠....................................................................... labs ٣,٥,١٣,١٢ﺍﻟﺪﺍﻟﺔ ٢٣٠........................................................................ div ٣,٥,١٣,١٣ﺍﻟﺪﺍﻟﺔ ٢٣١....................................................................... ldiv ٣,٥,١٤ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢٣١.................................................................... string.h ٣,٥,١٤,١ﺍﻟﺪﺍﻟﺔ strcpyﻭ ﺍﻟﺪﺍﻟﺔ ٢٣١....................................................... strncpy ٣,٥,١٤,٢ﺍﻟﺪﺍﻟﺔ strcatﻭ ﺍﻟﺪﺍﻟﺔ ٢٣٢........................................................ strncat ٣,٥,١٤,٣ﺍﻟﺪﺍﻟﺔ strcmpﻭ ﺍﻟﺪﺍﻟﺔ ٢٣٣...................................................... strncmp ٣,٥,١٤,٤ﺍﻟﺪﺍﻟﺔ strchrﻭ ﺍﻟﺪﺍﻟﺔ ٢٣٣........................................................ strrchr ٣,٥,١٤,٥ﺍﻟﺪﺍﻟﺔ strspnﻭ ﺍﻟﺪﺍﻟﺔ ٢٣٤....................................................... strcspn ٣,٥,١٤,٦ﺍﻟﺪﺍﻟﺔ ٢٣٤..................................................................... strpbrk ٣,٥,١٤,٧ﺍﻟﺪﺍﻟﺔ ٢٣٥....................................................................... strstr ٣,٥,١٤,٨ﺍﻟﺪﺍﻟﺔ ٢٣٥....................................................................... strlen ٣,٥,١٤,٩ﺍﻟﺪﺍﻟﺔ ٢٣٥...................................................................... strerror ٣,٥,١٤,١٠ﺍﻟﺪﺍﻟﺔ ٢٣٦..................................................................... strtok ٣,٥,١٥ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢٣٦..................................................................... time.h ٣,٥,١٥,١ﺍﻟﺪﺍﻟﺔ ٢٣٧........................................................................ clock ٣,٥,١٥,٢ﺍﻟﺪﺍﻟﺔ ٢٣٨......................................................................... time ٣,٥,١٥,٣ﺍﻟﺪﺍﻟﺔ ٢٣٩...................................................................... difftime ٣,٥,١٥,٤ﺍﻟﺪﺍﻟﺔ ٢٣٩.................................................................... localtime ٣,٥,١٥,٥ﺍﻟﺪﺍﻟﺔ ٢٤٠..................................................................... asctime ٣,٥,١٥,٦ﺍﻟﺪﺍﻟﺔ ٢٤٠........................................................................ ctime ﺍﳋﺎﲤﺔ ٢٤١.................................................................................................. ﺟﺪﻭﻝ ﺍﻷﺷﻜﺎﻝ )ﺍﻟﺼﻮﺭ( ..................................................................................... ﺟﺪﻭﻝ ﺍﳉﺪﺍﻭﻝ .............................................................................................. ﺟﺪﻭﻝ ﺍﻟﱪﺍﻣﺞ ............................................................................................... ﺃﻫﻢ ﺍﳌﺮﺍﺟﻊ ..................................................................................................
18
ﺍﳊﻤﺪ ﺍﷲ ﺭﺏ ﺍﻟﻌﺎﳌﲔ ﻭ ﺍﻟﺼﻼﺓ ﻭ ﺍﻟﺴﻼﻡ ﻋﻠﻰ ﺳﻴﺪ ﺍﳌﺮﺳﻠﲔ ﻧﺒﻴﻨﺎ ﳏﻤﺪ ﺻﻠﻰ ﺍﷲ ﻋﻠﻴﻪ ﻭ ﻋﻠـﻰ ﺁﻟـﻪ ﻭ ﺻـﺤﺒﻪ ﺃﲨﻌﲔ...ﺃﻣﺎ ﺑﻌﺪ ،ﺇﻗﺘﺮﺑﺖ ﺍﳌﺪﺓ ﻋﺎﻡ ﻣﻦ ﺇﻧﺸﺎﺀ ﺍﻟﻨﺴﺨﺔ ﺍﻷﻭﱃ ﻣﻦ ﻛﺘﺎﺏ ﻟﻐﺔ Cﺍﻟﺸﺎﻣﻞ ،ﻭ ﺍﻟﻴﻮﻡ ﻗﻤﺖ ﺑﺈﻧﺸﺎﺀ ﺍﻟﻠﻨـﺴﺨﺔ ﺍﻟﺜﺎﻧﻴﺔ ﻣﻨﻪ ،ﻭ ﻟﻜﻦ ﻫﺬﻩ ﺍﻟﻨﺴﺨﺔ ﱂ ﺃﺭﻛﺰ ﻋﻠﻰ ﺍﻟﺘﻮﺳﻴﻊ ﻓﻴﻬﺎ ﻋﻠﻰ ﺍﺳﺎﺑﻘﺔ ،ﺇﳕﺎ ﺭﻛﺰﺕ ﻋﻠﻰ ﺗﺼﺤﻴﺢ ﺃﺧﻄﺎﺀﻫﺎ ،ﺻـﺤﺤﺖ ﺍﻟﺬﻱ ﺍﺳﺘﻄﻌﺖ ﻣﻼﺣﻈﺘﻪ ،ﻭ ﻻﹶﺯِﻟﹾﺖ ﺃﻧﺘﻈﺮ ﻣﻼﺣﻈﺔ ﺃﺧﻄﺎﺀ ﺃﺧﺮﻯ ﻣﻦ ﻗﹸﺮﺍﺀ ﻫﺬﻩ ﺍﻟﻜﺘﺎﺏ ،ﻟﺬﺍ ﺃﺭﺟﻮ ﻟﻜﻞ ﻣﻦ ﻗﺮﺃ ﺍﻟﻜﺘﺎﺏ ﻭ ﻭﺟﺪ ﺑﻪ ﺃﺧﻄﺎﺀ ﺳﻮﺍﺀ ﻛﺎﻧﺖ ﺃﺧﻄﺎﺀ ﺇﻣﻼﺋﻴﺔ ﺃﻭ ﻣﻌﻨﻮﻳﺔ )ﻭ ﺧﺎﺻﺔ ﺍﳌﻌﻨﻮﻳﺔ( ﺃﻥ ﻳﻘﻮﻡ ﺑﺘﻨﺒﻴﻬﻲ ﻋﻠـﻰ ﺑﺮﻳـﺪﻱ ﺍﻹﻟﻴﻜﺘـﺮﻭﱐ ،
[email protected]ﺃﻭ ﳝﻜﻦ ﺃﻥ ﻳﻮﺿﻊ ﺍﳋﻄﺄ ﰲ ﻣﻮﺿﻮﻉ ﻫﺬﺍ ﺍﻟﻜﺘﺎﺏ .ﺣﻴﺚ ﺳﻴﺘﻢ ﺇﻧﺸﺎﺀ ﻗﺎﺋﻤﺔ ﻷﲰﺎﺀ ﻣﻼﺣﻈﻲ ﺃﺧﻄﺎﺀ ﻫﺬﺍ ﺍﻟﻜﺘﺎﺏ ﻭ ﻭﺿﻌﻬﺎ ﰲ ﺍﻟﺼﻔﺤﺎﺕ ﺍﻷﻭﱃ ﻣﻦ ﺍﻟﻜﺘﺎﺏ )ﻳﻌﲏ ﻋﻤﻞ ﲨﺎﻋﻲ(. ﻭ ﻣﻦ ﺃﺧﻄﺎﺀ ﺍﻟﻨﺴﺨﺔ ﺍﻷﻭﱃ)ﻫﺬﺍ ﻟﻜﻲ ﺃﺑﲔ ﻟﻘﺮﺍﺀ ﺍﻟﻨﺴﺨﺔ ﺍﻷﻭﱃ ﻣﻦ ﻫﺬﺍ ﺍﻟﻜﺘﺎﺏ ﺃﻱ ﳝﻜﻨﻬﻢ ﺇﻋﺎﺩﺓ ﺍﻟﻘﺮﺍﺀﺓ( ﻣـﻦ ﻫـﺬﺍ ﺍﻟﻜﺘﺎﺏ ﻛﺎﻧﺖ ﰲ ﻛﻞ ﻣﻦ :ﺍﻟﻔﺼﻞ ﺍﻷﻭﻝ ،ﺑﻌﺾ ﺍﻷﺧﻄﺎﺀ ﰲ ﺍﳉﺰﺀ "ﺍﻟﺒﺪﺀ ﻣﻊ ﻟﻐﺔ ،"Cﻭ ﺑﻌﺾ ﺍﻷﻣﺎﻛﻦ ﺍﻟﱵ ﲡﺎﻫﻠﺘـﻬﺎ ﰲ ﻗﺴﻢ "ﺍﳌﺆﺛﺮﺍﺕ "Operatorsﻭ ﻗﺴﻢ "ﺍﳌﺘﻐﲑﺍﺕ ﻭ ﺍﻟﺜﻮﺍﺑﺖ" ،ﺃﻣﺎ ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﱐ ﻓﺘﻮﺟﺪ ﺃﺧﻄﺎﺀ ﰲ ﺟﺰﺀ "ﺍﳌﺆﺷﺮﺍﺕ" ،ﻭ ﺃﺧﲑﺍ ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﻟﺚ ﰲ ﻛﻞ ﻣﻦ " "Command-line Argumentsﻭ "ﺍﳌﻜﺘﺒﺔ ﺍﻟﻘﻴﺎﺳﻴﺔ" .ﻭ ﻃﺒﻌﺎ ﺗﻮﺟﺪ ﺃﺧﻄﺎﺀ ﺃﺧﺮﻯ ﻣﺘﻔﺮﻗـﺔ ﰲ ﺍﻟﻜﺘﺎﺏ ﱂ ﺃﺫﻛﺮﻫﺎ .ﻭ ﺃﻛﻴﺪ ﻫﻨﺎﻙ ﺇﺿﺎﻓﺎﺕ ﰲ ﺍﻟﻜﺘﺎﺏ)ﻻﻛﻦ ﻻ ﺗﺘﻮﻗﻊ ﺍﻟﻜﺜﲑ(. ﻓﺼﻮﻝ ﻫﺬﻩ ﺍﻟﻨﺴﺨﺔ ﻣﺜﻞ ﺍﻟﻨﺴﺨﺔ ﺍﻟﺴﺎﺑﻘﺔ: § ﰲ ﺍﻟﻔﺼﻞ ﺍﻷﻭﻝ ﻣﻔﺎﻫﻴﻢ ﻭ ﻣﺒﺎﺩﺉ ﺃﺳﺎﺳﻴﺔ ﰲ ﻟﻐﺔ :Cﺍﻹﺩﺧﺎﻝ ﻭ ﺍﻹﺧﺮﺍﺝ ،ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﻭ ﺍﳌﺆﺛﺮﺍﺕ ،ﺍﻟﻘـﺮﺍﺭﺍﺕ ﻭ ﻋﻨﺎﺻﺮ ﻟﻐﺔ ،Cﻣﻊ ﻣﻠﺨﺺ ﻟﻠﻔﺼﻞ ﺍﻷﻭﻝ. § ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﱐ ﻣﻜﻤﻞ ﻟﻠﻔﺼﻞ ﺍﻷﻭﻝ ﰲ ﻛﻞ ﻣﻦ ﺍﻟﻘﺮﺍﺭ ،Switchﺣﻠﻘﺎﺕ ﺍﻟﺘﻜـﺮﺍﺭ ،ﺍﳌـﺼﻔﻮﻓﺎﺕ ﻭ ﺍﳌﺆﺷـﺮﺍﺕ، ﺍﻟﺪﻭﺍﻝ ،ﺍﳌﻠﻔﺎﺕ ﺍﻟﺮﺃﺳﻴﺔ ،ﺍﻹﺩﺧﺎﻝ ﻭ ﺍﻹﺧﺮﺍﺝ ﰲ ﺍﳌﻠﻔﺎﺕ ﻭ ﺍﻟﺘﺮﺍﻛﻴﺐ ،ﻭ ﺃﺧﲑﺍ ﻣﻠﺨﺺ ﻟﻠﻔﺼﻞ ﺍﻟﺜﺎﱐ. § ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﻟﺚ ﻣﻜﻤﻞ ﻟﻠﻜﺘﺎﺏ ،ﻣﻊ ﺇﺿﺎﻓﺔ ﺃﻫﻢ ﺛﻮﺍﺑﺖ ،ﳐﺘﺼﺮﺍﺕ ﻭ ﺩﻭﺍﻝ ﺍﳌﻜﺘﺒﺔ ﺍﻟﻘﻴﺎﺳﻴﺔ ﻟﻠﻐﺔ .C ﻭ ﺍﻟﻜﺘﺎﺏ ﻣﻔﺘﻮﺡ ﻟﻜﻞ ﻣﻦ ﻳﺮﻳﺪ ﺇﺿﺎﻓﺔ ﺣﺮﻑ ،ﻛﻠﻤﺔ ،ﲨﻠﺔ ﺃﻭ ﺟﻤﻞ ،ﺃﺟﺰﺍﺀ ﺃﻭ ﺃﻱ ﺷﻲﺀ ﻣﻔﻴـﺪ)ﺷـﺎﺭﻛﻨﺎ ﺍﳋـﲑ( .ﺃﻱ ﺗﻌﻠﻴﻘﺎﺕ ﺃﻭ ﻣﻼﺣﻈﺎﺕ ﺃﻫﻼ ﻭ ﺳﻬﻼ. ﺧﻠﻴﻞ ﺃﻭﻧﻴﺲ ،ﺍﳉﺰﺍﺋﺮ
) ٠٦٤٥٧٦٦١٨ﻣﻦ ﺍﻟﺪﺍﺧﻞ(+٢١٣٦٤٥٧٦٦١٨ ، ﺗﺎﺭﻳﺦ ﺍﻹﻧﺘﻬﺎﺀ ﻣﻦ ﺍﻟﻨﺴﺨﺔ٢٠٠٦-٠٨-١٩ :
19
ﰲ ﺃﻳﺎﻡ ﺑﺪﺍﻳﺔ ﺍﳊﺎﺳﻮﺏ ﻛﺎﻧﺖ ﺍﻟﱪﳎﺔ ﺗﺘﻢ ﻋﻠﻰ ﻟﻐﺔ ﺑﺪﺍﺋﻴﺔ ﻣﻨﺨﻔﻀﺔ ﺍﳌﺴﺘﻮﻯ low-level languageﺗﺪﻋﻰ ﺑﻠﻐﺔ ﺍﻵﻟﺔ ،Machine languageﺣﻴﺚ ﻛﺎﻧﺖ ﺗﻔﻬﻤﻬﺎ ﺍﻵﻟﺔ ﻣﺒﺎﺷﺮﺓ ،ﻭ ﻳﺘﻢ ﺍﻟﱪﳎﺔ ﻋﻠﻴﻬﺎ ﺑﺄﻭﺍﻣﺮ ﺗﻤﺜﻞ ﲞﻴﻮﻁ ﻃﻮﻳﻠﺔ ﻣﻜﻮﻧﺔ ﻣﻦ ﺍﻟﻮﺍﺣﺪ ﻭ ﺍﻟﺼﻔﺮ )ﺍﻟﺼﻔﺮ ﺗﻌﲏ lowﻭ ﻫﻲ ﳏﺼﻮﺭﺓ ﺑﲔ -٠,٥ﻭ +٠,٥ﻓﻮﻟﺖ ،ﻭ ﺍﻟﻮﺍﺣﺪ ﻳﻌﲏ highﻭ ﻫﻮ ﳏﺼﻮﺭ ﺑـﲔ +٤,٥ﻭ +٥,٥ﻓﻮﻟﺖ( ﺃﻱ ﲟﺎ ﻳﺴﻤﻰ ﺑﺎﻟﻨﻈﺎﻡ ﺍﻟﺜﻨﺎﺋﻲ ،ﻭ ﻛﺎﻧﺖ ﺍﻟﱪﳎﺔ ﻋﻠﻴﻬﺎ ﺻﻌﺒﺔ ﻭ ﻣﻌﻘﺪﺓ ﺣﱴ ﰎ ﺗﻄﻮﻳﺮ ﻟﻐﺔ ﺍﻟﺘﺠﻤﻴﻊ assembly ،languageﻭ ﻫﻲ ﻣﻦ ﺍﻟﻠﻐﺎﺕ ﺍﳌﻨﺨﻔﻀﺔ ﺍﳌﺴﺘﻮﻯ low-level languagesﺃﻳﻀﺎ ،ﺣﻴﺚ ﻛﺎﻧﺖ ﺳﻬﻠﺔ ﺑﺎﻟﻨﺴﺒﺔ ﻟـﻠﻐﺔ ﺍﻵﻟـﺔ، ﻓﺒﺪﻝ ﺍﺳﺘﻌﻤﺎﻝ ﺳﻼﺳﻞ ﻣﻦ ﺍﻟﺼﻔﺮ ﻭ ﺍﻟﻮﺍﺣﺪ ﻧﺴﺘﻌﻤﻞ ﺃﻭﺍﻣﺮ ﺫﺍﺕ ﻛﻠﻤﺎﺕ ﻣﻔﻬﻮﻣﺔ ﻣﺜﻞ ADDﻭ .MOV ﻣﻊ ﻣﺮﻭﺭ ﺍﻟﻮﻗﺖ ﰎ ﺗﻄﻮﻳﺮ ﻟﻐﺎﺕ ﺑﺮﳎﺔ ﺃﺧﺮﻯ ﻣﺜﻞ BASIC ،COBOLﻭ ،Cﻭ ﻛﺎﻥ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻌﻬﺎ ﺑﺎﻟﻜﻠﻤﺎﺕ ﻭ ﺍﻟﻨﺼﻮﺹ ﳑﺎ ﺟﻌﻞ ﻫﺬﻩ ﺍﻟﻠﻐﺎﺕ ﻣﻘﺮﻭﺋﺔ .ﻭ ﻫﺬﻩ ﻣﻌﻠﻮﻣﺎﺕ ﳐﺘﺼﺮﺓ ﻋﻦ ﺑﻌﺾ ﺍﻟﻠﻐﺎﺕ: ﻟﻐﺔ ﺍﳉﻤﻴﻊ ،Assembly Languageﰎ ﺗﻄﻮﻳﺮﻫﺎ ﰲ ﻋﺎﻡ ١٩٥٦ﻣﻦ ﻗﺒﻞ ﺷﺮﻛﺔ .IBMﻟﻐﺔ ﻓﻮﺭﺗﺮﺍﻥ ،Fortran Language ﻭ ﻛﻠﻤﺔ Fortranﳐﺘﺼﺮﺓ ﻣﻦ Formula Translationﺃﻱ ﺻﻴﻐﺔ ﺍﻟﺘﺮﲨﺔ ،ﰎ ﺗﻄﻮﻳﺮﻫﺎ ﰲ ﻋﺎﻡ ١٩٥٤ﻣﻦ ﻗﺒﻞ ﻓﺮﻳﻖ ﻳﺘﺮﺃﺳـﻪ ﺟﻮﻥ ﺑﺎﻛﻮﺱ ،John Backusﺣﻴﺚ ﻛﺎﻧﺖ ﺗﺴﺘﺨﺪﻡ ﺑﻜﺜﺮﺓ ﰲ ﺍﻟﺘﻄﺒﻴﻘﺎﺕ ﺍﻟﺮﻳﺎﺿﻴﺔ .ﻟﻐـﺔ ﻛﻮﺑـﻮﻝ ،COBOL Language ﺇﺧﺘﺼﺎﺭ ﻟـ ،Common Business Oriented Languageﺃﻱ ﻟﻐﺔ ﻣﻮﺟﻬﺔ ﻟﻸﻋﻤﺎﻝ ﺍﻟﺘﺠﺎﺭﻳﺔ ،ﰎ ﺗﻄﻮﻳﺮﻫﺎ ﰲ ﻋـﺎﻡ ١٩٥٩ ﻣﻦ ﻗﺒﻞ ﳉﻨﺔ ﻗﺼﲑﺓ ﻣﻜﻮﻧﺔ ﻣﻦ ﺛﻼﺛﺔ ﺷﺮﻛﺎﺕ ﻣﻨﻬﺎ .IBMﻟﻐﺔ ﺍﻟﺒﺎﺯﻳﻚ ،Basic Languageﺇﺧﺘﺼﺎﺭ ﻟــ Beginner's All- ،Purpose Symbolic Instruction Codeﺃﻱ ﺷﻔﺮﺓ ﺭﻣﻮﺯ ﻟﺘﻌﻠﻴﻤﺎﺕ ﲨﻴﻊ ﺍﻷﻏﺮﺍﺽ ﻟﻠﻤﺒﺘـﺪﺃﻳﻦ ،ﻭ ﰎ ﺗﻄﻮﻳﺮﻫـﺎ ﰲ ﻋـﺎﻡ ١٩٦٣ﻣﻦ ﻗﺒﻞ ﺍﻷﺳﺘﺎﺫ ﺟﻮﻥ ﻛﻴﻤﲏ John Kemenyﻭ ﺍﻷﺳﺘﺎﺫ ﺗﻮﻣﺎﺱ ﻛﻮﺭﺯ ،Thomas Kurtzﻭ ﺃﺧﺬﺕ ﺷﻬﺮﺓ ﻛـﺒﲑﺓ )ﺇﱃ ﺣﺪ ﺍﻵﻥ( .ﻟﻐﺔ ﺁﻟﭭﻮﻝ ،Algol Languageﺇﺧﺘﺼﺎﺭ ﻟـ ،Algorithmic Languageﰎ ﺗﻄﻮﻳﺮﻫﺎ ﰲ ﻋﺎﻡ ١٩٥٨ﻣﻦ ﻗﺒﻞ ﳎﻤﻮﻋﺔ ﻣﻦ ﻋﻠﻤﺎﺀ ﺣﻮﺍﺳﻴﺐ ﺃﻭﺭﻭﺑﻴﲔ ﻭ ﺃﻣﺮﻳﻜﻴﲔ .ﻟﻐﺔ ﺑﺎﺳﻜﺎﻝ ،Pascal Languageﻭ ﺍﺳﻢ ﻫﺬﻩ ﺍﻟﻠﻐﺔ ﻣﺄﺧﻮﺫ ﻣﻦ ﺍﺳـﻢ ﺍﻟﻌﺎﱂ ﺍﻟﻔﺮﻧﺴﻲ ،Blaise Pascalﻭ ﰎ ﺗﻄﻮﻳﺮﻫﺎ ﻋﺎﻡ ١٩٧٠ﻣﻦ ﻗﺒﻞ ﻧﻴﻜﻠﻮﺱ ﻭﻳﺮﺙ .Niklaus Wirthﻭ ﺗﺬﻛﺮ ﺃﻧﺎ ﻛﻞ ﻣـﻦ ﺍﻟﻠﻐﺎﺕ ﺍﻟﺴﺎﺑﻘﺔ ﻫﻲ ﺃﻗﺪﻡ ﻟﻐﺎﺕ ﺑﺮﳎﺔ. ﻟﻐﺔ Cﻣﻦ ﻟﻐﺎﺕ ﺍﻷﻏﺮﺍﺽ ﺍﻟﻌﺎﻣﺔ ،ﻭ ﺗﺴﺘﻌﻤﻞ ﺑﻜﺜﺮﺓ ﰲ ﺑﺮﳎﺔ ﺍﻟﻨﻈﻢ Systems Programmingﻭ ﺃﻧﻈﻤﺔ ﺍﻟﺘﺸﻐﻴﻞ ،Systemsﰎ ﺗﻄﻮﻳﺮﻫﺎ ﰲ ﺍﻟﺴﺒﻌﻴﻨﺎﺕ ﻣﻦ ﻃﺮﻑ ﻛﲔ ﺗﻮﻣـﺴﻦ Ken Thompsonﻭ ﺩﻧـﻴﺲ ﺭﻳﺘـﺸﻲ Dennis Ritchieﰲ ﳐﺘﱪﺍﺕ .Bellﻟﻐﺔ Cﻣﻦ ﺍﻟﻠﻐﺎﺕ ﺍﳌﻨﺨﻔﻀﺔ ﺍﳌﺴﺘﻮﻯ low-level languagesﺣﻴﺚ ﺃﺎ ﻗﺮﻳﺒﺔ ﻣﻦ ﺍﻷﺟﻬﺰﺓ ﻭ ﺷـﺒﻴﻬﺎ ﺑﻠﻐـﺔ ﺍﻟﺘﺠﻤﻴﻊ assembly languageﰲ ﻋﻤﻠﻬﺎ ،ﻭ ﻟﻜﻦ ﺍﻟﺒﻌﺾ ﻳﻌﺘﱪﻫﺎ ﻟﻐﺔ ﻣﺘﻮﺳﻄﺔ ﺍﳌﺴﺘﻮﻯ mid-level languageﻷـﺎ ﻟﻐـﺔ ﲢﺎﻛﻲ ﻟﻐﺔ ﺍﻹﻧﺴﺎﻥ ﺑﻌﺾ ﺍﻟﺸﻲﺀ ،ﻭ ﻫﻲ ﻟﻐﺔ ﻣﺴﺘﻘﻠﺔ ﻋﻦ ﺍﻟﺒﻨﻴﺔ ﺍﻟﺼﻠﺒﺔ ﻟﻠﺤﺎﺳﻮﺏ. Operating
20
ﻗﺎﻡ ﻛﲔ ﺗﻮﻣﺴﻦ ﻭ ﺩﻧﻴﺲ ﺭﻳﺘﺸﻲ ﺑﺘﻄﻮﻳﺮ ﻟﻐﺔ Cﻟﱪﳎﺔ ﻧﻈﺎﻡ ﻳﻮﻧﻴﻜﺲ ،Unixﺣﻴﺚ ﺭﻛﺰﺍ ﻣﻄﻮﺭﻱ ﻫﺬﻩ ﺍﻟﻠﻐـﺔ ﻋﻠـﻰ ﺃﻥ ﺗﻜﻮﻥ ﻟﻐﺘﻬﻢ ﺳﻬﻠﺔ ﺍﻻﺳﺘﻌﻤﺎﻝ ﺣﻴﺚ ﳝﻜﻦ ﻛﺘﺎﺑﺔ ﺑﺮﺍﻣﺞ ﻛﺒﲑﺓ ﻣﻊ ﻗﻠﺔ ﺍﻷﺧﻄﺎﺀ ﻭ ﰲ ﻭﻗﺖ ﺃﻗـﺼﺮ .ﰲ ﻋـﺎﻡ ١٩٧٣ﰎ ﺇﻃﻼﻕ ﻟﻐﺔ Cﺑﺸﻜﻞ ﺭﲰﻲ ،ﻭ ﲰﻴﺖ ﺑﻠﻐﺔ Cﻷﺎ ﻛﺎﻧﺖ ﻣﺸﺘﻘﺔ ﻣﻦ ﻟﻐﺔ ﺍﻟـ ) Bﻭ ﻛﺎﻧﺖ ﻟﻐﺔ ﺍﻟـ Bﻧﻔﺴﻬﺎ ﻣﺸﺘﻘﺔ ﻣﻦ ﻟﻐﺔ BCPLﺍﻟﱵ ﻗﺎﻡ ﺑﺘﻄﻮﻳﺮﻫﺎ ﻣﺎﺭﺗﻦ ﺭﻳﺘﺸﺎﺭﺩﺯ Martin Richardsﰲ ﻋﺎﻡ ،١٩٦٧ﻭ ﻫـﻲ ﳐﺘـﺼﺮﺓ ﻣـﻦ Basic Combined ،Programming Languageﺣﻴﺚ ﻛﺎﻥ ﺍﻟﻔﺮﻕ ﺑﲔ ﺍﻟﻠﻐﺘﲔ ﻫﻮ ﻧﻮﻉ ﺍﻟﺒﻴﺎﻧﺎﺕ( ﺍﻟﱵ ﻗﺎﻡ ﺑﺘﻄﻮﻳﺮﻫﺎ ﻛﲔ ﺗﻮﻣـﺴﻦ ﰲ ﻋـﺎﻡ ١٩٦٩ﺣﻴﺚ ﺃﺧﺬ ﺍﳊﺮﻑ Bﻣﻦ ﺍﺳﻢ ﺍﳌﺨﺘﱪ Bellﺍﻟﺬﻱ ﻳﻌﻤﻞ ﺑﻪ ،ﻭ ﺍﻟﺬﻱ ﻳﻠﻲ ﺍﳊﺮﻑ Bﰲ ﺍﻷﲜﺪﻳﺔ ﻫﻮ ،Cﻭ ﺫﻟﻚ ﻫﻮ ﺳﺒﺐ ﺗﺴﻤﻴﺘﻬﺎ ﺑﻠﻐﺔ .Cﰲ ﻋﺎﻡ ١٩٧٨ﻗﺎﻡ ﺩﻧﻴﺲ ﺭﻳﺘﺸﻲ ﻭ ﺑﺮﺍﻳﻦ ﻛﺎﺭﻧﻴﻐﺎﻥ Brian Kernighanﺑـﺘﺄﻟﻴﻒ ﺃﻭﻝ ﻛﺘﺎﺏ ﳍﺬﻩ ﺍﻟﻠﻐﺔ ﻭ ﲰﻲ ﺑـ The C Programming Languageﻭ ﺍﻟﺬﻱ ﻳﻌﺘﱪ ﺍﳌﺮﺟﻊ ﺍﻷﺳﺎﺳﻲ ﳍﺬﻩ ﺍﻟﻠﻐﺔ ،ﻭ ﻛﺎﻥ ﺍﻟﻜﺘﺎﺏ ﻣﻌـﺮﻭﻑ ﺑﻨﺴﺨﺔ (Kernighan & Ritchie C) K&R Cﻭ ﺍﻟﺴﺒﺐ ﰲ ﺗﺴﻤﻴﺘﻪ ﺑـ K&R Cﻫﻮ ﻛﺜﺮﺓ ﺍﺳﺘﻌﻤﺎﻝ ﻟﻐﺔ Cﺑﺸﻜﻞ ﻛﺒﲑ ﻭ ﺍﻟﺬﻱ ﺃﺩﻯ ﺇﱃ ﺗﻄﻮﻳﺮ ﻣﻜﺘﺒﺎﺕ ﻭ ﺩﻭﺍﻝ ﰲ ﻧﺴﺦ ﳐﺘﻠﻔﺔ ﻣﻦ ﻟﻐﺔ Cﺣﱴ ﺃﺻﺒﺢ ﻛﻞ ﻣﻦ ﺗﻠﻚ ﺍﻟﻨﺴﺦ ﻏﲑ ﻣﺘﻮﺍﻓﻘﺔ ﻣـﻊ ﺑﻌـﻀﻬﺎ ﻭ ﻛﺎﺩﺕ ﺃﻥ ﺗﻜﻮﻥ ﻏﲑ ﻣﺘﺸﺎﺎ ،ﻭ ﻫﺬﺍ ﻣﺎ ﺃﺩﻯ ﺇﱃ ﺗﻌﺮﻳﻒ ﻧﺴﺨﺔ ﻗﻴﺎﺳﻴﺔ ﻟﻠﻐﺔ .Cﰲ ﻋﺎﻡ ١٩٨٩ﰎ ﺇﻃﻼﻕ ﺍﻟﻨﺴﺨﺔ ﺍﻟﻘﻴﺎﺳﻴﺔ ﻟﻠﻐﺔ Cﻭ ﲰﻴﺖ ﺑـ ANSI Cﻭ ﻫﻲ ﳐﺘﺼﺮﺓ ﻣﻦ American National Standards Institute Cﺃﻱ ﺍﻟﻠﺠﻨﺔ ﺍﻟﻮﻃﻨﻴﺔ ﺍﻷﻣﲑﻛﻴﺔ ﻟﻠﻤﻌﺎﻳﺮ ،ﻭ ﺑﺘﻌﺎﻭﻥ ﺑﲔ ﺍﻟﻠﺠﻨﺔ ﺍﻟﻮﻃﻨﻴﺔ ﺍﻷﻣﲑﻛﻴﺔ ﻟﻠﻤﻌﺎﻳﺮ ﻭ ﺍﳌﻨﻈﻤﺔ ﺍﻟﻌﺎﳌﻴﺔ ﻟﻠﻤﻌﺎﻳﺮ ﰎ ﺇﻃﻼﻕ ﻟﻐﺔ Cﺍﻟﻘﻴﺎﺳﻴﺔ ﰲ ﳐﺘﻠﻒ ﺃﳓﺎﺀ ﺍﻟﻌﺎﱂ ﻭ ﲰﻴﺖ ﺑـ ISO Cﻭ ﻫﻲ ﺇﺧﺘﺼﺎﺭ ﻟــ .International Organization for Standardizationﻭ ﻛﺎﻧـﺖ ﺍﻟﻨـﺴﺨﺔ ﺍﻟﻘﻴﺎﺳﻴﺔ ﻟﻠﻐﺔ Cﳐﺘﻠﻔﺔ ﺑﻌﺾ ﺍﻟﺸﻲﺀ ﻋﻦ ﻧﺴﺨﺔ ) K&R Cﰲ ﻋﺎﻡ ١٩٨٨ﻗﺎﻡ ﺩﻧﻴﺲ ﺭﻳﺘﺸﻲ ﻭ ﺑـﺮﺍﻳﻦ ﻛﺎﺭﻧﻴﻐـﺎﻥ ﺑﻜﺘﺎﺑـﺔ ﺍﻟﻨﺴﺨﺔ ﺍﻟﺜﺎﻧﻴﺔ ﻣﻦ ﻛﺘﺎﺏ The C Programming Languageﻟﻨﺴﺨﺔ ﺍﻟﻘﻴﺎﺳﻴﺔ ﻟﻠﻐﺔ ،Cﺃﻱ .(ANSI C
ﺩﻧﻴﺲ ﺭﻳﺘﺸﻲ
ﻛﲔ ﺗﻮﻣﺴﻦ
١,١ﺍﻷﺩﻭﺍﺕ ﺍﻟﻼﺯﻣﺔ .................................................................................... ١,٢ﺍﻟﺒﺪﺀ ﻣﻊ ﻟﻐﺔ ...................................................................................... C ١,٣ﺍﳌﺘﻐﲑﺍﺕ ﻭ ﺍﻟﺜﻮﺍﺑﺖ .........................................................Variables and Constants ١,٤ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ............................................................................... Comments ١,٥ﺍﻹﺩﺧﺎﻝ ..................................................................................... Input ١,٦ﺍﳌﺆﺛﺮﺍﺕ ................................................................................. Operators ١,٧ﺍﻟﻘﺮﺍﺭﺍﺕ ........................................................................... if, else, else…if ١,٨ﻋﻨﺎﺻﺮ ﻟﻐﺔ ....................................................................................... C ١,٩ﻣﻠﺨﺺ ﻟﻠﻔﺼﻞ ﺍﻷﻭﻝ،ﻣﻊ ﺇﺿﺎﻓﺎﺕ ................................................................... ﻣﻘﺪﻣﺔ :ﰲ ﻫﺬﺍ ﺍﻟﻔﺼﻞ ﺳﻨﺘﻌﻠﻢ ﺍﳌﺒﺎﺩﺉ ﺍﻷﻭﻟﻴﺔ ﻋﻠﻰ ﻛﻴﻔﻴﺔ ﺍﻟﱪﳎﺔ ﰲ ﻟﻐﺔ ،Cﻛﻴﻔﻴﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺍﳌﺘﻐﲑﺍﺕ ﻭ ﺍﻟﺜﻮﺍﺑـﺖ،
ﺍﻹﺩﺧﺎﻝ ﻭ ﺍﻹﺧﺮﺍﺝ ،ﻣﻊ ﺍﳉﻤﻞ ﺍﻟﺸﺮﻃﻴﺔ.
ﺑﺎﻟﺘﻮﻓﻴﻖ ﺇﻥ ﺷﺎﺀ ﺍﷲ
ﻗﺎﻝ ﺍﷲ ﺗﻌﺎﱃ:
﴿ ﻳﺮﻓﻊ ﺍﷲ ﺍﻟﺬﻳﻦ ﺁﻣﻨﻮﺍ ﻣﻨﻜﻢ ﻭﺍﻟﺬﻳﻦ ﺃﻭﺗﻮﺍ ﺍﻟﻌﻠﻢ ﺩﺭﺟﺎﺕ ﴾
ﺻﺪﻕ ﺍﷲ ﺗﻌﺎﱃ
22
ﺃﺩﻭﺍﺕ ﻟﻐﺔ Cﻫﻲ ﺛﻼﺛﺔ ﺃﺷﻴﺎﺀ ﻻ ﺃﻛﺜﺮ ،ﳏﺮﺭ ﻧﺼﻮﺹ ،texts editorﻣﺘـﺮﺟﻢ compilerﻭ ﻣـﺮﺑﻂ .linkerﻭ ﺃﻱ ﺑﺮﻧﺎﻣﺞ ﺗﺘﻢ ﻛﺘﺎﺑﺘﻪ ﳚﺐ ﺃﻥ ﳝﺮ ﻋﻠﻰ ﻫﺬﻩ ﺍﻷﺩﻭﺍﺕ ،ﻭ ﰲ ﺎﻳﺔ ﻳﻨﺘﺞ ﺍﳌﻠﻒ ﺍﻟﺘﻨﻔﻴﺬﻱ .ﻭ ﻻ ﳝﻜﻦ ﺍﻻﺳﺘﻐﻨﺎﺀ ﻋﻦ ﺃﺩﺍﺓ ﻣﻦ ﻫﺬﻩ ﺍﻷﺩﻭﺍﺕ .ﰲ ﺍﳌﺘﺮﲨﺎﺕ ﺍﳊﺪﻳﺜﺔ ﺃﺻﺒﺢ ﻛﻞ ﻣﻦ ﺍﻷﺩﻭﺍﺕ ﻣﺪﳎﺔ ﻣﻊ ﺑﻌﻀﻬﺎ ﳑﺎ ﺟﻌﻠﻬﺎ ﺃﻛﺜﺮ ﺳﻬﻮﻝ ﰲ ﺍﻻﺳﺘﻌﻤﺎﻝ ،ﻓﻤﺜﻼ ﻟﻮ ﺃﺭﺩﻧﺎ ﺗﺮﲨﺔ ﻭ ﺭﺑﻂ ﺑﺮﻧﺎﻣﺞ ،ﺯﺭ ﻭﺍﺣﺪ ﻣﻦ ﻟﻮﺣﺔ ﺍﳌﻔﺎﺗﻴﺢ ﺃﻭ ﻧﻘﺮﺓ ﻣﻦ ﺍﻟﻔﺄﺭﺓ ﺗﻘﻮﻡ ﺗﺮﲨﺔ ﻭ ﺭﺑﻂ ﺍﳌﺸﺮﻭﻉ ﰒ ﺗﻨﻔﻴﺬ ﺍﻟﱪﻧﺎﻣﺞ. ﺃﻣﺎ ﰲ ﺍﻟﺴﺎﺑﻘﺔ ﻓﻜﺎﻧﺖ ﺗﺘﻢ ﻫﺬﻩ ﺍﻟﻌﻤﻠﻴﺎﺕ ﻋﻠﻰ ﺷﻜﻞ ﺃﻭﺍﻣﺮ ﻣﻦ .Console ١,١,١ﳏﺮﺭ ﻧﺼﻮﺹ :texts editor
ﺍﳋﻄﻮﺓ ﺍﻷﻭﻝ ﰲ ﺍﻟﱪﳎﺔ ﻫﻲ ﻛﺘﺎﺑﺔ ﺍﻟﱪﻧﺎﻣﺞ ،ﻭ ﻃﺒﻌﺎ ﺫﻟﻚ ﻳﺘﻢ ﻋﱪ ﳏﺮﺭﺍﺕ ﻧﺼﻮﺹ ،ﻭ ﰲ ﻟﻐﺔ Cﻧﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﺍﻟـﱪﺍﻣﺞ ﻋﻠﻰ ﺃﻱ ﳏﺮﺭ ﻧﺼﻮﺹ ،ﻓﻘﻂ ﻧﺮﺍﻋﻲ ﺃﻥ ﻳﺘﻢ ﺣﻔﻆ ﻣﺼﺪﺭ ﺍﻟﱪﻧﺎﻣﺞ ﻋﻠﻰ ﺻﻴﻐﺔ ،.cﻫﻨﺎﻙ ﺑﻌﺾ ﺍﳌﺘﺮﲨﺎﺕ )ﺍﻟﻘﺪﳝﺔ( ﺍﻟـﱵ ﻻ ﻳﻬﻤﻬﺎ ﺍﻣﺘﺪﺍﺩ ﺍﳌﻠﻒ ﺍﻟﻨﺼﻲ ﻟﻠﱪﻧﺎﻣﺞ ،ﻭ ﻟﻜﻦ ﻣﻦ ﺍﻷﻓﻀﻞ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﺼﻴﻐﺔ ﺍﻟﺮﲰﻴﺔ .ﻭ ﻣﻦ ﺷﺮﻭﻁ ﺍﳌﻠﻔﺎﺕ ﺍﻟﻨﺼﻴﺔ ﻟﻠﻐﺔ Cﺃﻥ ﺗﻜﻮﻥ ﺍﻟﻨﺼﻮﺹ ﻣﻜﺘﻮﺑﺔ ﺑﻨﻈﺎﻡ ،ASCIIﻣﺜﻼ ﳏﺮﺭ KWriteﰲ ﺃﻧﻈﻤﺔ Linuxﻭ Notepadﰲ ﺃﻧﻈﻤﺔ ،Windowsﻛِـﻼ ﻣـﻦ ﳏﺮﺭﻳﻦ ﻳﻌﺘﻤﺪﺍﻥ ﻋﻠﻰ ﺷﻔﺮﺓ .ASCIIﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺍﶈﺮﺭ Wordﰲ ﺃﻧﻈﻤﺔ Windowsﺃﻭ KWordﰲ ﺃﻧﻈﻤﺔ .Linux
١,١,٢ﻣﺘﺮﺟﻢ :compiler ﺗﻘﻮﻡ ﺍﳌﺘﺮﲨﺎﺕ ﺑﺘﺮﲨﺔ ﺃﻭ ﲢﻮﻳﻞ ﺍﳌﻠﻔﺎﺕ ﺍﳌﺼﺪﺭﻳﺔ ﺇﱃ ﻟﻐﺔ ﻣﻨﺨﻔﻀﺔ ﺍﳌﺴﺘﻮﻯ ﺇﻥ ﱂ ﺗﻜﻮﻥ ﻫﻨﺎﻙ ﺃﺧﻄﺎﺀ ﰲ ﻗﻮﺍﻋﺪ ﺍﻟﻠﻐﺔ، ﳝﻜﻦ ﺃﻥ ﺗﺘﺮﺟﻢ ﺇﱃ ﻟﻐﺔ ﺍﻟﺘﺠﻤﻴﻊ Assembly Languageﺃﻭ ﺇﱃ ﻟﻐﺔ ﺍﻵﻟﺔ Machine Languageﻣﺒﺎﺷﺮﺓ ،ﺣﻴﺚ ﺑﻌﺪ ﺍﻟﺘﺮﲨـﺔ ﻳﺘﻢ ﺇﻧﺸﺎﺀ ﻣﻠﻔﺎﺕ ﺑﺼﻴﻐﺔ ..objﲢﺘﻮﻱ ﻫﺬﻩ ﺍﳌﻠﻔﺎﺕ ﻋﻠﻰ ﺗﻌﻠﻴﻤﺎﺕ ﺍﻟﺘﺠﻤﻴﻊ ﺃﻭ ﺍﻵﻟﺔ ﻣﻢ ﻳﺴﻬﻞ ﻋﻤﻠﻴﺔ ﺭﺑﻂ ﻟﻐﺘﲔ ﺃﻭ ﺃﻛﺜـﺮ ﻣﻊ ﺑﻌﻀﻬﺎ ،ﻓﻤﺜﻼ ﳝﻜﻨﻨﺎ ﺍﺳﺘﺪﻋﺎﺀ ﺩﻭﺍﻝ ﻣﻦ ﻟﻐﺔ Pascalﰲ ﻟﻐﺔ .C ﻳﻮﺟﺪ ﺍﻟﻌﺪﻳﺪ ﻣﻦ ﺍﳌﺘﺮﲨﺎﺕ ﰲ ﺃﻏﻠﺐ ﺍﻷﻧﻈﻤﺔ ،ﻣﺜﻼ ﰲ ﺃﻧﻈﻤﺔ Windowsﻳﻮﺟﺪ ﺍﳌﺘﺮﺟﻢ Visual C++ﺣﻴﺚ ﻳﻘﻮﻡ ﺑﺘﺮﲨـﺔ ﻛﻼ ﺍﻟﻠﻐﺘﲔ Cﻭ ،C++ﻭ ﻫﻮ ﻣﻘﺪﻡ ﻣﻦ ﻃﺮﻑ ﺷﺮﻛﺔ ،MicroSoftﻭ ﻳﻮﺟﺪ ﻛﺬﻟﻚ ﺍﳌﺘﺮﺟﻢ Dev-C++ﻭ ﺍﳌﻘﺪﻡ ﻣﻦ ﺷﺮﻛﺔ ،Bloodshedﻭ ﻣﺘﺮﲨﺎﺕ ﺃﺧﺮﻯ ﻣﺜﻞ .... ،Pelles C ،Quick C ،Turbo Cﺑﺎﻟﻨﺴﺒﺔ ﻟﻠﻤﺘﺮﺟﻢ Visual C++ﻓﻬﻮ ﻏﲑ ﳎﺎﱐ. ﺍﳌﺘﺮﺟﻢ Dev-C++ﻣﻦ ﺍﳌﺘﺮﲨﺎﺕ ﺍﺎﻧﻴﺔ ﻭ ﳝﻜﻦ ﲢﻤﻴﻠﻪ ﻣﻦ ﺍﻟﺮﺍﺑﻂ ﺍﻟﺘﺎﱄ: http://www.bloodshed.net/devcpp.html
23
ﺍﳌﺘﺮﺟﻢ Turbo Cﺃﻳﻀﺎ ﻣﻦ ﺍﳌﺘﺮﲨﺎﺕ ﺍﺎﻧﻴﺔ ،ﻭ ﻫﻮ ﻣﻦ ﺃﻗﺪﻣﻬﺎ ،ﻭ ﺍﻷﻛﺜﺮ ﺍﺳﺘﻌﻤﺎﻟﻨﺎ ﰲ ﺍﳉﺎﻣﻌﺎﺕ ،ﺣﻴﺚ ﳝﻜﻦ ﲢﻤﻴﻠﻪ ﻣﻦ ﺍﻟﺮﺍﺑﻂ ﺍﻟﺘﺎﱄ: http://www.pitt.edu/~stephenp/misc/downloadTC.html
ﺍﳌﺘﺮﺟﻢ Pelles Cﺃﻳﻀﺎ ﻣﻦ ﺍﳌﺘﺮﲨﺎﺕ ﺍﺎﻧﻴﺔ ﻭ ﻳﻌﺘﱪ ﻣﻦ ﺃﻓﻀﻠﻬﺎ ﻭ ﳝﻜﻦ ﲢﻤﻴﻠﻪ ﻣﻦ ﺍﻟﺮﺍﺑﻂ ﺍﻟﺘﺎﱄ:
http://www.smorgasbordet.com/pellesc/download.htm
ﺃﻣﺎ ﰲ ﺃﻧﻈﻤﺔ Unixﻭ ،Linuxﻓﻼ ﲢﺘﺎﺝ ﺇﱃ ﻣﺘﺮﲨﺎﺕ ﻷﺎ ﻣﺪﳎﺔ ﻣﻊ ﺃﻱ ﻧﺴﺨﺔ ﻣﻦ ﻧﺴﺦ Unixﻭ ،Linuxﻛﻞ ﻣﺎ ﲢﺘﺎﺟـﻪ ﻫﻮ ﳏﺮﺭ ﻧﺼﻮﺹ .ﻭ ﻫﺬﺍ ﻻ ﻳﻌﲏ ﺃﻧﻪ ﻻ ﻳﻮﺟﺪ ﻣﺘﺮﲨﺎﺕ ﻟﺘﻠﻚ ﺍﻷﻧﻈﻤﺔ ،ﺑﻞ ﻳﻮﺟﺪ ﻭ ﺭﲟﺎ ﻋﺪﺩﻫﺎ ﺃﻛﺜﺮ ﻣـﻦ ﺍﻟـﱵ ﻫـﻲ ﻣﻮﺟﻮﺩﺓ ﻋﻠﻰ ﻧﻈﺎﻡ .Windows ﺃﺩﺧﻞ ﻋﻠﻰ ﺍﻟﺮﺍﺑﻂ ﺍﻟﺘﺎﱄ ﺣﻴﺚ ﺗﻮﺟﺪ ﻣﺘﺮﲨﺎﺕ ﳎﺎﻧﻴﺔ ﻋﺪﻳﺪﺓ ﰲ ﻛﻞ ﻣﻦ ﺃﻧﻈﻤﺔ Windowsﻭ ﺃﻧﻈﻤﺔ :Linux http://www.thefreecountry.com/compilers/cpp.shtml
ﲨﻴﻊ ﺍﳌﺘﺮﲨﺎﺕ ﺍﳊﺪﻳﺜﺔ ﻣﺘﻮﻓﺮﺓ ﺎ ،IDEﻣﺎﺫﺍ ﻳﻌﲏ ﻫـﺬﺍ ﺍﳌـﺼﻄﻠﺢ؟ ،ﺃﻭﻻ ﺍﻟﻜﻠﻤـﺔ IDEﳐﺘـﺼﺮﺓ ﻣـﻦ Development Environmentﺃﻱ ﺑﻴﺌﺔ ﺗﻄﻮﻳﺮ ﻣﺘﻜﺎﻣﻠﺔ ،ﺣﻴﺚ ﺗﺴﺎﻋﺪ ﺍﳌﺘﺮﲨﺎﺕ ﺫﺍﺕ ﺑﻴﺌﺔ ﺗﻄﻮﻳﺮ ﻣﺘﻜﺎﻣﻠﺔ ﻋﻠﻰ ﺍﳌـﱪﻣﺞ ﰲ ﻛﻞ ﻣﻦ ﺍﻟﺘﺤﺮﻳﺮ ،ﺍﻟﺘﺮﲨﺔ ﻭ ﺍﻟﺮﺑﻂ ،ﻓﻔﻲ ﺍﻟﺴﺎﺑﻖ ﻛﺎﻧﺖ ﺍﻟﺘﺮﲨﺔ ﻭ ﺍﻟﺮﺑﻂ ﺗﺘﻢ ﻋﻠﻰ ﺷﻜﻞ ﺃﻭﺍﻣﺮ ،ﺃﻣﺎ ﰲ ﺍﻟﺒﻴﺌـﺎﺕ ﺍﻟﺘﻄـﻮﻳﺮ ﺍﳌﺘﻜﺎﻣﻠﺔ ﻓﺄﺻﺒﺤﺖ ﻋﻤﻠﻴﺔ ﺍﻟﺮﺑﻂ ﻭ ﺍﻟﺘﺮﲨﺔ ﺗﺘﻢ ﻋﱪ ﺯﺭ ﻭﺍﺣﺪ ﻣﻦ ﻟﻮﺣﺔ ﺍﳌﻔﺎﺗﻴﺢ ﺃﻭ ﻋﱪ ﻧﻘﺮﺓ ﻣﻦ ﺍﻟﻔﺄﺭﺓ ،ﺃﻣﺎ ﻛﺘﺎﺑﺔ ﺍﻟﱪﺍﻣﺞ ﻓﺘﺘﻢ ﻋﱪ ﳏﺮﺭﺍﺕ ﻧﺼﻮﺹ ﻣﺴﺘﻘﻠﺔ ﻋﻦ ﺍﳌﺘﺮﺟﻢ ،ﻭ ﻫﺬﻩ ﺍﻟﻈﺎﻫﺮﺓ ﻣﻮﺟﻮﺩﺓ ﺇﱃ ﺣﺪ ﺍﻵﻥ ﰲ ﺃﻧﻈﻤﺔ ،Unix/Linuxﺣﱴ ﺃﺩﺍﺓ Qt ﺗﻌﺘﻤﺪ ﻋﻠﻰ ﺃﻭﺍﻣﺮ ﻟﺘﺮﲨﺔ ﻭ ﺍﻟﺮﺑﻂ .ﻭ ﻫﻨﺎ ﺃﻳﻀﺎ ﻛﻨﺖ ﺃﺭﻳﺪ ﺃﻥ ﻧﺮﻯ ﻛﻴﻒ ﺗﺘﻢ ﺍﻟﺘﺮﲨﺔ ﰲ ﻫﺬﺍ ﺍﻷﻧﻈﻤﺔ ،ﻭ ﻧﺄﺧـﺬ ﻣﺜـﺎﻻ ﻟﺬﻟﻚ ،ﻣﺜﻼ ﻟﺪﻳﻨﺎ ﺑﺮﻧﺎﻣﺞ ﳏﻔﻮﻅ ﺑﺈﺳﻢ ،cprog.cﻓﻤﻦ ﺧﻂ ﺍﻷﻭﺍﻣﺮ )ﻣﺜﻼ (Konsoleﻧﻜﺘﺐ: Integrated
cc cprog.c
ﻫﺬﻩ ﰲ ﺣﺎﻟﺔ ﺃﻥ ﺍﻟﱪﻧﺎﻣﺞ ﻣﻌﺘﻤﺪ ﻋﻠﻰ ﻟﻐﺔ Cﻓﻘﻂ ،ﺃﻣﺎ ﺇﺫﺍ ﻛﺎﻥ ﻣﺪﻣﺞ ﻣﻊ ﻟﻐﺔ C++ﻓﺴﻨﻜﺘﺐ ﺍﻷﻣﺮ gccﺑﺪﻝ .ccﻭ ﻃﺒﻌﺎ ﺗﻮﺟﺪ ﻃﺮﻕ ﺃﺧﺮﻯ ﻣﺜﻞ: cc –o cprog cprog.c
ﻫﻨﺎ ﺳﺘﻜﻮﻥ ﻟﺪﻳﻚ ﺇﻣﻜﺎﻧﻴﺔ ﺇﻋﺎﺩﺓ ﺗﺴﻤﻴﺔ ﺍﻟﱪﻧﺎﻣﺞ ،ﺃﻣﺎ ﻋﻤﻠﻴﺔ ﺗﻨﻔﻴﺬ ﺍﻟﱪﻧﺎﻣﺞ ﻓﺘﻜﻮﻥ ﻛﺘﺎﱄ: ./cprog
24
١,١,٣ﺍﳌﺮﺑﻂ :linker ﻳﻘﻮﻡ ﺍﳌﺮﺑﻂ ﲜﻤﻊ ﺍﳌﻠﻔﺎﺕ ﺫﺍﺕ ﺍﻟﺼﻴﻐﺔ .objﰒ ﻳﻌﻄﻴﻨﺎ ﺍﻟﱪﺍﻣﺞ ﺍﻟﺘﻨﻔﻴﺬﻳﺔ ﻭ ﺍﻟﱵ ﺗﻜﻮﻥ ﻏﺎﻟﺒﺎ ﺑﺎﻣﺘﺪﺍﺩ ،.exeﺃﻭ ﻣﻠﻔـﺎﺕ ﻣﻜﺘﺒﺎﺕ ﺍﻟﺮﺑﻂ ﺍﻟﺪﻳﻨﺎﻣﻴﻜﻴﺔ ﻭ ﺍﻟﱵ ﺗﻜﻮﻥ ﺑﺈﻣﺘﺪﺍﺩ ،.dllﻭ ﳝﻜﻦ ﺃﻥ ﺗﻜﻮﻥ ﻫﺬﻩ ﺍﳌﻠﻔﺎﺕ ﻣﻜﺘﻮﺑﺔ ﲟﺨﺘﻠﻒ ﺍﻟﻠﻐﺎﺕ.
ﺍﻟﺸﻜﻞ :١,١,١ﻣﺮﺣﻠﺔ ﺇﻧﺸﺎﺀ ﻣﻠﻒ ﺗﻨﻔﻴﺬﻱ
25
ﻗﻢ ﺑﺘﺤﻤﻴﻞ ﻭ ﺗﺜﺒﻴﺖ ﺃﺣﺪ ﺍﳌﺘﺮﲨﺎﺕ ﺍﻟﺴﺎﺑﻘﺔ ﻭ ﻗﻢ ﺑﺘﺸﻐﻴﻠﻬﺎ ﻛﺄﻱ ﺑﺮﻧﺎﻣﺞ ،ﰒ ﻗﻢ ﺑﺈﻧﺸﺎﺀ ﻣﺸﺮﻭﻉ ﺟﺪﻳﺪ ﻟﻠﻐﺔ Cﰲ ﺑﻴﺌﺔ ﺍﻟـ Consoleﻣﻊ ﺇﻧﺸﺎﺀ ﻣﻠﻒ ﻧﺼﻲ ﺟﺪﻳﺪ ﻭ ﺍﳊﺮﺹ ﻋﻠﻰ ﺃﻥ ﻳﺘﻢ ﺣﻔﻈﻪ ﺑﺎﻣﺘﺪﺍﺩ ،.cﳝﻜﻦ ﻛﺘﺎﺑـﺔ main.cﻛﺈﺳـﻢ ﻟﻠﻤﻠﻒ ﺍﻟﻨﺼﻲ ﻭ ﺍﻟﺬﻱ ﺳﻨﻘﻮﻡ ﺑﺎﻟﻜﺘﺎﺑﺔ ﻋﻠﻴﻪ ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﻭ ﻫﻮ: >#include<stdio.h )(main { ;)"!printf("Hello, World }
ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ
1 2 3 4 5 6
C
ﻣﻼﺣﻈﺔ: ﻗﻢ ﺑﻜﺘﺎﺑﺔ ﺍﻟﱪﻧﺎﻣﺞ ﺑﺪﻭﻥ ﺍﻟﺘﺮﻗﻴﻤﺎﺕ ،ﺃﻱ ﻧﻜﺘﺐ ﺍﻟﱪﻧﺎﻣﺞ ﻋﻠﻰ ﺍﻟﺸﻜﻞ ﺍﻟﺘﺎﱄ:
>#include<stdio.h )(main { ;)"!printf("Hello, World }
ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ
C
ﻫﺬﺍ ﻣﻦ ﺃﺑﺴﻂ ﺍﻟﱪﻧﺎﻣﺞ ﺍﻟﱵ ﳝﻜﻦ ﻛﺘﺎﺑﺘﻬﺎ ،ﻳﻘﻮﻡ ﻫﺬﺍ ﺍﻟﱪﻧﺎﻣﺞ ﻋﻨﺪ ﺗﺮﲨﺘﻪ ﻭ ﺗﻨﻔﻴﺬﻩ ﺑﻄﺒﺎﻋﺔ ﺍﳉﻤﻠـﺔ Hello, Worldﻋﻠـﻰ ﺍﻟﺸﺎﺷﺔ ﰲ ﺑﻴﺌﺔ ﺍﻟـ .Consoleﺍﻟﺴﻄﺮ ﺍﻷﻭﻝ ﻣﻦ ﺍﻟﱪﻧﺎﻣﺞ ﺑﻪ ﺍﻟﺸﻔﺮﺓ ) #include<stdio.h> (Codeﻭ ﻫﻲ ﻣﻘﺴﻤﺔ ﺇﱃ ﻗﺴﻤﲔ ،ﺍﻷﻭﻝ ﻫﻮ > < ﺇﱃ ﻣﺸﺮﻭﻋﻨﺎ .ﻳﻮﺟﺪ ﺍﻟﻌﺪﻳﺪ ﻣﻦ ﺍﳌﻠﻔﺎﺕ ﺍﻟﺮﺃﺳﻴﺔ، ﺳﻨﺘﻄﺮﻕ ﺇﻟﻴﻬﺎ ﻓﻴﻤﺎ ﺑﻌﺪ.
26
ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻟﺚ ﻳﻮﺟﺪ ﺍﺳﻢ ﺩﺍﻟﺔ ﻭ ﻫﻲ )( mainﻭ ﻫﻲ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ﻷﻱ ﻣﺸﺮﻭﻉ ﻭ ﻻ ﳝﻜﻦ ﺍﻻﺳﺘﻐﻨﺎﺀ ﻋﻨـﻬﺎ ،ﻭ ﻻ ﳝﻜﻦ ﺍﻟﺘﻐﲑ ﰲ ﺍﲰﻬﺎ ﺇﻻ ﰲ ﺣﺎﻻﺕ .ﻭ ﻣﻦ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﻳﺒﺪﺃ ﺍﻟﱪﻧﺎﻣﺞ ﺑﺎﻟﺘﻨﻔﻴﺬ ﺑﺸﻜﻞ ﻣﺘﺮﺗﺐ ،ﺃﻣﺎ ﺍﻟﻘﻮﺳﲔ ﺑﻌﺪ ﺍﺳﻢ ﺍﻟﺪﺍﻟـﺔ ﻓﻬﻤﺎ ﺍﻟﻠﺬﺍﻥ ﻳﺒﻴﻨﺎﻥ ﻋﻠﻰ ﺃﺎ ﺩﺍﻟﺔ )ﻭ ﺃﺎ ﺩﺍﻟﺔ ﺑﺪﻭﻥ ﻭﺳﺎﺋﻂ( ﻭ ﻟﻴﺴﺖ ﻣﺘﻐﲑ ﺃﻭ ﺛﺎﺑﺖ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺮﺍﺑﻊ ﺗﻮﺟﺪ ﺍﳊﺎﺿﻨﺔ { ﻭ ﺍﻟﱵ ﺗﻌﲏ ﺑﺪﺍﻳﺔ ﺍﻟﺪﺍﻟﺔ .main ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﺗﻮﺟﺪ ﺍﻟﻜﻠﻤﺔ printfﻭ ﻫﻲ ﻋﺒﺎﺭﺓ ﻋﻦ ﺩﺍﻟﺔ ﻣﻮﺟﻮﺩﺓ ﰲ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ،stdio.hﻭ ﻫﻲ ﳐﺘﺼﺮﺓ ﻣﻦ ،print formatﺃﻱ ﺻﻴﻐﺔ ﺍﻟﻄﺒﻊ ،ﻭ ﻫﻲ ﺗﻘﻮﻡ ﺑﻄﺒﻊ )ﺇﺧﺮﺍﺝ( ﻣﺎ ﻫﻮ ﺑﺪﺍﺧﻞ ﺃﻗﻮﺍﺱ ﺍﻟﺪﺍﻟﺔ ﺇﱃ ﺍﻟﺸﺎﺷﺔ ،ﻭ ﰲ ﻣﺜﺎﻟﻨـﺎ ﻫـﺬﺍ ﻳﻮﺟﺪ ﺍﻟﻨﺺ ! Hello, Worldﻭ ﻫﻲ ﺍﳉﻤﻠﺔ ﺍﻟﱵ ﺳﻴﺘﻢ ﺇﺧﺮﺍﺟﻬﺎ ﺇﱃ ﺍﻟﺸﺎﺷﺔ ،ﻭ ﺗﻜﻮﻥ ﺍﳉﻤﻞ ﺩﺍﺋﻤﺎ ﺩﺍﺧﻞ ﺍﻗﺘﺒﺎﺳﻴﲔ " "، ﻭ ﰲ ﺎﻳﺔ ﺍﻟﺴﻄﺮ ﻧﻜﺘﺐ ﺍﻟﻔﺎﺻﻠﺔ ﺍﳌﻨﻘﻮﻃﺔ ﻭ ﻫﻲ ﺗﻌﲏ ﺎﻳﺔ ﺍﻟﺴﻄﺮ ﺍﻟﺘﻌﻠﻴﻤﺔ )ﺃﻭ ﺍﻟﺘﻌﻠﻴﻤﺎﺕ( .ﺗﺴﺘﻌﻤﻞ ﺍﻟﺪﺍﻟﺔ printfﺑﺼﻔﺔ ﻋﺎﻣﺔ ﰲ ﻋﺮﺽ ﺃﻭ ﺇﺧﺮﺍﺝ ﻣﻌﻠﻮﻣﺎﺕ ﺇﱃ ﺃﺩﺍﺓ ﺍﻹﺧﺮﺍﺝ ﻭ ﻫﻲ ﺍﻟﺸﺎﺷﺔ Screenﺍﳋﺎﺻﺔ ﺑﺎﳊﺎﺳﻮﺏ. ﻭ ﺃﺧﲑﺍ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺩﺱ ﺣﻴﺚ ﻣﻮﺟﻮﺩ ﺑﻪ ﺍﳊﺎﺿﻨﺔ } ﻭ ﺍﻟﱵ ﺗﻌﲏ ﺎﻳﺔ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ .mainﻭ ﺗﺴﻤﻰ ﺣﺎﺿﻨﺔ ﺍﻟﺒﺪﺍﻳﺔ { ﻭ ﺣﺎﺿﻨﺔ ﺍﻟﻨﻬﺎﻳﺔ } ﻭ ﻣﺎ ﺑﻴﻨﻬﻤﺎ ﺑﺎﻟـ ،blockﺻﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ:
ﺍﻟﺸﻜﻞ :١,٢,١
block
ﳝﻜﻦ ﻛﺘﺎﺑﺔ ﺍﻟﱪﺍﻣﺞ ﺍﻟﺴﺎﺑﻖ ﺑﻄﺮﻕ ﳐﺘﻠﻔﺔ ،ﺣﻴﺚ ﳝﻜﻦ ﺗﻘﺴﻴﻢ ﺍﳉﻤﻠﺔ
! Hello, World
ﺇﱃ ﻗﺴﻤﲔ ﻣﺜﻞ: >#include<stdio.h
)(main { ;)" printf("Hello, ;)"!printf("World }
1 2 3 4 5 6 7
ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٢ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ (٢) C ﻭ ﻫﻨﺎ ﺳﻴﺘﻢ ﻃﺒﻊ ﺍﳉﻤﻠﺔ ﻛﺎﻣﻠﺔ ﰲ ﺳﻄﺮ ﻭﺍﺣﺪ ،ﻭ ﺗﻘﺴﻴﻤﻬﺎ ﻻ ﻳﻌﲏ ﺃﻥ ﻛﻞ ﻛﻠﻤﺔ ﰲ ﺳﻄﺮ .ﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﻛﺘﺎﺑـﺔ ﺍﳉﻤﻠـﺔ ﺣﺮﻓﻴﺎ ،ﻛﻞ ﺣﺮﻑ ﺑﺪﺍﻟﺔ ﻣﻦ .printfﺃﻭ ﳝﻜﻦ ﻛﺘﺎﺑﺔ ﺍﻟﺪﺍﻟﲔ ﰲ ﺳﻄﺮ ﻭﺍﺣﺪ ،ﻣﺜﺎﻝ:
27 >#include<stdio.h )(main { ;)"!printf("Hello, "), printf("World }
ﺃﻭ:
ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٣ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ (٣) C
1 2 3 4 5 6
>#include<stdio.h
1 2 3 4 5 6
>#include<stdio.h
1 2 3 4 5 6 7
)(main { ;)"!printf("Hello, "); printf("World }
ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٤ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ (٤) C ﻭ ﺗﻮﺟﺪ ﻃﺮﻳﻘﺔ ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﳍﺎ ﻭ ﻫﻲ:
)(main { printf("Hello, ;)"!World }
ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٥ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ (٥) C ﻋﻨﺪ ﺗﺮﲨﺔ ﻫﺬﺍ ﺍﳌﺜﺎﻝ ﺳﻴﻨﺒﻬﻚ ﺍﳌﺘﺮﺟﻢ ﻋﻦ ﻭﺟﻮﺩ ﺃﺧﻄﺎﺀ ،ﻣﻨﻬﺎ ﻧﺴﻴﺎﻥ ﻗﻮﺱ ﺍﻟﻨﻬﺎﻳﺔ ﻟﺪﺍﻟـﺔ ،printfﻭ ﻟﺘﻔـﺎﺩﻱ ﻫـﺬﻩ ﺍﻷﺧﻄﺎﺀ ﻧﻘﻮﻡ ﺑﻮﺿﻊ anti-slashﰲ ﺎﻳﺔ ﺍﻟﺴﻄﺮ ﺍﻷﻭﻝ ﻣﻦ ﺍﻟﺪﺍﻟﺔ ،printfﻭ ﺗﺼﺒﺢ ﺍﻟﺪﺍﻟﺔ ﻛﺎﻵﰐ: \ printf("Hello, ;)"!World
ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٦ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ (٦) C ﰲ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﺇﻥ ﻛﺘﺒﻨﺎ ﺍﻟﺴﻄﺮ ﺍﻷﻭﻝ )ﺍﻟﺬﻱ ﻳﺘﻤﺜﻞ ﰲ ﺿﻢ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ (stdio.hﰲ ﺎﻳﺔ ﺍﻟﱪﻧﺎﻣﺞ ﻓﺈﻥ ﺍﳌﺘﺮﺟﻢ ﻟـﻦ ﳚﺪ ﺍﻟﺪﺍﻟﺔ ،printfﻭ ﺳﺘﻨﺠﻢ ﺃﺧﻄﺎﺀ ﻋﻦ ﺫﻟﻚ ،ﻟﺬﺍ ﳚﺐ ﺩﺍﺋﻤﺎ ﺃﻥ ﻳﻜﻮﻥ ﺿﻢ ﺍﳌﻠﻔﺎﺕ ﺍﻟﺮﺃﺳﻴﺔ ﻗﺒـﻞ ﺍﻟـﺪﻭﺍﻝ ﺍﳌـﺮﺍﺩ ﺍﺳﺘﻌﻤﺎﳍﺎ ﻭ ﻳﺴﺘﺤﺴﻦ ﺩﺍﺋﻤﺎ ﺃﻥ ﻳﺘﻢ ﺿﻢ ﺍﳌﻠﻔﺎﺕ ﰲ ﺑﺪﺍﺑﺔ ﻛﻞ ﻣﺸﺮﻭﻉ. ﳝﻜﻦ ﻛﺘﺎﺑﺔ ﺍﻟﻜﻠﻤﺔ Hello,ﰲ ﺳﻄﺮ ﻭ ﺍﻟﻜﻠﻤﺔ ! Worldﰲ ﺳﻄﺮ ﺁﺧﺮ ﻭ ﺫﻟﻚ ﺑﺈﺿﺎﻓﺔ ﺍﻟﺮﻣﺰ \nﺑﲔ ﺍﻟﻜﻠﻤﺘﲔ ،ﻣﺜﺎﻝ: >#include<stdio.h )(main {
1 2 3 4
28 ;)"!printf("Hello, \nWorld }
ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٧ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ (٧) C ﺃﻭ ﻛﺘﺎﺑﺔ ﻛﻞ ﻣﻦ ﺍﻟﻜﻠﻤﺎﺕ ﰲ ﺩﺍﻟﺔ ﻣﺜﻞ:
>#include<stdio.h )(main { ;)" printf("Hello, ;)"printf("\n ;)"!printf("World }
ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٨ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ (٨) C ﻋﻨﺪ ﺗﺮﲨﺔ ﺍﻟﱪﻧﺎﻣﺞ ﻭ ﺗﻨﻔﻴﺬﻩ ﻓﻠﻦ ﲡﺪ ﺍﻟﺮﻣﺰ \nﻭ ﺳﺘﺠﺪ ﺃﻥ ﻛﻞ ﻣﻦ ﺍﻟﻜﻠﻤﺘﲔ ﰲ ﺳﻄﺮ ،ﻳﺘﻢ ﺍﺳﺘﺒﺪﺍﻝ ﺍﻟﺮﻣﺰ ﺟﺪﻳﺪ ﺣﻴﺚ ﻻ ﻳﺘﻢ ﻃﺒﺎﻋﺔ ﺍﻟﺮﻣﺰ ،ﻭ ﺍﳊﺮﻑ nﻳﻌﲏ .New line ﳝﻜﻦ ﻛﺘﺎﺑﺔ ﺍﳌﺜﺎﻝ ﺍﻷﻭﻝ ﰲ ﺛﻼﺛﺔ ﺃﺳﻄﺮ ﻛﻤﺎ ﰲ ﻳﻠﻲ:
\n
5 6
1 2 3 4 5 6 7 8
ﺑـﺴﻄﺮ
>#include<stdio.h
1 2 3
>#include<stdio.h
1 2 3 4
{)(#include<stdio.h> main };)"!printf("Hello, World
1 2
};)"!main(){printf("Hello, World
ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٩ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ (٩) C ﰎ ﲨﻊ ﲨﻴﻊ ﺍﻷﺳﻄﺮ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻟﺚ ،ﻭ ﺍﻟﱪﻧﺎﻣﺞ ﻳﻌﻤﻞ ﻣﺜﻞ ﺍﻟﺴﺎﺑﻖ ﺑﺪﻭﻥ ﺃﺧﻄﺎﺀ ،ﺣﻴﺚ ﺳﺘﻼﺣﻆ ﺃﻧﻪ ﳝﻜﻦ ﺍﺳـﺘﻌﻤﺎﻝ ﺍﳊﺎﺿﻨﺔ { )ﺑﺪﺍﻳﺔ ﺍﻟﺪﺍﻟﺔ( ﻭ ﺍﳊﺎﺿﻨﺔ } )ﺎﻳﺔ ﺍﻟﺪﺍﻟﺔ( ﰲ ﻧﻔﺲ ﺍﻟﺴﻄﺮ ،ﻭ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺃﻛﺜﺮ ﻣﻦ ﺫﻟﻚ ﻣﺜﻞ:
{)(main };)"!printf("Hello, World
ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٠ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ (١٠) C ﻭ ﻃﺮﻕ ﺃﺧﺮﻯ ،ﻭ ﻟﻜﻦ ﳚﺐ ﺃﻥ ﺗﻜﻮﻥ ﺍﻷﻭﺍﻣﺮ ،ﺍﻟﻮﻇﺎﺋﻒ ﻭ ﺍﻟﺪﻭﺍﻝ ﺍﳌﺮﺍﺩ ﺇﺳﺘﻌﻤﺎﳍﺎ ﺩﺍﺧﻞ ﺍﳊﺎﺿﻨﺘﲔ } { ﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ. ﻭ ﻣﺜﻞ ﻫﺬﻩ ﺍﻟﻄﺮﻕ ﻻ ﻳﻔﻀﻞ ﺍﺳﺘﻌﻤﺎﳍﺎ ﻭ ﺧﺎﺻﺔ ﺇﺫﺍ ﻛﺎﻥ ﺍﻟﱪﻧﺎﻣﺞ ﻛﺒﲑ .ﻭ ﺗﻮﺟﺪ ﻃﺮﻳﻘﺔ ﻻ ﳝﻜﻦ ﺇﺳﺘﻌﻤﺎﳍﺎ ﻭ ﻫﻲ ﻣﻮﺿﺤﺔ ﰲ ﺍﳌﺜﺎﻝ ﺍﻟﺘﺎﱄ:
ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١١ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ (١١) C
29
ﺇﺫﺍ ﺗﺮﲨﺔ ﻫﺬﺍ ﺍﳌﺜﺎﻝ ﻓﺴﻴﻨﺒﻬﻚ ﺍﳌﺘﺮﺟﻢ ﻋﻦ ﻭﺟﻮﺩ ﺧﻄﺄ ﻷﻥ ﺍﻟﻜﻠﻤﺔ #includeﺗﺘﻄﻠﺐ ﺳﻄﺮﺍ ﻛﺎﻣﻼ ﳍﺎ )ﻣـﻦ ﻗﻮﺍﻋـﺪ ﺍﻟﻠﻐﺔ( .ﺗﺪﻋﻰ ﺍﻟﻜﻠﻤﺔ #includeﺑﺎﻟﺘﻮﺟﻴﻪ directiveﺃﻭ ﻗﺒﻞ ﺍﳌﻌﺎﰿ preprocessorﻭ ﲰﻴﺖ ﺑﻘﺒﻞ ﺍﳌﻌﺎﰿ ﻷﻧﻪ ﻳﺘﻢ ﺗﻨﻔﻴﺬﻫﺎ ﻗﺒﻞ ﺍﻟﺘﺮﲨﺔ ،ﻭ ﻫﻲ ﺗﻘﻮﻡ ﺑﻀﻢ ﳏﺘﻮﻳﺎﺕ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ﺍﳌﻄﻠﻮﺏ ﺇﱃ ﺍﳌﺸﺮﻭﻉ ،ﺣﻴﺚ ﳛﺘﻮﻱ ﺫﻟﻚ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳـﻲ ﻋﻠـﻰ ﳎﻤﻮﻋﺔ ﻣﻦ ﺛﻮﺍﺑﺖ ،ﺑﻨﻴﺎﺕ ﻭ ﺩﻭﺍﻝ ﺗﺴﺎﻋﺪﻧﺎ ﰲ ﺑﺮﳎﺔ ﺑﺮﺍﳎﻨﺎ .ﺗﻮﺟﺪ ﺍﻟﻜﺜﲑ ﻣﻦ ﺍﻟﺘﻮﺟﻴﻬﺎﺕ directiveﻭ ﳝﻜﻦ ﲤﻴﺰﻫﺎ ﺑﺎﻟﺮﻣﺰ ،#ﺳﻨﻌﺮﻓﻬﺎ ﰲ ﺍﻟﺪﺭﻭﺱ ﺍﻟﻘﺎﺩﻣﺔ. ﳝﻜﻦ ﺃﻳﻀﺎ ﻭﺿﻊ blockﺩﺍﺧﻞ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ،mainﻣﺜﺎﻝ: >#include<stdio.h )(main { ;)"printf("Hello, World!\n { ;)"printf("Hello, World!\n } ;)"printf("Hello, World!\n }
1 2 3 4 5 6 7 8 9 10
ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٢ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ (١٢) C ﻭ ﻳﺘﻢ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻌﻬﺎ ﻛﺎﻟﺘﻌﺎﻣﻞ ﻣﻊ blockﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ،ﻭ ﳝﻜﻦ ﺇﻧﺸﺎﺀ ﺃﻛﺜﺮ ﻣﻦ blockﺩﺍﺧﻞ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ،ﺃﻭ ﺍﺳﺘﻌﻤﺎﻝ blockﺩﺍﺧﻞ blockﺁﺧﺮ. ١,٢,١ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻷﻋﺪﺍﺩ:
ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻷﻋﺪﺍﺩ ﻫﻮ ﻃﺒﺎﻋﺔ ﺍﻷﻋﺪﺍﺩ ﻋﻠﻰ ﺍﻟﺸﺎﺷﺔ ﻭ ﺍﺳﺘﻌﻤﺎﻝ ﻣﺆﺛﺮﺍﺕ ﻋﻠﻴﻬﺎ ﻣﺜﻞ ﺍﳉﻤﻊ ،ﺍﻟﻄﺮﺡ ،ﺍﻟﻘﺴﻤﺔ ﻭ ﺍﻟﻀﺮﺏ، ﻭ ﺳﻨﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻷﻋﺪﺍﺩ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺪﺍﻟﺔ ،printfﻭ ﺭﲟﺎ ﺗﻘﻮﻝ ﺃﻥ ﺍﻷﻣﺮ ﺳﻬﻞ ﻓﻘﻂ ﻧﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﺍﻷﻋﺪﺍﺩ ﺍﻟـﱵ ﻧﺮﻳـﺪﻫﺎ ﺩﺍﺧﻞ ﺍﻻﻗﺘﺒﺎﺳﺎﺕ ﰲ ﺍﻟﺪﺍﻟﺔ ،printfﺻﺤﻴﺢ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺗﻠﻚ ﺍﻟﻄﺮﻳﻘﺔ ﻭ ﻟﻜﻦ ﺍﳌﺘﺮﺟﻢ ﻫﻨﺎ ﺳﻴﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻷﻋﺪﺍﺩ ﻋﻠﻰ ﺃﺎ ﻧﺺ ﺛﺎﺑﺖ ﻭ ﻟﻴﺴﺖ ﺃﻋﺪﺍﺩ ،ﻫﺬﻩ ﺍﳊﺎﻟﺔ ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﻋﻤﻠﻴﺎﺕ ﺭﻳﺎﺿﻴﺔ ﻋﻠﻴﻬﺎ. ﰲ ﻟﻐﺔ Cﻟﻜﻞ ﻧﻮﻉ ﻣﻦ ﺍﻷﻋﺪﺍﺩ ﺭﻣﺰ ﻟﺘﻌﺎﻣﻞ ﻣﻌﻪ ،ﻣﺜﻼ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ﻳﺘﻢ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻌﻬﺎ ﺑﺎﻻﺳﺘﻌﻤﺎﻝ ﺍﻟﺮﻣـﺰ %dﺃﻭ ،%i ﺍﻟﺮﻣﺰ ﺍﻷﻭﻝ ﳐﺘﺼﺮ ﻣﻦ Decimalﻭ ﺍﻟﺮﻣﺰ ﺍﻟﺜﺎﱐ ﳐﺘﺼﺮ ﻣﻦ ،Integerﻫﺬﺍ ﺑﺎﻟﻨﺴﺒﺔ ﻟﻸﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺢ ،ﺃﻣﺎ ﺍﻷﻋﺪﺍﺩ ﺍﳊﻘﻴﻘﻴـﺔ ﻓﻴﺘﻢ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻌﻬﺎ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺮﻣﺰ ،%fﻭ ﺍﳊﺮﻑ fﳐﺘﺼﺮ ﻣﻦ ،floatﻭ ﺃﻳﻀﺎ ﺗﻮﺟﺪ ﺭﻣﻮﺯ ﺃﺧﺮﻯ ﺧﺎﺻﺔ ﺑﺎﻟﺘﻌﺎﻣﻞ ﻣﻊ ﻛﻞ ﻣﻦ ﺍﳊﺮﻭﻑ ﻭ ﺍﻟﻨﺼﻮﺹ ،ﺳﻨﺘﻄﺮﻕ ﺇﻟﻴﻬﺎ ﻓﻴﻤﺎ ﺑﻌﺪ. ﻧﺬﻫﺐ ﺇﱃ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ،ﻟﻜﺘﺎﺑﺔ ﻋﺪﺩ ﻣﻦ ﻧﻮﻉ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ﻧﻜﺘﺐ ﻛﻤﺎ ﻳﻠﻲ:
30
>#include<stdio.h
ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٣ﻃﺒﺎﻋﺔ ﻋﺪﺩ ﺻﺤﻴﺢ
)(main { ;)printf("%d", 20 }
1 2 3 4 5 6
ﻫﻨﺎ ﻭﺿﻌﻨﺎ ﺭﻣﺰ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ﺩﺍﺧﻞ ﺍﻟﺪﺍﻟﺔ printfﻭ ﺑﲔ ﺍﻻﻗﺘﺒﺎﺳﻴﲔ ،ﻭ ﺑﻌﺪ ﺍﻻﻗﺘﺒﺎﺳﻴﲔ ﻧﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﺍﻟﻌﺪﺩ ﺍﳌـﺮﺍﺩ ﻃﺒﻌﻪ ،ﻭ ﺍﳊﺮﺹ ﻋﻠﻰ ﺃﻥ ﻳﻜﻮﻥ ﺑﲔ ﺍﻻﻗﺘﺒﺎﺳﻴﲔ ﻭ ﺍﻟﻌﺪﺩ ﻓﺎﺻﻠﺔ ،ﻭ ﺬﻩ ﺍﻟﻄﺮﻳﻘﺔ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﻋﻤﻠﻴﺎﺕ ﻣﺜﻞ ﺍﳉﻤﻊ ﻣﺜﻼ ﻭ ﺫﻟﻚ ﺑﺈﺿﺎﻓﺔ ﻣﺆﺛﺮ ﺍﳉﻤﻊ ﻣﻊ ﺍﻟﻌﺪﺩ ﺍﳌﺮﺍﺩ ﺍﳉﻤﻊ ﻣﻌﻪ ﻣﺜﻞ ﻣﺎ ﻫﻮ ﻣﻮﺿﺢ ﰲ ﺍﳌﺜﺎﻝ ﺍﻟﺘﺎﱄ: >#include<stdio.h
ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٤ﺍﺳﺘﻌﻤﺎﻝ ﺍﳉﻤﻊ
)(main { ;)printf("%d", 20+5 }
1 2 3 4 5 6
ﻭ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺑﺎﻗﻲ ﺍﳌﺆﺛﺮﺍﺕ ﻣﺜﻞ ﺍﻟﻄﺮﺡ ،ﺍﻟﻘﺴﻤﺔ ﻭ ﺍﻟﻀﺮﺏ ﺑﻨﻔﺲ ﺍﻟﻄﺮﻳﻘﺔ .ﻭ ﳝﻜﻦ ﺇﻇﻬﺎﺭ ﺃﻛﺜﺮ ﻣﻦ ﺭﻗـﻢ ﻭ ﺫﻟـﻚ ﺑﺰﻳﺎﺩﺓ ﺍﻟﺮﻣﺰ %dﻣﻊ ﻓﺼﻠﻪ ﻣﻦ ﺍﻟﺮﻣﺰ ﺍﻟﺴﺎﺑﻖ ﺣﱴ ﺗﻜﻮﻥ ﺍﻷﺭﻗﺎﻡ ﻭﺍﺿﺤﺔ ﻣﺜﻞ ﻣﺎ ﻳﻠﻲ: >#include<stdio.h )(main { ;)printf("%d %d", 20+5, 87 }
ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٥ﻃﺒﻊ ﻋﺪﺩﻳﻦ
1 2 3 4 5 6
ﻛﻠﻤﺎ ﻧﻈﻴﻒ ﺭﻣﺰ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ﻧﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﺍﻟﺮﻗﻢ ﺍﻹﺿﺎﰲ ﺑﻌﺪ ﺍﻟﺮﻗﻢ ﺍﻟﺴﺎﺑﻖ ﻭ ﻧﻔﺼﻠﻬﻤﺎ ﺑﻔﺎﺻﻠﺔ ،ﳝﻜـﻦ ﺍﺳـﺘﻌﻤﺎﻝ ﺃﻛﺜﺮ ﻣﻦ ﻋﺪﺩﻳﻦ ﻭ ﺑﻄﺮﻳﻘﺔ ﻣﻨﻈﻤﺔ ﻓﻤﺜﻼ ﺇﺫﺍ ﺃﺭﺩﻧﺎ ﺃﻥ ﻧﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﻋﻤﻠﻴﺔ ﺍﳉﻤﻊ ﻓﺴﻨﻜﺘﺐ ﻛﻤﺎ ﻳﻠﻲ: >#include<stdio.h )(main { ;)printf("%d + %d = %d\n", 20, 5, 20+5 }
ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٦ﻋﻤﻠﻴﺔ ﲨﻊ
1 2 3 4 5 6
31
ﻭ ﻧﻔﺲ ﺍﻟﻄﺮﻳﻘﺔ ﻣﻊ ﺍﻷﻋﺪﺍﺩ ﺍﳊﻘﻴﻘﻴﺔ ﻓﻘﻂ ﻧﺴﺘﻌﻤﻞ ﺍﻟﺮﻣﺰ %fﺑﺪﻝ ﺍﻟﺮﻣﺰ .%dﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﻟﻜﻴﻔﻴﺔ ﺍﺳﺘﻌﻤﺎﳍﺎ: >#include<stdio.h )(main { ;)printf("%f + %f = %f\n", 1.0, 2.14, 1.0+2.14 }
ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٧ﲨﻊ ﻭ ﺇﻇﻬﺎﺭ ﺃﻋﺪﺍﺩ ﺣﻘﻴﻘﻴﺔ
1 2 3 4 5 6
ﻣﻼﺣﻈﺔ: ﰲ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻘﺔ ﻭﺿﻌﻨﺎ ﺍﻟﻨﻘﻄﺔ ﰲ ﻣﻜﺎﻥ ﺍﻟﻔﺎﺻﻠﺔ ،ﻫﻜﺬﺍ ﻛﻲ ﳝﻴﺰ ﺍﳌﺘﺮﺟﻢ ﻋﻠﻰ ﺃﺎ ﻗﻴﻢ ﻟﻸﻋﺪﺍﺩ ﺣﻘﻴﻘﻴﺔ ﺃﻱ ﺃﺎ ﺃﻋﺪﺍﺩ ﳍﺎ ﻓﻮﺍﺻﻞ ،ﺃﻣﺎ ﺇﺫﺍ ﻭﺿﻌﺖ ﺍﻟﻔﺎﺻﻠﺔ ﰲ ﻣﻜﺎﻥ ﺍﻟﻨﻘﻄﺔ ﻓﺴﻴﻌﺘﱪﻫﺎ ﺍﳌﺘﺮﺟﻢ ﻣﻨﻔﺼﻠﺔ ﻋﻦ ﺍﻷﺧﺮﻯ ﻭ ﻫﻜﺬﺍ ﺳـﺘﻨﺠﻢ ﺃﺧﻄـﺎﺀ ﻛﺜﲑﺓ ،ﻭ ﺗﺬﻛﺮ ﺃﻥ ﺍﻟﻔﺎﺻﻠﺔ ﺗﺴﺘﻌﻤﻞ ﰲ ﻓﺼﻞ ﻭﺳﺎﺋﻂ ﺩﺍﻟﺔ. ﺃﻣﺎ ﺭﻣﻮﺯ ﻃﺒﻊ ﺍﻷﺣﺮﻑ ﻭ ﺍﻟﻨﺼﻮﺹ ﻓﻄﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﳍﺎ ﻣﺜﻞ ﺍﻟﻄﺮﻕ ﺍﻟﺴﺎﺑﻘﺔ ﻓﻘـﻂ ﺑـﺪﻝ ﺍﻟﺮﻣـﺰﻳﻦ %dﻭ %fﻧـﻀﻊ %c ﻟﻸﺣﺮﻑ ،ﺣﻴﺚ ﺣﺮﻑ cﳐﺘﺼﺮ ﻣﻦ characterﻭ ﻧﻀﻊ ﺍﻟﺮﻣﺰ %sﻟﻠﻨﺼﻮﺹ ،ﻭ ﺍﳊﺮﻑ sﳐﺘﺼﺮ ﻣﻦ Stringﺃﻱ ﺳﻠـﺴﻠﺔ ﺣﺮﻭﻑ .ﺑﺎﻟﻨﺴﺒﺔ ﻟﻠﺤﺮﻭﻑ ﻓﻬﺬﺍ ﻣﺜﺎﻝ ﻳﻮﺿﺢ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﳍﺎ: >#include<stdio.h
ﻭ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﻫﺬﺍ ﺍﳌﺜﺎﻝ ﺃﻳﻀﺎ:
ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٨ﻃﺒﺎﻋﺔ ﺣﺮﻑ
ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٩ﻃﺒﺎﻋﺔ ﺣﺮﻑ )(٢ ﻫﻨﺎ ﺳﻴﻄﺒﻊ ﺍﻟﱪﻧﺎﻣﺞ ﺍﳊﺮﻑ ،aﻭ ﰲ ﺣﺎﻟﺔ ﺃﺭﺩﻧﺎ ﻃﺒﻊ ﻧﺺ ﻧﻜﺘﺐ ﻛﻤﺎ ﻳﻠﻲ:
)(main { ;)"printf("%c", "a }
1 2 3 4 5 6
>#include<stdio.h
1 2 3 4 5 6
>#include<stdio.h
1 2 3 4
)(main { ;)'printf("%c", 'a }
)(main {
32 5 6
;)"!printf("%s\n", "Hello, World }
ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٢٠ﻃﺒﺎﻋﺔ ﻧﺺ ﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﻛﺘﺎﺑﺔ ﻛﻞ ﻛﻠﻤﺔ ﺃﻭ ﺣﺮﻑ ﰲ ﺇﻗﺘﺒﺎﺳﲔ ﻣﺜﻞ:
1 2 3 4 5 6
>#include<stdio.h )(main { ;)"printf("%s", "Hello, " "\n" "World }
ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٢١ﻃﺒﺎﻋﺔ ﻧﺺ )(٢ ﻭ ﺗﻮﺟﺪ ﺭﻣﻮﺯ ﺃﺧﺮﻯ ﻣﻨﻬﺎ ﻣﻦ ﻫﻲ ﺧﺎﺻﺔ ﺑﺄﺭﻗﺎﻡ ﺍﻟﻨﻈﺎﻡ ﺍﻟﺴﺪﺍﺳﻲ ﻋﺸﺮ ﻭ ﺍﻟﱵ ﻳﻜﻮﻥ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻌﻬﺎ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺮﻣﺰ %xﺃﻭ %Xﺣﻴﺚ ﺗﺒﺪﺃ ﻣﻦ 0xﺃﻭ ،0Xﻣﺜﻼ ﺍﻟﺮﻗﻢ ،0x000Fﻭ ﺍﻟﺮﻣﺰ %oﻷﻋﺪﺍﺩ ﺍﻟﻨﻈﺎﻡ ﺍﻟﺜﻤﺎﱐ ،ﻭ ﺭﻣﻮﺯ ﺃﺧـﺮﻯ ﺳـﻨﻌﺮﻓﻬﺎ ﰲ ﺍﻟﺪﺭﻭﺱ ﺍﻟﻘﺎﺩﻣﺔ. ١,٢,٢ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ: .١ﰲ ﻟﻐﺔ Cﺍﳌﺘﺮﲨﺎﺕ ﺗﻔﺮﻕ ﺑﲔ ﺍﳊﺮﻭﻑ ﺍﻟﻜﺒﲑﺓ ﻭ ﺍﳊﺮﻭﻑ ﺍﻟﺼﻐﲑﺓ ،ﻣﺜﻼ ﺍﻟﺪﺍﻟﺔ mainﻻ ﳝﻜﻦ ﻛﺘﺎﺑﺘﻬﺎ Mainﺃﻭ .MAIN .٢ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ printfﺃﻭ ﺩﻭﺍﻝ ﺃﺧﺮﻯ ﺧﺎﺭﺝ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ،mainﻣﺜﻼ ﻻ ﳝﻜﻦ ﻛﺘﺎﺑﺔ: >#include<stdio.h ;)"printf("Hello, World!\n )(main {
ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٢٢ﺍﳋﻄﺄ ١
}
1 2 3 4 5 6 7 8
ﺇﻻ ﰲ ﺣﺎﻟﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺩﻭﺍﻝ ﺎ ﺩﻭﺍﻝ ﺃﺧﺮﻯ ﰒ ﺭﺑﻄﺘﻬﺎ ﺑﺎﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ،ﺳﻨﺘﻌﺮﻑ ﻋﻠﻰ ﺫﻟﻚ ﰲ ﺍﻟﺪﺭﻭﺱ ﺍﻟﻘﺎﺩﻣﺔ. .٣ﻛﺜﲑﺍ ﻣﺎ ﻳﺘﻢ ﻧﺴﻴﺎﻥ ﺍﻟﻔﺎﺻﻠﺔ ﺍﳌﻨﻘﻮﻃﺔ ،ﻭ ﺇﻥ ﰎ ﻧﺴﻴﺎﺎ ﻻ ﳝﻜﻦ ﺇﻧﺸﺎﺀ ﺍﳌﻠﻒ ﺍﻟﺘﻨﻔﻴﺬﻱ ﻟﻠﱪﻧﺎﻣﺞ ﺣﱴ ﻳﺘﻢ ﺗـﺼﺤﻴﺢ ﺍﳋﻄﺄ.
33
.٤ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﻔﺎﺻﻠﺔ ﺍﳌﻨﻘﻮﻃﺔ ﰲ ﺎﻳﺔ ﺳﻄﺮ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ )( ،mainﻭ ﺳﺒﺐ ﺫﻟﻚ ﻫﻮ ﻋﻨﺪﻣﺎ ﻳﺘﻢ ﺍﻹﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ ﻭ ﺇﻋﻄﺎﺀﻫﺎ ﺃﻭﺍﻣﺮ ﻻ ﳚﺐ ﺃﻥ ﻧﻜﺘﺐ ﺍﻟﻔﺎﺻﻠﺔ ﺍﳌﻨﻘﻮﻃﺔ ،ﻟﻴﺴﺖ ﻣﺜﻞ ﺩﻭﺍﻝ ﻣﻌﺮﻓﺔ ﺳـﺎﺑﻘﺎ ﻣﺜـﻞ ﺍﻟﺪﺍﻟـﺔ .printf .٥ﰲ ﺩﺍﻟﺔ ﺍﻟﻄﺒﻊ ،printfﺇﻥ ﻛﺘﺒﻨﺎ ﺍﻟﻨﺺ ﺍﳌﺮﺍﺩ ﻃﺒﻌﻪ ﺑﺪﻭﻥ ﺭﻣﻮﺯ ﺍﻻﻗﺘﺒﺎﺱ " " ﻓﺈﻥ ﺍﳌﺘﺮﺟﻢ ﺳﻴﻨﺒﻬﻚ ﻋﻦ ﻭﺟـﻮﺩ ﺧﻄﺄ. ١,٢,٣ﲤﺎﺭﻳﻦ: .١ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﺍﳉﻤﻠﺔ ! Hello, Worldﻣﺮﺗﲔ ،ﺍﻷﻭﱃ ﰲ ﺳﻄﺮ ﻭ ﺍﻟﺜﺎﻧﻴﺔ ﰲ ﺳﻄﺮ ﺁﺧﺮ. .٢ .٣ .٤ .٥
ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﺍﳉﻤﻠﺔ ! ،Hello, Worldﻛﻞ ﺣﺮﻑ ﰲ ﺳﻄﺮ. ﻫﻞ ﳝﻜﻦ ﺗﻐﲑ ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ mainﺇﱃ ﺍﺳﻢ ﻣﻦ ﺍﺧﺘﻴﺎﺭﻧﺎ؟ ﻫﻞ ﳝﻜﻦ ﺍﻻﺳﺘﻐﻨﺎﺀ ﻋﻦ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ main؟ ﻫﻞ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ﺃﻛﺜﺮ ﻣﻦ ﻣﺮﺓ؟
.٦ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﻄﺒﻊ ﻧﺘﻴﺠﺔ ﻃﺮﺡ ﺍﻟﻌﺪﺩ ٢ﻣﻦ .٣,٥ .٧ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﺍﻟﻜﻠﻤﺔ Helloﺑﺎﺳﺘﺨﺪﺍﻡ ﺭﻣﻮﺯ ﺍﻷﺣﺮﻑ ).(%c .٨ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﻧﺼﻴﲔ ﺑﺎﺳﺘﻌﻤﺎﻝ ﺍﻟﺮﻣﺰ ﺍﳋﺎﺹ ﺑﻄﺒﻊ ﺍﻟﻨﺼﻮﺹ ﻣﺮﺗﲔ ).(%s%s
34
ﺍﳌﺘﻐﲑﺍﺕ ﻫﻲ ﳎﻤﻮﻋﺔ ﻣﻦ ﺍﻟﺒﺎﻳﺘﺎﺕ ﻳﺘﻢ ﺣﺠﺰﻫﺎ ﰲ ﺍﻟﺬﺍﻛﺮﺓ ﺍﻟﻌﺸﻮﺍﺋﻴﺔ Random Access Memoryﺃﻱ ،RAMﺣﻴﺚ ﻳﺘﻢ ﻭﺿﻊ ﻗِﻴﻢ ﻣﺘﻐﲑﺓ ﰲ ﺗﻠﻚ ﺍﻟﺒﺎﻳﺘﺎﺕ ﺍﶈﺠﻮﺯﺓ ،ﳝﻜﻦ ﺍﺳﺘﺮﺟﺎﻋﻬﺎ ﰲ ﺃﻱ ﻭﻗﺖ .ﻛﻞ ﺑﺎﻳﺖ ﻳﺘﻢ ﺍﻟﻮﺻﻮﻝ ﺇﻟﻴﻬﺎ ﻋﱪ ﻋﻨﻮﺍﻥ. ﻭ ﺗﻔﻘﺪ ﻫﺬﻩ ﺍﻟﺬﺍﻛﺮﺓ ﲨﻴﻊ ﺑﻴﺎﻧﺎﺎ ﻋﻨﺪ ﻗﻄﻊ ﺍﻟﺘﻴﺎﺭ .ﺍﻟـ RAMﻋﺒﺎﺭﺓ ﻋﻦ ﺭﻗﺎﻗﺔ Chipﲢﺘﻮﻱ ﻋﻠﻰ ﻋﺪﺩ ﻣﻦ ﺍﻟﺘﺮﺍﻧﺰﺳﺘﻮﺭﺍﺕ Transistorsﻭ ﺍﳌﻜﺜﻔﺎﺕ Capacitorﺗﻘﺪﺭ ﺑﺎﳌﻼﻳﲔ ،ﺣﻴﺚ ﻭﺍﺣﺪ ﺗﺮﺍﻧﺰﺳﺘﻮﺭ ﻭ ﻣﻜﺜﻒ ﻳﺸﻜﻼﻥ ﻭﺣـﺪﺓ ﺫﺍﻛـﺮﺓ ﺗﻘـﺪﺭ ﺑﺎﻟـﺒﺖ ،Bitﳛﻞ ﻫﺬﺍ ﺍﻟﺒﺖ ﺇﻣﺎ ﺍﻟﻘﻴﻤﺔ ٠ﺃﻭ ﺍﻟﻘﻴﻤﺔ ،١ﺣﻴﺚ ٨ﺑﺘﺎﺕ ﺗﺸﻜﻞ ﻭﺍﺣﺪ ﺑﺎﻳﺖ ،Byteﻭ ﻛﻞ ﺑﻴﺎﺕ ﻣﻦ ﻫـﺬﻩ ﺍﻟﺬﺍﻛﺮﺓ ﳝﺜﻞ ﺑﻌﻨﻮﺍﻥ)ﻳﺘﻢ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﻫﺬﻩ ﺍﻟﻌﻨﺎﻭﻳﻦ ﺑﺎﻟﻨﻈﺎﻡ ﺍﻟﺴﺪﺍﺳﻲ ﺍﻟﻌﺸﺮ( ﳝﻜﻦ ﺍﻟﻮﺻﻮﻝ ﺇﻟﻴﻪ ﻭ ﺍﻟﺘﻐﲑ ﰲ ﳏﺘﻮﺍﻩ ،ﳑﺎ ﻧﻔﻬﻢ ﺃﻥ ﺍﻟﺬﺍﻛﺮﺓ ﻋﺒﺎﺭﺓ ﻋﻦ ﻋﻨﺎﻭﻳﻦ ﻣﺘﺴﻠﺴﻠﺔ ،ﻟﻜﻞ ﻋﻨﻮﺍﻥ ﻗﻴﻤﺔ ﻣﺘﻐﲑﺓ .ﺻﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ:
ﺍﻟﺸﻜﻞ :١,٣,١ﺍﻟﺬﺍﻛﺮﺓ ﻭ ﺍﻟﻌﻨﺎﻭﻳﻦ ﰲ ﺍﻟﻨﻤﻂ ﺍﳊﻘﻴﻘﻲ
real mode
ﰲ ﻟﻐﺔ Cﻳﻮﺟﺪ ﻋﺪﺕ ﺃﻧﻮﺍﻉ ﻣﻦ ﺍﳌﺘﻐﲑﺍﺕ ﻭ ﺍﻟﺜﻮﺍﺑﺖ ،ﻣﻨﻬﺎ ﻣﺘﻐﲑﺍﺕ ﺧﺎﺹ ﺑﺎﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺢ ﻭ ﺃﺧﺮﻯ ﺑﺎﻷﻋﺪﺍﺩ ﺍﳊﻘﻴﻘﻴﺔ ﻭ ﺃﺧﺮﻯ ﺑﺎﻷﺣﺮﻑ ﻭ ،...ﻭ ﺩﺍﺋﻤﺎ ﻧﻘﻮﻡ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﺍﳌﺘﻐﲑﺍﺕ ﻭ ﺍﻟﺜﻮﺍﺑﺖ ﻗﺒﻞ ﺍﺳﺘﻌﻤﺎﳍﺎ)ﻭ ﻛﺄﻧﻚ ﲢﺠﺰ ﻣﻜﺎﻧـﺎ ﺃﻭﻻ ﰒ ﺗﻘﻮﻡ ﺑﺎﳉﻠﻮﺱ )ﺃﻱ ﻭﺿﻊ ﻗﻴﻤﺔ(( .ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻫﻲ ﻛﺘﺎﺑﺔ ﻧﻮﻉ ﺍﳌﺘﻐﲑ ﰒ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ﰒ ﺍﻟﻘﻴﻤﺔ ﺍﻟﱵ ﺳـﻴﺤﺘﻮﻳﻬﺎ )ﻫﺬﺍ ﰲ ﺣﺎﻟﺔ ﺇﻋﻄﺎﺀﻩ ﻗﻴﻤﺔ ﻣﺒﺎﺷﺮﺓ( ﺍﳌﺘﻐﲑ ،ﺻﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ:
35
ﺍﻟﺸﻜﻞ :١,٣,٢ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ
١,٣,١ﻧﻮﻉ ﺍﳌﺘﻐﲑ :Variable Type
ﻛﻤﺎ ﻗﻠﻨﺎ ﺳﺎﺑﻘﺎ ،ﺗﻮﺟﺪ ﻋﺪﺓ ﺃﻧﻮﺍﻉ ﻟﻠﻤﺘﻐﲑﺍﺕ ،ﻭ ﻟﻜﻦ ﺍﻟﺬﻱ ﳚﺐ ﺃﻥ ﻧﻌﺮﻓﻪ ﻫﻮ ﺃﻥ ﺗﻠﻚ ﺍﻷﻧﻮﺍﻉ ﻻ ﲣﺘﻠﻒ ﻋﻦ ﺑﻌﻀﻬﺎ ﺇﻻ ﰲ ﺍﳊﺠﻢ ،ﻭ ﻫﺬﺍ ﻳﻌﲏ ﻟﻮ ﺃﻋﻠﻨﺎ ﻋﻦ ﻣﺘﻐﲑ ﻷﻋﺪﺍﺩ ﺻﺤﻴﺢ ﳝﻜﻨﻨﺎ ﺃﻥ ﻧﻌﻄﻴﻪ ﺣﺮﻓﺎ ﺑﺪﻝ ﻣﻦ ﻗﻴﻤﺔ ﺻﺤﻴﺢ ،ﻭ ﻋﻜـﺲ .ﻭ ﺗﻮﺟﺪ ﺣﺎﻟﺔ ﺧﺎﺻﺔ ﻫﻨﺎ ﻭ ﻫﻲ ﺍﻷﻋﺪﺍﺩ ﺍﳊﻘﻴﻘﻴﺔ ﻷﺎ ﻟﻴﺴﺖ ﻛﻐﲑﻫﺎ .ﺃﻧﻮﺍﻉ ﺍﳌﺘﻐﲑﺍﺕ ﻫﻲ: ١,٣,١,١ﻣﺘﻐﲑ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ :int
ﻧﻘﻮﻡ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ﺑﻜﺘﺎﺑﺔ ﺍﻟﻜﻠﻤﺔ intﰲ ﻣﻜﺎﻥ ،Variable_Typeﺣﻴﺚ ﻳﺄﺧﺬ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ Integerﻣﺴﺎﺣﺔ ﻗﺪﺭﻫﺎ ٢ﺑﺎﻳﺖ ﻭ ﺍﻟﱵ ﺗﺴﺎﻭﻱ ١٦ﺑﺖ ﻭ ﺗﺴﺎﻭﻱ ٦٥٥٣٦ﺍﺣﺘﻤﺎﻝ ،ﺃﻱ ﺃﻥ ﺃﻗﺼﻰ ﻗﻴﻤﺔ ﳝﻜﻦ ﺃﻥ ﳛﻤﻠﻬﺎ ﺍﳌﺘﻐﲑ ﻫﻲ ،٦٥٥٣٥ﺍﺑﺘﺪﺍﺀ ﻣﻦ ﺍﻟﺼﻔﺮ ،ﺃﻭ ﺍﺑﺘﺪﺍﺀ ﻣﻦ -٣٢،٧٦٨ﺇﱃ ٣٢،٧٦٧ﰲ ﺣﺎﻟـﺔ ﺿـﻢ ﺍﻷﻋـﺪﺍﺩ ﺍﻟﺴﺎﻟﺒﺔ .ﻭ ﳝﻜﻦ ﺃﻥ ﻳﻜﻮﻥ ﺣﺠﻤﻬﺎ ٤ﺑﺎﻳﺖ )ﺣﺴﺐ ﺍﳌﺘﺮﺟﻢ ﻭ ﳕﻄﻪ( ﺃﻱ ﺗﺴﺎﻭﻱ ٣٢ﺑﺖ ،ﺣﻴﺚ ﺃﻗﺼﻰ ﻗﻴﻤﺔ ﳝﻜـﻦ ﺃﻥ ﲢﻤﻠﻬﺎ ﻫﻲ ،٤٢٩٤٩٦٧٢٩٦ﺍﺑﺘﺪﺍﺀ ﻣﻦ ﺍﻟﺼﻔﺮ)ﰲ ﺣﺎﻟﺔ ﺃﻥ ﺍﳌﺘﻐﲑ ﻻ ﳛﺘﻮﻱ ﺇﻻ ﻋﻠﻰ ﻗﻴﻢ ﻣﻮﺟﺒﺔ( .ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;int Variable_Name = 0 }
ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﻋﺪﺩ ﺻﺤﻴﺢ
1 2 3 4 5 6
١,٣,١,٢ﻣﺘﻐﲑ ﺍﻷﻋﺪﺍﺩ ﺍﳊﻘﻴﻘﻴﺔ :float
ﺍﻷﻋﺪﺍﺩ ﺍﳊﻘﻴﻘﻴﺔ ﻫﻲ ﺍﻷﻋﺪﺍﺩ ﺍﻟﱵ ﳍﺎ ﻓﻮﺍﺻﻞ ،ﻭ ﻳﺘﻢ ﺍﻹﻋﻼﻥ ﻋﻨﻬﺎ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﻜﻠﻤﺔ ،floatﺣﺠﻤﻬﺎ ٤ﺑﺎﻳﺖ ،ﺣﻴﺚ ﺗﺒﺪﺃ ﻣﻦ 1.2E-38ﺇﱃ .3.4E+38ﻣﺜﺎﻝ: >#include<stdio.h )(main {
1 2 3 4
36 ;float Variable_Name = 0.0
ﺍﻟﱪﻧﺎﻣﺞ :١,٣,٢ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﻋﺪﺩ ﺣﻘﻴﻘﻲ
}
5 6
١,٣,١,٣ﻣﺘﻐﲑ ﺍﻷﻋﺪﺍﺩ ﺍﳊﻘﻴﻘﻴﺔ :double
doubleﻫﻲ ﺿﻌﻒ ،floatﻭ ﻳﺘﻢ ﺍﻹﻋﻼﻥ ﻋﻨﻬﺎ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﻜﻠﻤﺔ ،doubleﺣﻴﺚ ﺣﺠﻤﻬﺎ ٨ﺑﺎﻳﺖ ﻭ ﺗﺒﺪﺃ ﻣـﻦ 2.3E-308ﺇﱃ .1.7E+308ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;double Variable_Name = 0.0 }
ﺍﻟﱪﻧﺎﻣﺞ :١,٣,٣ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﻋﺪﺩ ﺣﻘﻴﻘﻲ )(٢
1 2 3 4 5 6
١,٣,١,٤ﻣﺘﻐﲑ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ :short
ﻫﻮ ﺃﻳﻀﺎ ﻣﻦ ﻣﺘﻐﲑﺍﺕ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ﺣﻴﺚ ﻧﻘﻮﻡ ﺑﺎﻹﻋﻼﻥ ﻋﻨﻪ ﺑﻜﺘﺎﺑﺔ ﺍﻟﻜﻠﻤﺔ shortﰲ ﻣﻜـﺎﻥ ،Variable_Type ﺣﺠﻤﻪ ٢ﺑﺎﻳﺖ ﻭ ﺍﻟﱵ ﺗﺴﺎﻭﻱ ١٦ﺑﺖ ﻭ ﺗﺴﺎﻭﻱ ٦٥٥٣٦ﺍﺣﺘﻤﺎﻝ ،ﺃﻱ ﺃﻥ ﺃﻗﺼﻰ ﻗﻴﻤﺔ ﳝﻜﻦ ﺃﻥ ﳛﻤﻠﻬﺎ ﺍﳌـﺘﻐﲑ ﻫـﻲ ٦٥٥٣٥ﺍﺑﺘﺪﺍﺀ ﻣﻦ ﺍﻟﺼﻔﺮ ،ﺃﻭ ﺍﺑﺘﺪﺍﺀ ﻣﻦ -٣٢،٧٦٨ﺇﱃ ٣٢،٧٦٧ﰲ ﺣﺎﻟﺔ ﺿﻢ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺴﺎﻟﺒﺔ .ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;short Variable_Name = 0 }
ﺍﻟﱪﻧﺎﻣﺞ :١,٣,٤ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﻋﺪﺩ ﺻﺤﻴﺢ )(٢
1 2 3 4 5 6
١,٣,١,٥ﻣﺘﻐﲑ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ :long
ﻫﻮ ﺃﻳﻀﺎ ﻣﻦ ﻣﺘﻐﲑﺍﺕ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ﺣﻴﺚ ﻧﻘﻮﻡ ﺑﺎﻹﻋﻼﻥ ﻋﻨﻪ ﺑﻜﺘﺎﺑﺔ ﺍﻟﻜﻠﻤﺔ longﰲ ﻣﻜـﺎﻥ ،Variable_Type ﺣﺠﻤﻪ ٤ﺑﺎﻳﺖ ﺃﻱ ﻳﺴﺎﻭﻱ ٣٢ﺑﺖ ،ﺣﻴﺚ ﺃﻗﺼﻰ ﻗﻴﻤﺔ ﳝﻜﻦ ﺃﻥ ﳛﻤﻠﻬﺎ ﻫﻲ ،٤٢٩٤٩٦٧٢٩٦ﺍﺑﺘﺪﺍﺀ ﻣﻦ ﺍﻟـﺼﻔﺮ)ﰲ ﺣﺎﻟﺔ ﺃﻥ ﺍﳌﺘﻐﲑ ﻻ ﳛﺘﻮﻱ ﺇﻻ ﻋﻠﻰ ﻗﻴﻢ ﻣﻮﺟﺒﺔ( .ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;long Variable_Name = 0 }
ﺍﻟﱪﻧﺎﻣﺞ :١,٣,٥ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﻋﺪﺩ ﺻﺤﻴﺢ )(٣
1 2 3 4 5 6
37
١,٣,١,٥ﻣﺘﻐﲑ ﺍﻟﺮﻣﻮﺯ :char
ﻣﻦ ﺃﺻﻐﺮ ﺍﳌﺘﻐﲑﺍﺕ ،ﻳﺘﻢ ﺍﻹﻋﻼﻥ ﻋﻨﻪ ﺑﻜﺘﺎﺑﺔ ﺍﻟﻜﻠﻤﺔ charﰲ ﻣﻜﺎﻥ ،Variable_Typeﺣﺠﻤﻪ ١ﺑﺎﻳـﺖ ﺃﻱ ٨ﺑـﺖ ﺣﻴﺚ ﳛﻤﻞ ٢٥٦ﺍﺣﺘﻤﺎﻝ ﺍﺑﺘﺪﺍﺀ ﻣﻦ ٠ﺇﱃ ٢٥٥ﺃﻭ ﻣﻦ -١٢٨ﺇﱃ ،١٢٧ﺣﻴﺚ ﻛﻞ ﺭﻗﻢ ﳝﺜﻞ ﺑﺮﻣﺰ ﰲ ﺟﺪﻭﻝ .ASCII ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;'char Variable_Name = 'A }
ﺍﻟﱪﻧﺎﻣﺞ :١,٣,٦ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﺣﺮﰲ
1 2 3 4 5 6
١,٣,٢ﺍﺳﻢ ﺍﳌﺘﻐﲑ :Variable Name
ﲢﺪﺛﻨﺎ ﺳﺎﺑﻘﺎ ﻋﻦ ﻋﻨﺎﻭﻳﻦ ،ﺗﻮﺟﺪ ﻣﻼﺣﻈﺔ ﻗﻮﻳﺔ ﻫﻨﺎ ﳚﺐ ﺍﻟﺘﻨﺒﻪ ﺎ ،ﻭ ﻫﻲ ﺃﻧﻨﺎ ﻧﺮﻯ ﺍﳌﺘﻐﲑﺍﺕ ﺃﲰﺎﺀ ،ﺃﻣﺎ ﺍﳉﻬـﺎﺯ ﻓـﲑﺍﻩ ﻋﻨﺎﻭﻳﻦ ،ﺍﻹﺳﻢ ﳎﺮﺩ ﺃﺩﺍﺓ ﺍﺳﺘﻌﻤﻠﺖ ﻟﺘﺴﻬﻴﻞ ﻋﻤﻠﻴﺔ ﺍﻟﻮﺻﻮﻝ ﺇﱃ ﺗﻠﻚ ﺍﻟﻌﻨﺎﻭﻳﻦ ﺑﺪﻭﻥ ﺍﻟﻠﺠﻮﺀ ﺇﱃ ﻋﻨﺎﻭﻳﻦ ،ﺇﳕﺎ ﺃﲰﺎﺀ ﻭﺍﺿﺤﺔ ﺗﻮﺿﺢ ﺳﺒﺐ ﺍﻹﻋﻼﻥ ﻋﻨﻬﺎ .ﻭ ﻻﺳﻢ ﺍﳌﺘﻐﲑ ﺣﺪﻭﺩ ﻻ ﳚﺐ ﲡﺎﻭﺯﻫﺎ ﻭ ﻫﻲ: § § § § § §
ﺃﻥ ﻻ ﻳﺘﺠﺎﻭﺯ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ﺃﻛﺜﺮ ﻣﻦ ٣١ﺣﺮﻑ. ﺃﻥ ﻻ ﻳﺒﺪﺃ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ﺑﺄﺭﻗﺎﻡ. ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ﳛﺘﻮﻱ ﻋﻠﻰ ﻣﺆﺛﺮﺍﺕ ﻣﺜﻞ ﺍﳉﻤﻊ ﻭ ﺍﻟﻄﺮﺡ ﻭ.... ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ﳛﺘﻮﻱ ﻋﻠﻰ ﺭﻣﻮﺯ ﻣﺜﻞ %ﻭ #ﻭ { ﻭ)...ﺑﺎﺳﺘﺜﻨﺎﺀ ﺍﻟﺮﻣﺰ _(. ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ﻣﺴﺘﻌﻤﻞ ﺳﺎﺑﻘﺎ ﰲ ﺩﺍﻟﺔ ﺃﻭ ﻣﺘﻐﲑ ﺁﺧﺮ. ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ﻣﻦ ﺃﲰﺎﺀ ﺍﻟﻜﻠﻤﺎﺕ ﺍﶈﺠﻮﺯﺓ.
١,٣,٣ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ :Variable Value ﳚﺐ ﻣﺮﺍﻋﺎﺓ ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ ﺣﺴﺐ ﻧﻮﻋﻪ ،ﻓﻤﺜﻼ ﻻ ﳝﻜﻦ ﺃﻥ ﻧﻌﻄﻲ ﻟﻠﻤﺘﻐﲑ intﻗﻴﻤﺔ ﻋﺪﺩ ﺣﻘﻴﻘﻲ .floatﻭ ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ ﳝﻜﻦ ﺃﻥ ﻧﻌﻄﻴﻬﺎ ﻟﻪ ﻣﺒﺎﺷﺮﺓ ﺑﻌﺪ ﺍﻹﻋﻼﻥ ﻋﻨﻪ ،ﺃﻭ ﻧﻘﻮﻡ ﺑﺎﻹﻋﻼﻥ ﻋﻨﻪ ﻭ ﻧﻀﻊ ﺑﻪ ﻗﻴﻤﺔ ﻓﻴﻤﺎ ﺑﻌﺪ)ﺃﻭ ﻧﻀﻊ ﺑﻪ ﻗﻴﻤﺔ ﺇﺳﺘﻘﺒﻠﻨﺎ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﻣﺜﻼ(. ١,٣,٤ﺃﻣﺜﻠﺔ ﺣﻮﻝ ﺍﳌﺘﻐﲑﺍﺕ:
38
ﺳﺄﻗﺪﻡ ﺃﻣﺜﻠﺔ ﳐﺘﻠﻔﺔ ﺣﻮﻝ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺍﳌﺘﻐﲑﺍﺕ ،ﻭ ﻧﺒﺪﺃ ﲟﺘﻐﲑﺍﺕ ﺃﻋﺪﺍﺩ ﺻﺤﻴﺤﺔ ﺣﻴﺚ ﻧﻘﻮﻡ ﺑﺈﻋﻼﻥ ﻋـﻦ ﻣـﺘﻐﲑ ﺑﺎﺳﻢ Varﻭ ﺑﻪ ﺍﻟﻘﻴﻤﺔ ،٥ﰒ ﻧﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻮﺟﻮﺩﺓ ﰲ ﺍﳌﺘﻐﲑ Varﻋﻠﻰ ﺍﻟﺸﺎﺷﺔ ،ﺍﳌﺜﺎﻝ: >#include<stdio.h )(main { ;int Var = 5 ;)printf("%d\n", Var }
ﺍﻟﱪﻧﺎﻣﺞ :١,٣,٧ﻃﺮﻳﻘﺔ ﻃﺒﺎﻋﺔ ﳏﺘﻮﻯ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﻋﺪﺩ ﺻﺤﻴﺢ
1 2 3 4 5 6 7 8
ﰲ ﻫﺬﺍ ﺍﳌﺜﺎﻝ ،ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﰎ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﺑﺎﺳﻢ Varﻭ ﻣﻦ ﻧﻮﻉ ) intﻋﺪﺩ ﺻﺤﻴﺢ( ﻭ ﺑﻪ ﺍﻟﻘﻴﻤـﺔ ،٥ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﺍﺳﺘﻌﻤﻠﻨﺎ ﺍﻟﺪﺍﻟﺔ printfﻟﻄﺒﺎﻋﺔ ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ ،Varﻭ ﺗﻮﺟﺪ ﻃﺮﻕ ﺃﺧﺮﻯ ﻹﻋﻄﺎﺀ ﻟﻠﻤﺘﻐﲑﺍﺕ ﻗﻴﻢ ،ﺳـﺄﻋﻄﻲ ﻃﺮﻳﻘﺘﲔ ،ﺍﻷﻭﱃ ﻫﻲ ﺍﻹﻋﻼﻥ ﻋﻦ ﺍﳌﺘﻐﲑ ﰲ ﺳﻄﺮ ﰒ ﺇﻋﻄﺎﺀﻩ ﻗﻴﻤﺔ ﰲ ﺳﻄﺮ ﺁﺧﺮ ﻣﺜﻞ: >#include<stdio.h )(main { ;int Var ;Var = 5 ;)printf("%d\n", Var
ﺍﻟﱪﻧﺎﻣﺞ :١,٣,٨ﻃﺮﻳﻘﺔ ﲢﺪﻳﺚ ﻗﻴﻤﺔ ﻣﺘﻐﲑ ﻭ ﻃﺒﻌﻬﺎ
}
1 2 3 4 5 6 7 8 9
ﻭ ﺍﻟﻄﺮﻳﻘﺔ ﺍﻟﺜﺎﻧﻴﺔ ﻫﻲ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑﻳﻦ ،ﺍﻷﻭﻝ ﺑﻪ ﺍﻟﻘﻴﻤﺔ ٥ﻭ ﺍﻟﺜﺎﱐ ﺑﻪ ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ ﺍﻷﻭﻝ ،ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;int Var_1 = 5 ;int Var_2 = Var_1 ;)printf("%d\n", Var_2
ﺍﻟﱪﻧﺎﻣﺞ :١,٣,٩ﻃﺮﻳﻘﺔ ﲢﺪﻳﺚ ﻗﻴﻤﺔ ﻣﺘﻐﲑ ﻣﻌﻄﺎﺓ ﻣﻦ ﻣﺘﻐﲑ ﺁﺧﺮ
}
1 2 3 4 5 6 7 8 9
ﻣﺜﺎﻝ ﺁﺧﺮ: >#include<stdio.h )(main
1 2 3
39 { ;int Num1, Num2, Num3 ;Num1 = 5 ;Num2 = 7 ;Num3 = Num1 + Num2 ;)printf("%d + %d = %d\n", Num1, Num2, Num3
ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٠ﻧﺎﺗﺞ ﲨﻊ ﺑﲔ ﻋﺪﺩﻳﻦ ﺻﺤﻴﲔ ﰲ ﻣﺘﻐﲑ
}
4 5 6 7 8 9 10 11
ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﰎ ﺍﻹﻋﻼﻥ ﻋﻦ ﺛﻼﺛﺔ ﻣﺘﻐﲑﺍﺕ ﰲ ﻧﻔﺲ ﺍﻟﺴﻄﺮ ﺣﻴﺚ ﻧﻘﻮﻡ ﺑﻔﺼﻞ ﺑﲔ ﺍﺳﻢ ﻣﺘﻐﲑ ﻭ ﺁﺧﺮ ﺑﻔﺎﺻﻠﺔ ،ﻭ ﻫﻨﺎ ﺳﺘﻜﻮﻥ ﲨﻴﻊ ﺍﳌﺘﻐﲑﺍﺕ ﻣﻦ ﻧﻮﻉ ﺃﻋﺪﺍﺩ ﺻﺤﻴﺤﺔ ) ،(intﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺩﺱ ﻭ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﺃﻋﻄﻴﻨﺎ ﻟﻠﻤـﺘﻐﲑ Num1 ﺍﻟﻘﻴﻤﺔ ٥ﻭ ﺍﳌﺘﻐﲑ Num2ﺍﻟﻘﻴﻤﺔ ،٧ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﺃﻋﻄﻴﻨﺎ ﻟﻠﻤﺘﻐﲑ Num3ﻧﺘﻴﺠﺔ ﺍﳉﻤﻊ ﺑﲔ ﺍﳌـﺘﻐﲑ Num1ﻭ ﺍﳌـﺘﻐﲑ ،Num2ﻭ ﺃﺧﲑﺍ ﺍﻟﺴﻄﺮ ﺍﻟﻌﺎﺷﺮ ﻭ ﺍﻟﺬﻱ ﻳﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﻧﺘﺎﺋﺞ ﺍﻟﱪﻧﺎﻣﺞ .ﻭ ﻧﻔﺲ ﺍﻟﻄﺮﻕ ﺍﻟﺴﺎﺑﻘﺔ ﳝﻜﻦ ﺇﺳﺘﻌﻤﺎﳍﺎ ﻣﻊ ﻣـﺘﻐﲑﺍﺕ ﻣﻦ ﻧﻮﻉ floatﻭ shortﻭ ،longﺃﻣﺎ ﺍﳌﺘﻐﲑ charﻓﻄﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻟﻪ ﻟﻴﺴﺖ ﳐﺘﻠﻔﺔ ﻛﺜﲑ ،ﺣﻴﺚ ﳝﻜﻨﻨﺎ ﺃﻳﻀﺎ ﺃﻥ ﻧﻌﻄﻴﻪ ﻋﺪﺩ ﺑﺪﻝ ﺍﳊﺮﻑ ﺣﻴﺚ ﻋﻨﺪ ﻃﺒﺎﻋﺘﻪ ﻻ ﻳﻄﺒﻊ ﻋﺪﺩﺍ ،ﺇﳕﺎ ﺍﳊﺮﻑ ﺍﻟﺬﻱ ﳛﻤﻞ ﺫﻟﻚ ﺍﻟﺮﻗﻢ ﰲ ﺟﺪﻭﻝ ،ASCIIﻭ ﻟﻜﻲ ﺗﻔﻬـﻢ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻝ ﻣﺘﻐﲑﺍﺕ ﻣﻦ ﻧﻮﻉ charﺇﻟﻴﻚ ﺍﳌﺜﺎﻝ ﺍﻟﺘﺎﱄ: >#include<stdio.h )(main { ;'char ch = 'a ;)printf("%c\n", ch
ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١١ﻃﺮﻳﻘﺔ ﻃﺒﺎﻋﺔ ﺣﺮﻑ ﻣﻮﺟﻮﺩ ﰲ ﻣﺘﻐﲑ ﺣﺮﰲ
ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﺃﻋﻄﲔ ﻟﻠﻤﺘﻐﲑ chﺍﳊﺮﻑ ﺍﻟﺬﻱ aﻣﻊ ﻣﺮﺍﻋﺎﺓ ﺃﻥ ﻳﻜﻮﻥ ﺩﺍﺧﻞ ﻟﻨﺎ ﺍﳊﺮﻑ aﻓﻬﻮ ﺍﻟﺮﻗﻢ ٩٧ﰲ ﺟﺪﻭﻝ ،ASCIIﻭ ﺳﻴﺼﺒﺢ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻘﺔ ﻛﻤﺎ ﻳﻠﻲ:
‘
}
1 2 3 4 5 6 7 8
‘ ،ﺃﻣﺎ ﺇﺫﺍ ﺃﺭﺩﻧﺎ ﺃﻥ ﻧﻌﻄﻴﻪ ﻋﺪﺩﺍ ﻳﻄﺒﻊ
>#include<stdio.h )(main { ;char ch = 97 ;)printf("%c\n", ch
ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٢ﻃﺮﻳﻘﺔ ﻃﺒﺎﻋﺔ ﺣﺮﻑ ﺑﺎﻹﻋﺘﻤﺎﺩ ﻋﻠﻰ ﺭﻗﻤﻪ ﰲ ﺟﺪﻭﻝ ﺃﺳﻜﻲ
}
1 2 3 4 5 6 7 8
ﻭ ﻛﻤﺎ ﻗﻠﻨﺎ ﺳﺎﺑﻘﺎ ﺃﻥ ﺃﻗﺼﻰ ﻗﻴﻤﺔ ﳝﻜﻦ ﺃﻥ ﳛﻤﻠﻬﺎ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ charﻫﻲ ٢٥٥ﺍﺑﺘﺪﺍﺀ ﻣﻦ ﺍﻟﺼﻔﺮ ،ﻭ ﻛﻞ ﺭﻗـﻢ ﳝﺜـﻞ ﺑﺮﻣﺰ.
40
١,٣,٥ﺍﻷﻋﺪﺍﺩ ﺍﳌﻮﺟﺒﺔ ﻭ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺴﺎﻟﺒﺔ: ﰲ ﺣﺎﻟﺔ ﺃﻧﻚ ﺃﺭﺩﺕ ﺍﺳﺘﻌﻤﺎﻝ ﺃﻋﺪﺍﺩ ﻣﻮﺟﺒﺔ ﻭ ﺃﻋﺪﺍﺩ ﺳﺎﻟﺒﺔ ﳌﺘﻐﲑ ﻓﺘﻮﺟﺪ ﻃﺮﻳﻘﺘﲔ ﻟﺬﻟﻚ ﺍﻷﻭﱃ ﺗﻜﻮﻥ ﺍﻓﺘﺮﺍﺿﻴﺔ ﻋﻨـﺪ ﻛﺘﺎﺑﺔ ﻧﻮﻉ ﻭ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ،ﺃﻱ ﺃﻧﻪ ﻋﻨﺪﻣﺎ ﻧﻘﻮﻡ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻣﺜﻼ int Numﳝﻜﻨﻪ ﺃﻥ ﳛﻤﻞ ﻛﻼ ﻣﻦ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺴﺎﻟﺒﺔ ﻭ ﺍﳌﻮﺟﺒﺔ ،ﺃﻭ ﳝﻜﻦ ﻛﺘﺎﺑﺔ signed Numﻭ ﻫﻲ ﻣﺜﻞ int Numﻣﻦ ﻧﺎﺣﻴﺔ ﺍﳊﺠﻢ ﻭ ﺍﻻﺳﺘﻌﻤﺎﻝ ،ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;signed Num = 5 ;)printf("%d\n", Num }
ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٣ﻣﺘﻐﲑ ﺫﺍﺕ ﺇﺷﺎﺭﺓ
1 2 3 4 5 6 7 8
ﻫﺬﺍ ﺑﺎﻟﻨﺴﺒﺔ ﻟﻠﻤﺘﻐﲑﺍﺕ ﺍﻟﱵ ﲢﺘﻮﻱ ﻋﻠﻰ ﺃﻋﺪﺍﺩ ﻣﻮﺟﺒﺔ ﻭ ﺃﻋﺪﺍﺩ ﺳﺎﻟﺒﺔ ،ﺃﻣﺎ ﰲ ﺣﺎﻟﺔ ﺃﺭﺩﻧﺎ ﺃﻋﺪﺍﺩ ﻣﻮﺟﺒﺔ ﻓﻘﻂ ﻓﺴﻨـﺴﺘﻌﻤﻞ ﺍﻟﻜﻠﻤﺔ unsignedﻗﺒﻞ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ،ﻣﺜﻠﻤﺎ ﻫﻮ ﻣﻮﺿﺢ ﰲ ﺍﳌﺜﺎﻝ ﺍﻟﺘﺎﱄ: >#include<stdio.h )(main { ;unsigned Num = 5 ;)printf("%u\n", Num
ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٤ﻣﺘﻐﲑ ﺑﺪﻭﻥ ﺇﺷﺎﺭﺓ
}
1 2 3 4 5 6 7 8
ﰎ ﺍﻹﻋﻼﻥ ﻋﻦ ﺍﳌﺘﻐﲑ ﺍﻟﺬﻱ ﻻ ﳛﺘﻮﻱ ﻋﻠﻰ ﺃﻋﺪﺍﺩ ﺳﺎﻟﺒﺔ ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﻭ ﻛﻤﺎ ﺃﻥ ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﳍﺎ ﻛﺎﺳﺘﻌﻤﺎﻝ ﻣـﺘﻐﲑ ﻃﺒﻴﻌﻲ ،ﻭ ﻫﻨﺎ ﻧﺘﻌﺮﻑ ﻋﻠﻰ ﺍﻟﺮﻣﺰ ﺍﳉﺪﻳﺪ %uﺍﻟﺬﻱ ﳜﱪ ﺍﳌﺘﺮﺟﻢ ﺃﻧﺎ ﺍﻟﻘﻴﻤﺔ ﺍﻟﱵ ﺳﻴﺘﻢ ﻃﺒﻌﻬﺎ ﻣﻦ ﻧﻮﻉ unisgnedﺃﻱ ﺃﻋﺪﺍﺩ ﺑﺪﻭﻥ ﺇﺷﺎﺭﺓ. ﻣﻼﺣﻈﺔ: ﻋﻨﺪ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻃﺒﻴﻌﻲ ﻣﺜﻼ charﻓﺈﻧﻪ ﺳﻴﺤﺘﻮﻱ ٢٥٦ﺍﺣﺘﻤﺎﻝ ﻛﻤﺎ ﻗﻠﻨﺎ ﺳﺎﺑﻘﺎ،ﺣﻴﺚ ﳝﻜﻦ ﺃﻥ ﻳﺒﺪﺃ ﻣﻦ ٠ﺇﱃ ٢٥٥ﰲ ﺣﺎﻟﺔ ﻋﺪﻡ ﺍﳊﺎﺟﺔ ﺇﱃ ﺃﻋﺪﺍﺩ ﺳﺎﻟﺒﺔ ،ﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﺃﻥ ﻳﺒﺪﺃ ﻣﻦ -١٢٨ﺇﱃ ١٢٧ﰲ ﺣﺎﻟﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺃﻋﺪﺍﺩ ﺳﺎﻟﺒﺔ، ﻭ ﻟﻜﻲ ﺗﻌﺮﻑ ﺍﻟﺴﺒﺐ ﰲ ﺫﻟﻚ ﺇﻟﻴﻚ ﺍﻟﺸﺮﺡ: ﻟﻜﻞ ﻣﺘﻐﲑ ﺣﺠﻤﻪ ،ﻣﺜﻼ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ charﺣﺠﻤﻪ ١ﺑﺎﻳﺖ ﺃﻣﺎ intﻓﺤﺠﻤﻪ ﻫﻮ ٢ﺑﺎﻳﺖ ،ﻭ ﻛﻤﺎ ﻧﻌﺮﻑ ﺃﻥ ١ﺑﺎﻳـﺖ ﻳﺴﺎﻭﻱ ٨ﺑﺖ ،ﺃﻱ ﺃﻥ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ charﺣﺠﻤﻪ ٨ﺑﺖ ،ﻭ ١ﺑﺖ ﻳﺴﺎﻭﻱ ﺇﻣﺎ ١ﺃﻭ ٠ﺣﻴﺚ ﻫﺬﺍ ﻳﻌﲏ ﺃﻥ ١ﺑـﺖ
41
ﻟﺪﻳﻪ ﺍﺣﺘﻤﺎﻟﲔ ) ٠ﺃﻭ ،(١ﺃﻣﺎ ٨ﺑﺖ ﻓﻠﺪﻳﻬﺎ ٢٥٦ﺍﺣﺘﻤﺎﻝ ﺗﺒﺪﺃ ﻣﻦ ٠ﻭ ﺗﻨﺘﻬﻲ ﻋﻨﺪ ٢٥٥ﺇﻥ ﱂ ﺗﻜﻦ ﲢﺘﻮﻱ ﻋﻠﻰ ﺃﻋﺪﺍﺩ ﺳﺎﻟﺒﺔ ،ﺃﻣﺎ ﰲ ﺣﺎﻟﺔ ﺃﺭﺩﻧﺎ ﺃﻋﺪﺍﺩ ﺳﺎﻟﺐ ﻓﺴﻴﺘﻢ ﺳﺤﺐ ١ﺑﺖ ﻣﻦ ٨،ﺃﻱ ﺳﻴﺼﺒﺢ ﺣﺠﻢ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ٧ charﺑﺖ ﺃﻣـﺎ ﺍﻟﺒﺖ ﺍﻟﺜﺎﻣﻦ ﺳﻨﺘﺮﻛﻪ ﻟﻺﺷﺎﺭﺓ ،ﻭ ﺳﻴﺤﻤﻞ ﺇﻣﺎ ﺍﻹﺷﺎﺭﺓ +ﺃﻭ ﺍﻹﺷﺎﺭﺓ ،-ﻭ ٧ﺑﺖ ﺗﺴﺎﻭﻱ ١٢٨ﺍﺣﺘﻤﺎﻝ .ﻭ ﻫﺬﺍ ﺟﺪﻭﻝ ﺑﻪ ﺍﻟﻘﻴﻢ ﺍﶈﺘﻤﻠﺔ ﻟﻜﻞ ﻧﻮﻉ ﻣﻦ ﺍﳌﺘﻐﲑﺍﺕ: ﺍﳊﺠﻢ
ﺍﻟﻘﻴﻢ
ﺍﻟﻨﻮﻉ charﻭ
signed char
١ﺑﺎﻳﺖ
ﻣﻦ -١٢٧ﺇﱃ ١٢٧
charﻭ
char unsigned
١ﺑﺎﻳﺖ
ﻣﻦ ٠ﺇﱃ ٢٥٥
intﻭ
signed int
٢ﺑﺎﻳﺖ
ﻣﻦ -٣٢،٧٦٨ﺇﱃ ٣٢،٧٦٧
intﻭ
unsigned int
٢ﺑﺎﻳﺖ
ﻣﻦ ٠ﺇﱃ ٦٥٥٣٥
shortﻭ
signed short
٢ﺑﺎﻳﺖ
ﻣﻦ -٣٢،٧٦٨ﺇﱃ ٣٢،٧٦٧
shortﻭ
unsigned short
٢ﺑﺎﻳﺖ
ﻣﻦ ٠ﺇﱃ ٦٥٥٣٥
longﻭ
signed long
٤ﺑﺎﻳﺖ
ﻣﻦ -٢،١٤٧،٤٨٣،٦٤٨ﺇﱃ ٢،١٤٧،٤٨٣،٦٤٧
longﻭ
unsigned long
٤ﺑﺎﻳﺖ
ﻣﻦ ٠ﺇﱃ ٤،٢٩٤،٩٦٧،٢٩٥
ﺍﳉﺪﻭﻝ :١,٣,١ﺃﻧﻮﺍﻉ ﺍﳌﺘﻐﲑﺍﺕ ﻭ ﺃﺣﺠﺎﻣﻬﺎ
ﺍﻟﺜﻮﺍﺑﺖ ،ﻫﻲ ﻋﻜﺲ ﺍﳌﺘﻐﲑﺍﺕ ،ﳝﻜﻦ ﺃﻥ ﺗﻜﻮﻥ ﻋﺪﺩ ،ﺣﺮﻑ ،ﺃﻭ ﻧﺺ ،ﺣﻴﺚ ﻻ ﳝﻜﻦ ﺍﻟﺘﻐﲑ ﻗﻴﻤﺘﻬﺎ ﺃﻱ ﺗـﺼﺒﺢ ﻗﺎﺑﻠـﺔ
ﻟﻠﻘﺮﺍﺀﺓ ﻓﻘﻂ ،ﺳﺄﻋﻄﻲ ﻣﺜﺎﻝ ،ﺣﻴﺚ ﻫﺬﺍ ﻣﺜﺎﻝ ﺑﻪ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﺃﻋﺪﺍﺩ ﺻﺤﻴﺤﺔ ،ﻭ ﻧﻌﻄﻴﻪ ﺍﻟﻘﻴﻤﺔ ٥ﰒ ﻧﻘﻮﻡ ﺑﻄﺒﻊ ﺍﳌـﺘﻐﲑ ﻋﻠﻰ ﺍﻟﺸﺎﺷﺔ ﰒ ﻧﻘﻮﻡ ﺑﺘﺤﺪﻳﺚ ﺍﳌﺘﻐﲑ ﺇﱃ ﺍﻟﻘﻴﻤﺔ ٨ﰒ ﻧﻌﻴﺪ ﻃﺒﺎﻋﺔ ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ ﻭ ﻫﺎ ﻫﻮ ﺍﳌﺜﺎﻝ: >#include<stdio.h )(main { ;int num ;num = 5 ;)printf("%d\n", num ;num = 8 ;)printf("%d\n", num
ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٥ﻃﺮﻳﻘﺔ ﲢﺪﻳﺚ ﻗﻴﻤﺔ ﻣﺘﻐﲑ
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14
42
ﻫﻨﺎ ﺳﻴﺘﻢ ﺗﻐﲑ ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ numﻣﻦ ٥ﺇﱃ ،٨ﻭ ﻫﺬﻩ ﺍﻟﻄﺮﻳﻘﺔ ﺻﺤﻴﺢ .ﻭ ﺍﻵﻥ ﺳﻨﻜﺘﺐ ﻧﻔﺲ ﺍﻟﱪﻧﺎﻣﺞ ﺍﻟﺴﺎﺑﻖ ﻣﻊ ﺇﺿـﺎﻓﺔ ﺑﺴﻴﻄﺔ ،ﺍﳌﺜﺎﻝ: >#include<stdio.h )(main { ;const int num ;num = 5 ;)printf("%d\n", num ;num = 8 ;)printf("%d\n", num
ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٦ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺛﺎﺑﺖ ﻭ ﺍﻟﺘﺤﺪﻳﺚ ﰲ ﻗﻴﻤﺘﻪ
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14
ﺍﻹﺿﺎﻓﺔ ﻣﻮﺟﻮﺩﺓ ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ،ﻭ ﻫﻲ ﺇﺿﺎﻓﺔ ﺍﻟﻜﻠﻤﺔ constﺇﱃ ﺍﳌﺘﻐﲑ int numﻭ ﺍﻟﱵ ﺗﻌﲏ ﺃﻥ ﺍﳌﺘﻐﲑ numﺛﺎﺑﺖ، ﻭ ﻫﻨﺎ ﺍﻟﱪﻧﺎﻣﺞ ﻟﻦ ﻳﻌﻤﻞ ﻭ ﺍﻟﺴﺒﺐ ﻫﻮ ﺃﻧﻪ ﻻ ﳝﻜﻦ ﲢﺪﻳﺚ ﺍﻟﻘﻴﻤﺔ ﺍﻷﻭﱃ ﻟﺜﻮﺍﺑﺖ ،ﻭ ﰲ ﻣﺜﺎﻟﻨﺎ ﺍﻟﺴﺎﺑﻘﺔ ﻻ ﺗﻮﺟﺪ ﻗﻴﻤﺔ ﻟﻠﻤﺘﻐﲑ numﺑﻌﺪﻣﺎ ﺃﻥ ﰎ ﺍﻹﻋﻼﻥ ﻋﻨﻪ ،ﻭ ﳚﺐ ﺩﺍﺋﻤﺎ ﺇﻋﻄﺎﺀ ﻗﻴﻢ ﻟﺜﻮﺍﺑﺖ ﻣﺒﺎﺷﺮﺓ ﺑﻌﺪ ﺍﻹﻋﻼﻥ ﻋﻨﻬﺎ ﻭ ﺇﻻ ﺳﺘﻜﻮﻥ ﻋﺒﺎﺭﺓ ﻋﻦ ﺛﻮﺍﺑﺖ ﺫﺍﺕ ﺃﻋﺪﺍﺩ ﻋﺸﻮﺍﺋﻴﺔ ﺛﺎﺑﺘﺔ ﻻ ﳝﻜﻦ ﺍﻟﺘﺤﺪﻳﺚ ﻓﻴﻬﺎ ،ﻭ ﻫﺬﺍ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﺑﻌﺪ ﺍﻟﺘﺼﺤﻴﺢ: >#include<stdio.h )(main { ;const int num = 5 ;)printf("%d\n", num }
ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٧ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺛﺎﺑﺖ
1 2 3 4 5 6 7 8
ﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﻛﺘﺎﺑﺔ ﺍﻟﻜﻠﻤﺔ constﻣﺒﺎﺷﺮﺓ ﺑﻌﺪ ﻧﻮﻉ ﺍﳌﺘﻐﲑ ﻣﺜﻞ: >#include<stdio.h )(main { ;int const num = 5 ;)printf("%d\n", num
ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٨ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺛﺎﺑﺖ )(٢
}
1 2 3 4 5 6 7 8
43
ﻭ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﻧﻔﺲ ﺃﻧﻮﺍﻉ ﺍﳌﺘﻐﲑﺍﺕ ﻋﻠﻰ ﺍﻟﺜﻮﺍﺑﺖ .ﻭ ﻳﻮﺟﺪ ﻧﻮﻉ ﺁﺧﺮ ﻣﻦ ﺍﻟﺜﻮﺍﺑﺖ ،ﻭ ﻫﻲ ﺑﺎﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﻭ ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﳍﺎ ﻣﻮﺿﺤﺔ ﻛﻤﺎ ﰲ ﺍﻟﺼﻮﺭﺓ ﺍﻟﺘﺎﻟﻴﺔ:
#define
ﺍﻟﺸﻜﻞ :١,٣,٣ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺛﺎﺑﺖ ﺣﻴﺚ ﺳﻴﺼﺒﺢ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻘﺔ ﻛﻤﺎ ﻳﻠﻲ: >#include<stdio.h #define num 5 )(main { ;)printf("%d\n", num }
1 2 3 4 5 6 7 8
ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٩ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺛﺎﺑﺖ )(٣ ﰎ ﺍﻹﻋﻼﻥ ﻋﻦ ﺍﻟﺜﺎﺑﺖ numﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻟﺚ ،ﰒ ﻃﺒﺎﻋﺔ ﻗﻴﻤﺘﻪ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ .ﻭ ﻛﻤﺎ ﻗﻠﺖ ﺳـﺎﺑﻘﺎ ،ﺃﻥ preprocessor ﺗﺒﺪﺃ ﺑﺎﻟﺮﻣﺰ ،#ﻭ ﻫﺬﺍ ﻳﻌﲏ ﺃﻥ #defineﻣﻦ ﺍﻟـ ،preprocessorsﻭ ﲨﻴﻊ preprocessorsﻻ ﺗﻨﺘﻬﻲ ﺑﻔﻮﺍﺻﻞ ﻣﻨﻘﻮﻃﺔ. ١,٣,٦ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ: .١ﻻ ﳝﻜﻦ ﻭﺿﻊ ﻗﻴﻤﺔ ﺃﻛﺜﺮ ﻣﻦ ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ ﺍﻟﻘﺼﻮﻯ.
.٢ﻻ ﳝﻜﻦ ﺍﻹﻋﻼﻥ ﻋﻦ ﺍﳌﺘﻐﲑﺍﺕ ﺇﻻ ﰲ ﺑﺪﺍﻳﺔ ﻛﻞ .block .٣ﰲ ﺣﺎﻟﺔ ﱂ ﻳﺘﻢ ﺗﻌﲔ ﻗﻴﻤﺔ ﳌﺘﻐﲑ ،ﻭ ﺃﺭﺩﺕ ﻃﺒﻊ ﻗﻴﻤﺔ ﺫﻟﻚ ﺍﳌﺘﻐﲑ ﻋﻠﻰ ﺍﻟﺸﺎﺷﺔ ﻓﺴﺘﺄﰐ ﺃﻋﺪﺍﺩ ﻋﺸﻮﺍﺋﻴﺔ ﲣﺘﻠﻒ ﻣـﻦ ﺟﻬﺎﺯ ﻵﺧﺮ. .٤ .٥ .٦ .٧
ﳚﺐ ﺍﳊﺮﺹ ﻋﻠﻰ ﺃﻥ ﺑﲔ ﻧﻮﻉ ﺍﳌﺘﻐﲑ ﻭ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ﻣﺴﺎﻓﺔ ﻭﺍﺣﺪﺓ ﻋﻠﻰ ﺍﻷﻗﻞ. ﻻ ﳝﻜﻦ ﻛﺘﺎﺑﺔ ﺍﻟﻜﻠﻤﺔ constﺑﻌﺪ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ﺃﻭ ﺑﻌﺪ ﺍﻹﻋﻼﻥ ﻋﻨﻪ. ﻻ ﳝﻜﻦ ﺗﻐﲑ ﺍﺳﻢ ﻣﺘﻐﲑ ﺃﻭ ﺛﺎﺑﺖ. ﻻ ﳝﻜﻦ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑﻳﻦ ﺑﻨﻔﺲ ﺍﻻﺳﻢ.
44
١,٣,٧ﲤﺎﺭﻳﻦ: .١ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﺍﻟﻌﺪﻳﺪﻳﻦ ٣,١٤ﻭ ،١٥ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺮﻣﻮﺯ ﺍﳋﺎﺻﺔ ﺑﻄﺒﺎﻋﺘﻬﺎ. .٢ .٣ .٤ .٥ .٦
ﻣﺎﺫﺍ ﳛﺪﺙ ﺇﻥ ﺃﻋﻄﲔ ﳌﺘﻐﲑ ﻣﻦ ﻧﻮﻉ intﻗﻴﻤﺔ ﺃﻛﺜﺮ ﻣﻦ ٦٥٥٣٥؟ ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﺍﳊﺮﻑ Aﺑﺪﻝ ﺍﻟﺮﻗﻢ ،٦٥ﺑﺪﻭﻥ ﺍﺳﺘﺨﺪﺍﻡ ﻣﺘﻐﲑﺍﺕ ﺃﻭ ﺛﻮﺍﺑﺖ. ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﺍﳊﺮﻑ Aﺑﺪﻝ ﺍﻟﺮﻗﻢ ،٦٥ﺑﺎﺳﺘﺨﺪﺍﻡ .char ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﺑﻪ ﺛﻼﺛﺔ ﻣﺘﻐﲑﺍﺕ ،ﺍﳌﺘﻐﲑ ﺍﻷﻭﻝ ﺑﻪ ﺍﻟﻘﻴﻤﺔ ١٨ﻭ ﺍﻟﺜﺎﱐ ،٨٩ﺃﻣﺎ ﺍﻟﺜﺎﻟﺚ ﻳﻜﻮﻥ ﺍﻟﻨﺎﺗﺞ ﺍﳊﺎﺻﻞ ﺑـﲔ ﺍﳌﺘﻐﲑ ﺍﻷﻭﻝ ﻭ ﺍﻟﺜﺎﱐ ﰲ ﻛﻞ ﻣﻦ ﺍﳉﻤﻊ ،ﺍﻟﻄﺮﺡ ،ﺍﻟﻘﺴﻤﺔ ﻭ ﺍﻟﻀﺮﺏ. ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﺑﻪ ﺛﻼﺛﺔ ﻣﻦ preprocessor #defineﺣﻴﺚ ﺍﻟﺜﺎﻟﺜﺔ ﻫﻲ ﻧﺘﻴﺠﺔ ﺍﳉﻤﻊ ﺑﲔ ﺍﻷﻭﱃ ﻭ ﺍﻟﺜـﺎﱐ ،ﺍﻷﻭﱃ ﺎ ﺍﻟﻘﻴﻤﺔ ٥ﻭ ﺍﻟﺜﺎﱐ ﺎ ﺍﻟﻘﻴﻤﺔ .١٥
45
ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﻫﻲ ﳎﻤﻮﻋﺔ ﻣﻦ ﺳﻼﺳﻞ ﻧﺼﻴﺔ ﻧﺴﺘﻌﻤﻠﻬﺎ ﻟﺘﻮﺿﻴﺢ ﺃﻭﺍﻣﺮ ﰲ ﻣﺼﺎﺩﺭ ﺑﺮﺍﳎﻨﺎ ،ﻭ ﳝﻜﻦ ﺃﻥ ﲢﺘـﻮﻱ ﺗﻠـﻚ ﺍﻟﻨﺼﻮﺹ ﻋﻠﻰ ﺃﺭﻗﺎﻡ ،ﺃﺣﺮﻑ ،ﺃﻭ ﺭﻣﻮﺯ ﻳﻘﻮﻡ ﺍﳌﺘﺮﺟﻢ ﺑﺘﺠﺎﻫﻠﻬﺎ. ١,٤,١ﻓﺎﺋﺪﺓ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ: ﻓﺎﺋﺪﺓ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﳝﻜﻨﻚ ﺃﻥ ﺗﻼﺣﻈﻬﺎ ﰲ ﺍﻟﻜﺜﲑ ﻣﻦ ﺍﻷﻣﺜﻞ ﺍﳌﻔﺘﻮﺣﺔ ﺍﳌﺼﺪﺭ ﺍﳌﻮﺟﻮﺩﺓ ﻋﻠﻰ ﺍﻹﻧﺘﺮﻧﺖ ،ﻣﺜﻼ ﲡـﺪ ﻣﺜـﺎﻝ ﻟﱪﻧﺎﻣﺞ ﻣﺎ ﻛﺒﲑ ﻭ ﻏﲑ ﻭﺍﺿﺢ ،ﻭ ﻫﻨﺎ ﻳﻠﺠﺊ ﺍﳌﱪﻣﺞ ﺇﱃ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﳉﻌﻠﻬﺎ ﺃﻛﺜﺮ ﻭﺿﻮﺡ. ١,٤,٢ﺃﻧﻮﺍﻉ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ:
ﻳﻮﺟﺪ ﻧﻮﻋﲔ ﻣﻦ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﳘﺎ:
١,٤,٢,١ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﺑﺎﻟﻨﺼﻮﺹ ﺍﻟﻄﻮﻳﻠﺔ:
ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﺑﺎﻟﻨﺼﻮﺹ ﺍﻟﻄﻮﻳﻠﺔ ﻫﻲ ﻧﺼﻮﺹ ﺎ ﺃﻛﺜﺮ ﻣﻦ ﺳﻄﺮ ،ﻭ ﻃﺮﻳﻘﺔ ﺍﺳﺘﺨﺪﺍﻣﻬﺎ ﻫﻲ ﲢﺪﻳﺪ ﺑﺪﺍﻳﺔ ﺍﻟﺘﻌﻠﻴﻖ ﻭ ﺍﻟﱵ ﺗﺒﺪﺃ ﺑـ */ﻭ ﻧﻀﻊ * /ﰲ ﺎﻳﺔ ﺍﻟﺘﻌﻠﻴﻖ ،ﻣﺜﺎﻝ: */ My First Program: !Hello, World */ #include<stdio.h> /* Standart Input Output Header File*/ )(main /*main function*/ {/*Start of main function*/ printf("Hello, World!");/*to print Hello, World!*/ }/*End of main function*/
ﺍﻟﱪﻧﺎﻣﺞ :١,٤,١ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﺑﺎﻟﻨﺼﻮﺹ ﺍﻟﻄﻮﻳﻠﺔ
1 2 3 4 5 6 7 8 9 10 11
١,٤,٢,٢ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﺑﺎﻷﺳﻄﺮ:
ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﺑﺎﻷﺳﻄﺮ ﻫﻲ ﲡﺎﻫﻞ ﺍﻟﺴﻄﺮ ﺍﻟﺘﻌﻠﻴﻘﻲ ﺣﻴﺚ ﺗﺒﺪﺃ ﺑـ ،//ﲤﺖ ﺇﺿﺎﻓﺘﻬﺎ ﰲ ﻟﻐﺔ C++ﺍﻟﻘﻴﺎﺳﻴﺔ ،ﻫـﺬﺍ ﻣﺜـﺎﻝ ﻳﻮﺿﺢ ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﳍﺎ: //My First Program: !//Hello, World
1 2 3
46 #include<stdio.h> //Standart Input Output Header File )(main //main function {//Start of main function !printf("Hello, World!");//to print Hello, World }//End of main function
ﺍﻟﱪﻧﺎﻣﺞ :١,٤,٢ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﺍﻟﺴﻄﺮﻳﺔ
4 5 6 7 8 9
ﻭ ﻫﺬﻩ ﺍﻟﻄﺮﻳﻘﺔ ﻟﻴﺴﺖ ﻣﻦ ﻃﺮﻕ ﻟﻐﺔ Cﺍﻟﻘﻴﺎﺳﻴﺔ ﰲ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ،ﻭ ﻟﻜﻦ ﺍﻟﻜﺜﲑ ﻣﻦ ﺍﳌﺘﺮﲨﺎﺕ ﺗﺪﻋﻤﻬﺎ. ١,٤,٣ﻛﻴﻒ ﻳﺴﺘﻌﻤﻞ ﺍﳌﱪﳎﻮﻥ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ: ﻻ ﺗﺴﺘﻌﻤﻞ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﰲ ﺗﺒﲔ ﺃﻭ ﺗﻮﺿﻴﺢ ﺗﻌﻠﻴﻤﺎﺕ ﰲ ﺍﻟﱪﺍﻣﺞ ،ﻓﻤﺜﻼ ﻳﺴﺘﻌﻤﻞ ﻣﱪﳎﻮﻥ ﺁﺧﺮﻭﻥ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﻟﺘﺒﲔ ﺍﺳـﻢ ﺍﳌﻠﻒ ،ﻛﺎﺗﺒﻪ ،ﺷﺮﺡ ﳐﺘﺼﺮ ﰒ ﺗﺎﺭﻳﺦ ﺇﻧﺸﺎﺀ ﺍﳌﻠﻒ ،ﻣﺜﺎﻝ: /*****************************************************************************/ /*author : Khalil Ounis */ /*Date : 2006/01/01 */ /*Information : This is small program show */ */ how programmers use comments */ */ All rights reserved (c) 2006/2007 */ /*****************************************************************************/ /*****************************************************************************/ /*Function : Principal function */ /*Input : None */ /*Output : None */ /*****************************************************************************/ )(main { /*Empty project*/ }/*Main function end*/
ﺍﻟﱪﻧﺎﻣﺞ :١,٤,٣ﻛﻴﻔﻴﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
١,٤,٤ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ: .١ﰲ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﺑﺎﻟﻨﺼﻮﺹ ﺍﻟﻄﻮﻳﻠﺔ ﺇﻥ ﱂ ﻳﺘﻢ ﲢﺪﻳﺪ ﺎﻳﺔ ﺍﻟﺘﻌﻠﻴﻖ ﻓﺈﻥ ﻛﻞ ﻣﺎ ﻫﻮ ﺑﻌﺪ ﺑﺪﺍﻳﺔ ﺍﻟﺘﻌﻠﻴﻖ ﻳﻌﺘﱪ ﺗﻌﻠﻴﻖ ،ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﺗﻮﺿﻴﺤﻲ: /*comment >#include<stdio.h )(main { ;)"!printf("Hello, World }
ﺍﻟﱪﻧﺎﻣﺞ :١,٤,٤ﺍﳋﻄﺄ ١
1 2 3 4 5 6 7
47
ﻫﻨﺎ ﺍﻟﱪﻧﺎﻣﺞ ﻛﻠﻪ ﻋﺒﺎﺭﺓ ﻋﻦ ﺗﻌﻠﻴﻖ ،ﺃﻱ ﺃﻥ ﺍﳌﺸﺮﻭﻉ ﻓﺎﺭﻍ. .٢ﰲ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﺍﻟﺴﻄﺮﻳﺔ ﳚﺐ ﺍﻻﻧﺘﺒﺎﻩ ﺇﱃ ﻣﺎ ﻧﻀﻌﻪ ﺗﻌﻠﻴﻖ ﻓﻤﺜﻼ: >//#include<stdio.h )(main { ;)"!printf("Hello, World }
ﺍﻟﱪﻧﺎﻣﺞ :١,٤,٥ﺍﳋﻄﺄ ٢
ﻫﻨﺎ ﺳﻴﺨﱪﻙ ﺍﳌﺘﺮﺟﻢ ﻋﻠﻰ ﺃﻥ ﺍﻟﺪﺍﻟﺔ printfﻏﲑ ﻣﻌﺮﻓﺔ ﺳﺎﺑﻘﺎ ،ﻭ ﻫﺬﺍ ﺍﳋﻄﺄ ﺳﺒﺒﻪ ﻫﻮ ﺟﻌﻞ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ﺍﳋﺎﺻﺔ ﺑﻀﻢ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ stdio.hﻋﺒﺎﺭﺓ ﻋﻦ ﺗﻌﻠﻴﻖ ،ﻭ ﻫﻨﺎ ﺳﻴﺘﻢ ﲡﺎﻫﻞ ﺿﻢ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ .stdio.h ١,٤,٥ﲤﺎﺭﻳﻦ:
ﻻ ﺗﻮﺟﺪ ﲤﺎﺭﻳﻦ ﰲ ﻫﺬﺍ ﺍﻟﺪﺭﺱ.
1 2 3 4 5 6
#include
48
ﰲ ﺍﻟﺪﺭﻭﺱ ﺍﻟﺴﺎﺑﻘﺔ ﱂ ﻧﺪﺭﺱ ﺇﻻ ﺍﻹﺧﺮﺍﺝ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺪﺍﻟﺔ ،printfﺍﻵﻥ ﺳﻨﻌﺮﻑ ﻛﻴﻔﻴﺔ ﺍﻹﺩﺧﺎﻝ ﺑﻮﺍﺳﻄﺔ ﺍﻟﺪﺍﻟﺔ ﺩﻭﺍﻝ ﺧﺎﺻﺔ ﺑﺎﻹﺧﺮﺍﺝ ،ﺣﺎﻟﻴﺎ ﺳﻨﺮﻯ ﺍﻟﺪﺍﻟﺔ ،scanfﺍﻟﺘﺸﺎﺑﻪ ﻛﺒﲑ ﺟﺪﺍ ﺑﲔ ﺍﻟـﺪﺍﻟﻴﺘﲔ printfﻭ ،scanfﻓﻘـﻂ ﺍﻷﻭﱃ ﺧﺎﺻﺔ ﺑﺎﻹﺧﺮﺍﺝ ﻭ ﺍﻟﺜﺎﻧﻴﺔ ﺧﺎﺻﺔ ﺑﺎﻹﺩﺧﺎﻝ .ﺗﺴﺘﻌﻤﻞ ﺍﻟﺪﺍﻟﺔ scanfﻟﻘﺮﺍﺀﺓ ﺃﻭ ﺍﺳﺘﻘﺒﺎﻝ ﺍﳌﻌﻠﻮﻣﺎﺕ ﻣﻦ ﺃﺩﺍﺀﻩ ﺍﻹﺩﺧﺎﻝ ﻟﻮﺣﺔ ﺍﳌﻔﺎﺗﻴﺢ .keyboardﺍﻵﻥ ﺳﻨﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﺑﺮﻧﺎﻣﺞ ﻳﻄﻠﺐ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﻗﻴﻤﺔ ﰒ ﻧﻌﻄﻴﻪ ﺍﻟﻘﻴﻤﺔ ﺍﻟﱵ ﻗﺎﻡ ﺑﺈﺩﺧﺎﳍﺎ: */اﻹدﺧﺎل*/ >#include<stdio.h
*/ﻫﻨﺎ ﺳﻨﻀﻊ اﻟﻘﯿﻤﺔ اﻟﱵ ﺳﯿﺪﺧﻠﻬﺎ اﳌﺴﺘﺨﺪم*/
)(main { ;int usr_val
*/ﻫﻨﺎ ﻧﻄﻠﺐ ﻣﻦ اﳌﺴﺘﺨﺪم إدﺧﺎل ﻗﯿﻤﺔ*printf("Enter a value: ");/ */ﯾﻘﻤﻮم اﳉﻬﺎز ﺑﺈﻧﺘﻈﺎر دﺧﻮل ﻗﯿﻤﺔ ﻣﻦ اﳌﺴﺘﺨﺪم *scanf("%d", &usr_val); / */و ﻫﻨﺎ ﻧﻄﺒﻊ اﻟﻘﯿﻤﺔ اﻟﱵ أدﺧﻠﺖ *printf("Your value is: %d\n", usr_val);/
ﺍﻟﱪﻧﺎﻣﺞ :١,٥,١ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ scanfﻹﺩﺧﺎﻝ ﻗﻴﻤﺔ ﺻﺤﻴﺤﺔ
}
1 2 3 4 5 6 7 8 9 10 11
ﺍﻟﱪﻧﺎﻣﺞ ﻣﻮﺿﺢ ﺑﺎﻟﺘﻌﻠﻴﻘﺎﺕ ،ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺘﺎﺳﻊ ﻗﻤﻨﺎ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺪﺍﻟﺔ scanfﻭ ﺩﺍﺧﻠﻬﺎ ﺳﺘﺠﺪ ﻭﺳﻴﻄﲔ ،ﺍﻷﻭﻝ ﻧﻘﻮﻡ ﻓﻴـﻪ ﺑﺘﺤﺪﻳﺪ ﻧﻮﻉ ﺍﻟﻘﻴﻤﺔ ﺍﻟﱵ ﺳﻴﺪﺧﻠﻬﺎ ﺍﳌﺴﺘﺨﺪﻡ ﺣﻴﺚ ﻫﻨﺎ ﻭﺿﻌﻨﺎ ﺍﻟﺮﻣﺰ %dﻭ ﺍﻟﺬﻱ ﺩﺭﺳﻨﻪ ﺳﺎﺑﻘﺎ ﰲ ﺍﻟﺪﺍﻟﺔ printfﺣﻴـﺚ ﻗﻠﻨﺎ ﺃﺎ ﺧﺎﺹ ﺑﺎﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ،ﻭ ﰲ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻳﻮﺟﺪ ،&usr_valﻭ ﺍﻟﺮﻣﺰ & ﻳﻌﲏ ﻭﺿﻊ ﺍﻟﻘﻴﻤﺔ ﺍﻟـﱵ ﺃﺩﺧﻠـﻬﺎ ﺍﳌﺴﺘﺨﺪﻡ ﰲ ﻋﻨﻮﺍﻥ ﺍﳌﺘﻐﲑ ،usr_valﻭ ﺳﺘﻔﻬﻢ ﺍﻟﺴﺒﺐ ﺇﺿﺎﻓﺔ ﺍﻟﺮﻣﺰ & ﰲ ﺍﻟﺪﺭﻭﺱ ﺍﻟﻘﺎﺩﻣﺔ ، .ﺇﻻ ﻫﻨـﺎ ﺗﻜـﻮﻥ ﻗﻴﻤـﺔ usr_valﻗﺪ ﺃﺻﺒﺤﺖ ﺍﻟﻘﻴﻤﺔ ﺍﻟﱵ ﺃﺩﺧﻠﻬﺎ ﺍﳌﺴﺘﺨﺪﻡ ﰒ ﻧﻘﻮﻡ ﺑﻄﺒﺎﻋﺘﻬﺎ ﻋﻠﻰ ﺍﻟﺸﺎﺷﺔ. ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﺧﺎﺹ ﺑﺈﺩﺧﺎﻝ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ،ﺃﻣﺎ ﺑﺎﻟﻨﺴﺒﺔ ﻟﺒﺎﻗﻲ ﺃﻧﻮﺍﻉ ﺍﳌﺘﻐﲑﺍﺕ ﻓﺴﻨﺴﺘﻌﻤﻞ ﻧﻔﺲ ﺍﻟﻄﺮﻳﻘﺔ ﻓﻘﻂ ﻧﻘـﻮﻡ ﺑﺘﻐﲑ ﺍﻟﺮﻣﺰ %dﺇﱃ ﻧﻮﻉ ﺍﳌﺘﻐﲑ ﺍﻟﺬﻱ ﻧﺮﻳﺪ ﺇﺳﺘﻘﺒﺎﻟﻪ ،ﻓﻤﺜﻼ ﺇﺫﺍ ﺃﺭﺩﻧﺎ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺃﻥ ﻳﻘﻮﻡ ﺑﺈﺩﺧﺎﻝ ﺭﻣﺰ ﺑﺪﻝ ﺭﻗـﻢ ﻧـﻀﻊ ﺍﻟﺮﻣﺰ %cﰲ ﺍﻟﺪﺍﻟﺔ ،scanfﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﻳﻮﺿﺢ ﺫﻟﻚ: >#include<stdio.h )(main { ;char usr_char ;)" printf("Enter a character: ;)scanf("%c", &usr_char ;)printf("Your character is: %c\n", usr_char }
1 2 3 4 5 6 7 8 9 10
49
ﺍﻟﱪﻧﺎﻣﺞ :١,٥,٢ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ scanfﻹﺩﺧﺎﻝ ﺣﺮﻑ
ﺍﻵﻥ ﺳﻨﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﺑﺮﻧﺎﻣﺞ ﻳﻄﻠﺐ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﻗﻴﻤﺔ ،ﰒ ﻳﻄﻠﺐ ﻣﻨﻪ ﺇﺩﺧﺎﻝ ﻗﻴﻤﺔ ﺛﺎﻧﻴﺔ ،ﻭ ﻧﻌﻄﻴﻪ ﺍﻟﻨﺘـﺎﺋﺞ ﲜﻤﻴـﻊ ﺍﳌﺆﺛﺮﺍﺕ ﺍﻷﺳﺎﺳﻴﺔ: >#include<stdio.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
>#include<stdio.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14
)(main { ;int val1, val2 ;)" printf("1)Enter a value: ;)scanf("%d", &val1 ;)" printf("2)Enter a value: ;)scanf("%d", &val2 ;)val1+val2 ;)val1-val2 ;)val1*val2 ;)val1/val2
val2, val2, val2, val2,
val1, val1, val1, val1,
%d\n", %d\n", %d\n", %d\n",
= = = =
%d %d %d %d
+ * /
printf("%d printf("%d printf("%d printf("%d
}
ﺍﻟﱪﻧﺎﻣﺞ :١,٥,٣ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ scanfﻹﺩﺧﺎﻝ ﻗﻴﻤﺔ ﺻﺤﻴﺤﺔ )(٢ ﺍﳌﺜﺎﻝ ﻭﺍﺿﺢ ،ﻗﻤﻨﺎ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑﻳﻦ ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ،ﰒ ﻃﻠﺒﻨﺎ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﻗﻴﻤﺔ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﻭ ﻗﻤﻨﺎ ﺑﺄﺧﺬ ﺍﻟﻘﻴﻤﺔ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ،ﻭ ﺑﻌﺪﻫﺎ ﻃﻠﺒﻨﺎ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﺍﻟﻘﻴﻤﺔ ﺍﻟﺜﺎﻧﻴﺔ ﰒ ﺃﺧﺬﻧﺎ ﺍﻟﻘﻴﻤﺔ ﺍﻟﺜﺎﻧﻴﺔ ﰲ ﺍﻟﺴﻄﺮ ﺍﳊﺎﺩﻱ ﻋﺸﺮ ،ﰒ ﻃﺒﻌﻨﺎ ﺍﻟﻨﺘﺎﺋﺞ ﰲ ﻛﻞ ﻣﻦ ﺍﻟﺴﻄﺮ ١٥ ،١٤ ،١٣ﻭ .١٦ﻭ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺇﺩﺧﺎﻝ ﻣﺘﻌﺪﺩ ﰲ ﺍﻟﺪﺍﻟـﺔ ،scanfﻭ ﻫﺬﺍ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻘﺔ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻹﺩﺧﺎﻝ ﺍﳌﺘﻌﺪﺩ:
)(main { ;int val1, val2 ;)" printf("Enter two value: ;)scanf("%d%d", &val1, &val2 ;)val1+val2 ;)val1-val2 ;)val1*val2 ;)val1/val2
val2, val2, val2, val2,
val1, val1, val1, val1,
%d\n", %d\n", %d\n", %d\n",
= = = =
%d %d %d %d
+ * /
printf("%d printf("%d printf("%d printf("%d
ﺍﻟﱪﻧﺎﻣﺞ :١,٥,٤ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ scanfﻹﺩﺧﺎﻝ ﻗﻴﻤﺔ ﺻﺤﻴﺤﺔ )(٣
}
50
ﺍﻟﺘﻌﺪﺩ ﻫﻨﺎ ﻣﻮﺟﻮﺩ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ،ﰲ ﺍﻟﺪﺍﻟﺔ ،scanfﻭ ﳝﻜﻦ ﺃﻥ ﻧﺰﻳﺪ ﺃﻛﺜﺮ ﻣﻦ ﺫﻟﻚ ،ﻓﻘﻂ ﻧﻀﻴﻒ ﺍﻟﺮﻣﺰ ﺍﳋﺎﺹ ﺑﻨﻮﻉ ﺍﳌﺘﻐﲑ ﰒ ﺇﺿﺎﻓﺔ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ﰲ ﺁﺧﺮ ﺍﻟﺪﺍﻟﺔ. ١,٥,١ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ:
.١ﻻ ﳝﻜﻦ ﺍﺳﺘﺨﺪﺍﻡ ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻣﻦ ﺍﻟﺪﺍﻟﺔ scanfﻟﻄﺒﺎﻋﺔ)ﺍﻹﺧﺮﺍﺝ( ،ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻣﻦ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺧﺎﺹ ﺑﻨﻮﻉ ﺍﻟﺮﻣﻮﺯ ﺍﻟﱵ ﺳﻴﺴﺘﻘﺒﻠﻬﺎ ﺍﻟﱪﻧﺎﻣﺞ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ. .٢ﰲ ﺣﺎﻟﺔ ﺍﻻﺳﺘﻐﻨﺎﺀ ﻋﻦ ﺍﻟﺮﻣﺰ & ﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﺎﺋﺞ ﻏﲑ ﺻﺤﻴﺤﺔ. .٣ﳚﺐ ﺍﻻﻧﺘﺒﺎﻩ ﺇﱃ ﻋﺪﺩ ﺍﳌﺘﻐﲑﺍﺕ ﺍﳌﺮﺍﺩ ﻓﺤﺼﻬﺎ ،ﳚﺐ ﺃﻥ ﻳﻜﻮﻥ ﻋﺪﺩ ﺭﻣﻮﺯ ﺃﻧﻮﺍﻉ ﺍﳌﺘﻐﲑﺍﺕ ﻧﻔﺴﻪ ﻋﺪﺩ ﺍﳌـﺘﻐﲑﺍﺕ ﺍﳌﺮﺍﺩ ﻓﺤﺼﻬﺎ.
١,٥,٢ﲤﺎﺭﻳﻦ: .١ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻄﻠﺐ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﺍﳊﺮﻑ ﺍﻷﻭﻝ ﻭ ﺍﻷﺧﲑ ﻣﻦ ﺍﲰﻪ ﰒ ﻳﻘﻮﻡ ﺍﻟﱪﻧﺎﻣﺞ ﺑﺈﺧﺒﺎﺭ ﺍﳌﺴﺘﺨﺪﻡ ﺃﻥ ﺇﺳﻢ ﻳﺒﺪﺃ ﺑـ "ﺍﳊﺮﻑ ﺍﻷﻭﻝ ﺍﻟﺬﻱ ﺃﺩﺧﻠﻪ ﺍﳌﺴﺘﺨﺪﻡ" ﻭ ﻳﻨﺘﻬﻲ ﺑﺎﳊﺮﻑ "ﺍﳊﺮﻑ ﺍﻷﺧﲑ ﺍﻟﺬﻱ ﺃﺩﺧﻠﻪ ﺍﳌﺴﺘﺨﺪﻡ".
51
ﻟﻠﻤﺆﺛﺮﺍﺕ ﺃﻧﻮﺍﻉ ﺃﳘﻬﻤﺎ ﺛﻼﺛﺔ ﻭ ﻫﻲ: ١,٦,١ﺍﳌﺆﺛﺮﺍﺕ ﺍﳊﺴﺎﺑﻴﺔ ):(arthimetic operators
ﻫﻲ ﺍﳌﺆﺛﺮﺍﺕ ﺍﳊﺴﺎﺑﻴﺔ ﺍﻷﺳﺎﺳﻴﺔ ﻭ ﺍﻟﱵ ﺗﺘﻤﺜﻞ ﰲ ﻛﻞ ﻣﻦ ﺍﳉﻤﻊ) ،(+ﺍﻟﻄﺮﺡ) ،(-ﺍﻟﻘﺴﻤﺔ) (/ﻭ ﺍﻟﻀﺮﺏ)*(،ﻭ ﺗﻮﺟـﺪ ﻣﺆﺛﺮﺍﺕ ﺃﺧﺮﻯ ﺧﺎﺹ ﺑﻠﻐﺔ Cﻭ ﻫﻲ :ﺍﻟﺰﻳﺎﺩﺓ) ،(++ﺍﻟﻨﻘﺼﺎﻥ) (--ﻭ ﺑﺎﻗﻲ ﺍﻟﻘﺴﻤﺔ).(% ﺑﺎﻟﻨﺴﺒﺔ ﻟﻠﺠﻤﻊ ،ﺍﻟﻄﺮﺡ ،ﺍﻟﻘﺴﻤﺔ ﻭ ﺍﻟﻀﺮﺏ ﻓﻘﺪ ﺃﺧﺬﻧﺎ ﺃﻣﺜﻠﺔ ﻋﻨﻬﺎ ﺳﺎﺑﻘﺎ .ﺳﻨﺄﺧﺬ ﺃﻣﺜﻠﺔ ﻋﻦ ﻛﻞ ﻣﻦ ﻣـﺆﺛﺮﺍﺕ ﺍﻟﺰﻳـﺎﺩﺓ ﻭ ﺍﻟﻨﻘﺼﺎﻥ ﻭ ﺑﺎﻗﻲ ﺍﻟﻘﺴﻤﺔ: ١,٦,١,١ﻣﺆﺛﺮ ﺍﻟﺰﻳﺎﺩﺓ :(++) increment
ﺗﻌﺘﱪ ﻣﺆﺛﺮﺍﺕ ﺍﻟﺰﻳﺎﺩﺓ ﻭ ﺍﻟﻨﻘﺼﺎﻥ ﻣﻦ ﺃﻫﻢ ﺍﳌﺆﺛﺮﺍﺕ ،ﺗـﺴﺘﻌﻤﻞ ﰲ ﺍﻟﻜـﺜﲑ ﻣـﻦ ﺍﻟـﱪﺍﻣﺞ ﻭ ﺧﺎﺻـﺔ ﰲ ﺣﻠﻘـﺎﺕ ﺍﻟﺘﻜﺮﺍﺭ)ﺳﻨﺪﺭﺳﻬﺎ ﰲ ﺍﻟﺪﺭﻭﺱ ﺍﻟﻘﺎﺩﻣﺔ( .ﻣﺆﺛﺮ ﺍﻟﺰﻳﺎﺩﺓ ﻳﻌﲏ ﺯﻳﺎﺩﺓ ﺭﻗﻢ ﻭﺍﺣﺪ ﺇﱃ ﺍﳌﺘﻐﲑ ﺍﻟﺬﻱ ﻧﺮﻳﺪ ﺍﻟﺰﻳﺎﺩﺓ ﺇﻟﻴﻪ ،ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﻳﻮﺿﺢ ﺫﻟﻚ: >#include<stdio.h )(main { ;int Inc ;Inc = 0 ;)printf("Inc = %d\n", Inc ;Inc++ ;)printf("Inc = %d\n", Inc ;++Inc ;)printf("Inc = %d\n", Inc
ﺍﻟﱪﻧﺎﻣﺞ :١,٦,١ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﻣﺆﺛﺮ ﺍﻟﺰﻳﺎﺩﺓ
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
ﻗﻤﻨﺎ ﺑﺎﺳﺘﻌﻤﺎﻝ ﻣﺆﺛﺮ ﺍﻟﺰﻳﺎﺩﺓ ﰲ ﻛﻼ ﻣﻦ ﺍﻟﺴﻄﺮ ﺍﻟﻌﺎﺷﺮ ﻭ ﺍﻟﺴﻄﺮ ﺍﻟﺮﺍﺑﻊ ﻋﺸﺮ ،ﻭ ﻧﺘﺎﺋﺞ ﺍﻟﱪﻧﺎﻣﺞ ﺗﻜـﻮﻥ ٠ﰒ ١ﰒ .٢ﻭ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﻃﺮﻕ ﺃﺧﺮﻯ ﻣﺜﻞ: ;)printf("Inc = %d\n", Inc
1 2
52 ;Inc = Inc+1 ;)printf("Inc = %d\n", Inc ;Inc += 1 ;)printf("Inc = %d\n", Inc
3 4 5 6 7 8 9
ﺍﻟﱪﻧﺎﻣﺞ :١,٦,٢ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﻣﺆﺛﺮ ﺍﻟﺰﻳﺎﺩﺓ )(٢ ﺍﻟﻄﺮﻳﻘﺔ ﺍﻷﻭﱃ ﻫﻲ Inc = Inc+1ﻭ ﺍﻟﱵ ﻣﻮﺟﻮﺩ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻟﺚ ،ﻫﻲ ﻣﻄﺎﺑﻘﺔ ﲤﺎﻣﺎ ﻟـ Inc++ﻭ ﻟﻜﻦ ﰲ ﺍﻟـﺴﺎﺑﻘﺔ ﳝﻜﻦ ﺃﻥ ﻧﻘﻮﻡ ﺑﺰﻳﺎﺩﺓ ﺃﻛﺜﺮ ﻣﻦ ١ﻳﻌﲏ ﺇﻥ ﻛﺘﺒﻨﺎ Inc = Inc+3ﻓﺴﻴﺘﻢ ﺍﻹﺿﺎﻓﺔ ﺇﱃ ﺍﳌﺘﻐﲑ Incﺛﻼﺛﺔ ﺃﺭﻗـﺎﻡ ،ﻛـﺬﻟﻚ ﺍﻟﻄﺮﻳﻘﺔ ﺍﻟﺜﺎﻧﻴﺔ ،Inc += 1ﻫﻲ ﻣﺜﻞ Inc = Inc+1ﲤﺎﻡ .ﻭ ﻟﻜﻦ ﻳﺴﺘﺤﺴﻦ ﺩﺍﺋﻤﺎ ﺍﺳﺘﻌﻤﺎﻝ ++ﻋﻨﺪ ﺍﻟﺰﻳﺎﺩﺓ ﺑﺎﻟﻮﺍﺣﺪ ،ﻭ ﰲ ﺣﺎﻟﺔ ﺃﻥ ﺯﻳﺎﺩﺓ ﺳﺘﻜﻮﻥ ﺃﻛﺜﺮ ﻣﻦ ﻭﺍﺣﺪ ﻓﺴﻨﺴﺘﻌﻤﻞ ﺍﻟﻄﺮﻕ ﺍﻷﺧﺮﻯ .ﻭ ﺍﻟﻔﺮﻕ ﺑﲔ ﺃﻥ ﻳﻜﻮﻥ ﺍﳌﺆﺛﺮﻳﻦ ++ﰲ ﺑﺪﺍﻳﺔ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ﺃﻭ ﺎﻳﺘﻪ ﻫﻮ ﻣﻮﺿﺢ ﰲ ﺍﳌﺜﺎﻝ ﺍﻟﺘﺎﱄ: >#include<stdio.h )(main { ;int Inc ;Inc = 0 ;)Inc ;)Inc++ ;)Inc ;)++Inc ;)Inc
%d\n", %d\n", %d\n", %d\n", %d\n",
= = = = =
printf("Inc printf("Inc printf("Inc printf("Inc printf("Inc }
1 2 3 4 5 6 7 8 9 10 11 12 13
ﺍﻟﱪﻧﺎﻣﺞ :١,٦,٣ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﻣﺆﺛﺮ ﺍﻟﺰﻳﺎﺩﺓ )(٣ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﺳﻴﺘﻢ ﻃﺒﺎﻋﺔ ﺍﻟﻌﺪﺩ ،٠ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺘﺎﺳﻊ ﺃﻳﻀﺎ ﻭ ﻣﻌﻨﺎ ﺫﻟﻚ ﻋﻨﺪ ﻛﺘﺎﺑﺔ ﻣﺘﻐﲑ ﻗﻢ ﺍﳌﺆﺛﺮ ++ﻳﻌﲏ ﻃﺒﺎﻋﺘﻪ ﰒ ﺗﻨﻔﻴﺬ ﻣﺆﺛﺮ ﺍﻟﺘﺰﺍﻳﺪ .ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﻌﺎﺷﺮ ﺳﻴﺘﻢ ﻃﺒﻊ ﺍﻟﻌﺪﺩ ١ﻷﻧﻨﺎ ﻗﻤﻨﺎ ﺑﺎﻟﺰﻳﺎﺩﺓ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺘﺎﺳﻊ .ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﳊـﺎﺩﻱ ﻋﺸﺮ ﺳﻴﺘﻢ ﺗﻨﻔﺬ ﻣﺆﺛﺮ ﺍﻟﺘﺰﺍﻳﺪ ﺃﻭﻻ ﱘ ﻃﺒﺎﻋﺔ ﺍﻟﻨﺘﻴﺠﺔ ﺍﻟﱵ ﻫﻲ ،٢ﻭ ﻛﺬﻟﻚ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﱐ ﻋﺸﺮ ﺳﻴﺘﻢ ﻃﺒﺎﻋﺔ ﺍﻟﻌﺪﺩ .٢ ١,٦,١,٢ﻣﺆﺛﺮ ﺍﻟﻨﻘﺼﺎﻥ :(--) decrement
ﺳﻨﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﺆﺛﺮ ﺍﻟﻨﻘﺼﺎﻥ ﻣﺜﻠﻤﺎ ﺗﻌﺎﻣﻠﻨﺎ ﻣﻊ ﻣﺆﺛﺮ ﺍﻟﺰﻳﺎﺩﺓ ﻓﻘﻂ ﺑﺪﻝ ++ﻧﻀﻊ --ﻭ ﻫﺬﺍ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﺑﺎﺳﺘﺨﺪﺍﻡ ﻣﺆﺛﺮ
ﺍﻟﻨﻘﺼﺎﻥ:
>#include<stdio.h )(main
1 2 3
53 { ;int Dec ;Dec = 2 ;)printf("Dec = %d\n", Dec ;Dec-- ;)printf("Dec = %d\n", Dec ;--Dec ;)printf("Dec = %d\n", Dec
ﺍﻟﱪﻧﺎﻣﺞ :١,٦,٤ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﻣﺆﺛﺮ ﺍﻟﻨﻘﺼﺎﻥ
}
4 5 6 7 8 9 10 11 12 13 14 15 16 17
ﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﺍﺳﺘﻌﻤﺎﻝ ﻧﻔﺲ ﺍﻟﻄﺮﻕ ﺍﻟﺴﺎﺑﻘﺔ ﰲ ﺍﻟﻨﻘﺼﺎﻥ:
;)printf("Dec = %d\n", Dec ;Dec = Dec-1 ;)printf("Dec = %d\n", Dec ;Dec -= 1 ;)printf("Dec = %d\n", Dec
ﺍﻟﱪﻧﺎﻣﺞ :١,٦,٥ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﻣﺆﺛﺮ ﺍﻟﻨﻘﺼﺎﻥ )(٢
1 2 3 4 5 6 7 8 9
١,٦,١,٣ﻣﺆﺛﺮ ﺑﺎﻗﻲ ﺍﻟﻘﺴﻤﺔ ):(%
ﺃﻳﻀﺎ ﳝﻜﻦ ﺍﻋﺘﺒﺎﺭﻩ ﻣﻦ ﺍﳌﺆﺛﺮﺍﺕ ﺍﳌﻬﻤﺔ ،ﻭ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻟﻪ ﺳﻬﻞ ﻓﻤﺜﻼ ﻟﻮ ﺃﺭﺩﻧﺎ ﺃﻥ ﳒﺪ ﺑﺎﻗﻲ ﺍﻟﻘﺴﻤﺔ ﺑﲔ ﺍﻟﻌـﺪﺩ ٥ﻭ ﺍﻟﻌﺪﺩ ٣ﻧﻜﺘﺐ ،5%3ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﺗﻮﺿﻴﺤﻲ: >#include<stdio.h )(main { ;)printf("%d\n", 5%3 }
ﺍﻟﱪﻧﺎﻣﺞ :١,٦,٦ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﻣﺆﺛﺮ ﺑﺎﻗﻲ ﺍﻟﻘﺴﻤﺔ
1 2 3 4 5 6
١,٦,٢ﺍﳌﺆﺛﺮﺍﺕ ﺍﻟﻌﻼﻗﻴﺔ ):(relational operators
ﻫﻲ ﻣﺆﺛﺮﺍﺕ ﺗﻌﺘﻤﺪ ﻋﻠﻰ ﺍﳌﻘﺎﺭﻧﺔ ﺑﲔ ﻗﻴﻤﺔ ﻭ ﻗﻴﻤﺔ ﺃﺧﺮﻯ ،ﺣﻴﺚ ﺗﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﺇﻣﺎ ﺻﺤﻴﺤﺔ ) (trueﺃﻭ ﺧﺎﻃﺌﺔ )،(false ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﻳﻮﺿﺢ ﺫﻟﻚ: >#include<stdio.h
1
54
)(main { ;)printf("%d\n", 53 }
ﺍﻟﱪﻧﺎﻣﺞ :١,٦,٧ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮﺍﺕ ﺍﻟﻌﻼﻗﻴﺔ
2 3 4 5 6 7 8
ﻫﻨﺎ ﺳﺘﺠﺪ ﻧﺘﺎﺋﺞ ﺍﻟﱪﻧﺎﻣﺞ: :٠ﻷﻥ ﺍﻟﻌﺪﺩ ٥ﻟﻴﺲ ﺃﻗﻞ ﻣﻦ .٣ :٠ﻷﻥ ﺍﻟﻌﺪﺩ ٥ﻻ ﻳﺴﺎﻭﻱ ﺍﻟﻌﺪﺩ .٣ :١ﻷﻥ ﺍﻟﻌﺪﺩ ٥ﺃﻛﺒﲑ ﻣﻦ .٣
ﺣﻴﺚ ٠ﺗﻌﲏ ﺧﻄﺄ ) (trueﻭ ١ﺗﻌﲏ ﺻﺤﻴﺢ ) ،(falseﻭ ﺃﻳﻀﺎ ﺳﺘﻼﺣﻆ ﺃﻧﻪ ﻛﺘﺒﻨﺎ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟـﺴﺎﺩﺱ ٣==٥ﻭ ﻟـﻴﺲ ٣=٥ﻭ ﺫﻟﻚ ﻷﻧﻨﺎ ﻧﻘﺎﺭﻥ ﻭ ﻋﻨﺪ ﺍﳌﻘﺎﺭﻧﺔ ﻧﻜﺘﺐ == ،ﻭ ﺇﺫﺍ ﻭﺿﻌﺖ = ﻣﻜﺎﻥ == ﻓﺴﻴﺨﱪﻙ ﺍﳌﺘﺮﺟﻢ ﻋﻦ ﻭﺟﻮﺩ ﺧﻄـﺄ .ﻭ ﻳﻮﺟﺪ ﻛﺬﻟﻚ ﺍﳌﺆﺛﺮ ﺃﻛﱪ ﻣﻦ ﺃﻭ ﻳﺴﺎﻭﻱ ﻭ ﳝﺜﻞ ﰲ ﻟﻐﺔ Cﺑـ => ،ﻭ ﻣﺆﺛﺮ ﺃﺻﻐﺮ ﻣﻦ ﺃﻭ ﻳﺴﺎﻭﻱ ﺑــ =#include<stdio.h )(main { ;)printf("%d\n", 53 ;)printf("%d\n", 5==3 && 3==5 ;)printf("%d\n", 5>3 && 53 || 5#include<stdio.h )(main { ;)printf("%d\n", 128>>7 }
ﺻﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ:
ﺍﻟﱪﻧﺎﻣﺞ :١,٦,١٠ﻣﺆﺛﺮ ﺍﻹﺯﺍﺣﺔ ﺇﱃ ﺍﻟﻴﻤﲔ
1 2 3 4 5 6
ﺍﻟﺸﻜﻞ :١,٦,٢ﺍﻹﺯﺍﺣﺔ ﺇﱃ ﳝﲔ
ﺍﳌﺆﺛﺮ ،#ﻭ ﻫﻮ ﻳﺴﺘﻌﻤﻞ ﻣﻊ ﺍﻟﺘﻮﺟﻴﻪ ،#defineﻣﺜﺎﻝ:
>#include<stdio.h )"#define printer(str) printf(#str "\n
ﺍﻟﱪﻧﺎﻣﺞ :١,٦,١١ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮ
)(main { ;)printer(Hello } #
1 2 3 4 5 6 7 8 9
57
ﺍﳌﺆﺛﺮﻳﻦ ##ﻣﻌﺎ ،ﺃﻳﻀﺎ ﻳﺘﻢ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻌﻬﻤﺎ ﻣﻊ ﺍﻟﺘﻮﺟﻴﻪ ،#defineﻭ ﳝﻜﻦ ﺗﺴﻤﻴﺘﻬﻤﺎ ﺑﺎﻟـ Mergeﺃﻱ ﺍﻟﺪﻣﺞ ،ﻣﺜﺎﻝ: >#include<stdio.h #define MergingName(str, strplus) str##strplus
;''H ;''e ;''l ;''l ;''o
= = = = =
)1 )2 )3 )4 )5
MergingName(ch, MergingName(ch, MergingName(ch, MergingName(ch, MergingName(ch,
)(main { char char char char char
;)printf("%c%c%c%c%c\n", ch1, ch2, ch3, ch4, ch5
ﺍﻟﱪﻧﺎﻣﺞ :١,٦,١٢ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮﻳﻦ
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
##
١,٦,٥ﻣﺆﺛﺮﺍﺕ ﺧﺎﺻﺔ ﺑﺎﻟﺒﺘﺎﺕ ):(bitwize
ﻫﻲ ﳎﻤﻮﻋﺔ ﻣﻦ ﺍﳌﺆﺛﺮﺍﺕ ﺧﺎﺻﺔ ﺑﺎﻟﺒﺘﺎﺕ ،bitsﺗﻘﻮﻡ ﺑﺎﳌﻘﺎﺭﻧﺔ ﺑﲔ ﺑﺘﺎﺕ ﺑﺪﻝ ﺍﻟﺒﻴﺘﺎﺕ ،ﻭ ﻫﻲ ﻣﺸﺎﺑﻪ ﻟﻠﻤﺆﺛﺮﺍﺕ ﺍﻟﺴﺎﺑﻘﺔ. ﻧﺒﺪﺃ ﺑﺎﳌﺆﺛﺮ "ﺃﻭ" ORﻭ ﺍﻟﺬﻱ ﻫﻮ ﺍﻟﺮﻣﺰ | ﻭﺣﺪﻩ ،ﻭ ﻗﻠﻨﺎ ﺳﺎﺑﻘﺎ ﺃﻥ ﺍﳌﺆﺛﺮ "ﺃﻭ" ﳛﺘﺎﺝ ﺇﱃ ﺷﺮﻁ ﻭﺍﺣﺪ ﺻـﺤﻴﺢ ،ﺻـﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ:
ﺍﻟﺸﻜﻞ :١,٦,٣ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮ ﺃﻭ
| OR
ﺍﻟﻌﻤﻠﻴﺔ ﻫﻲ ﺇﺫﺍ ﻛﺎﻥ ﺑﺖ ﺑﻪ ﺍﻟﻘﻴﻤﺔ ٠ﻳﻘﺎﺭﻥ ﻣﻊ ﺑﺖ ﺑﻪ ﻗﻴﻤﺔ ٠ﻓﺴﻴﻜﻮﻥ ﺍﻟﻨﺎﺗﺞ ﺻﻔﺮ ﻷﻥ ﻛﻼ ﺍﻟﺒﺘﺎﺕ ﳛﺘﻮﻱ ﻋﻠﻰ ﺍﻟﻘﻴﻤـﺔ ٠ﺃﻱ ﺧﻄﺄ ،ﻭ ﺇﺫﺍ ﻛﺎﻥ ﺑﺖ ﺑﻪ ﺍﻟﻘﻴﻤﺔ ٠ﻳﻘﺎﺭﻥ ﻣﻊ ﺑﺖ ﺑﻪ ﺍﻟﻘﻴﻤﺔ ١ﻓﺴﻴﻜﻮﻥ ﺍﻟﻨﺎﺗﺞ ﻭﺍﺣﺪ ﻷﻧﻪ ﺗﻮﺟـﺪ ﺍﻟﻘﻴﻤـﺔ ١ﺃﻱ ﺻﺤﻴﺢ ﺣﻴﺚ ﻗﻠﻨﺎ ﺃﻥ ﺍﳌﺆﺛﺮ "ﺃﻭ" ﳛﺘﺎﺝ ﺇﱃ ﻗﻴﻤﺔ ﺻﺤﻴﺤﺔ ﻭﺍﺣﺪﺓ ﺣﱴ ﻳﻜﻮﻥ ﺍﻟﻨﺎﺗﺞ ﺻﺤﻴﺢ .ﻣﺜﺎﻝ: >#include<stdio.h )(main { int x = 1; /* 1 decimal = 00000001 Binary*/ ;x = x|4 /* 4 decimal = 00000100 Binary*/ */ = 00000101 Binary, x = 5 decimal*/ ;)printf("x = %d\n", x }
1 2 3 4 5 6 7 8 9
58
ﺍﻟﱪﻧﺎﻣﺞ :١,٦,١٣ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮ ﺃﻭ
| OR
ﺑﻌﺪ ﻫﺬﺍ ﺍﳌﺆﺛﺮ ﻳﺄﰐ ﺍﳌﺆﺛﺮ "ﻭ" ANDﻭ ﻳﻜﻮﻥ ﺑﺈﺳﺘﺨﺪﺍﻡ ﺍﻟﺮﻣﺰ & ،ﺻﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ:
ﺍﻟﺸﻜﻞ :١,٦,٤ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮ ﻭ
& AND
ﳛﺘﺎﺝ ﺍﳌﺆﺛﺮ "ﻭ" ﺇﱃ ﺃﻥ ﺗﻜﻮﻥ ﻛﻼ ﺍﻟﻘﻴﻤﺘﲔ ﺻﺤﻴﺤﺘﲔ ،ﺣﻴﺚ ﺇﺫﺍ ﻛﺎﻧﺖ ﻗﻴﻤﺔ ﺑﺖ ٠ﻭ ﻗﻴﻤﺔ ﺍﻟﺒﺖ ﺍﻟﺜـﺎﱐ ٠ﻓـﺴﻴﻜﻮﻥ ﺍﻟﻨﺎﺗﺞ ٠ﻷﻥ ﻛﻼ ﺑﺘﺎﺕ ﺧﺎﻃﺌﲔ ،ﻭ ﺇﺫﺍ ﻛﺎﻧﺖ ﻗﻴﻤﺔ ﺑﺖ ١ﻭ ﺍﻵﺧﺮ ٠ﻓﺄﻳﻀﺎ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ٠ﺃﻱ ﺧﺎﻃﺌﺔ ﻷﻥ ﺍﳌـﺆﺛﺮ "ﻭ" ﳛﺘﺎﺝ ﺇﱃ ﻗﻴﻤﺘﲔ ﺻﺤﻴﺤﺘﲔ ،ﺃﻣﺎ ﺇﺫﺍ ﻛﺎﻥ ﺑﺖ ١ﻭ ﺍﻵﺧﺮ ١ﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﻫﻨﺎ ١ﺃﻱ ﺻﺤﻴﺢ .ﻣﺜﺎﻝ: >#include<stdio.h )(main { int x = 1; /* 1 decimal = 00000001 Binary*/ ;x = x&4 /* 4 decimal = 00000100 Binary*/ */ = 00000000 Binary, x = 0*/ ;)printf("x = %d\n", x }
ﺍﻟﱪﻧﺎﻣﺞ :١,٦,١٤ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮ ﻭ
1 2 3 4 5 6 7 8 9
& AND
ﻭ ﺑﻌﺪ ﻫﺬﺍ ﺍﳌﺆﺛﺮ ﺳﻨﺮﻯ ﺍﳌﺆﺛﺮ ،XORﻭ ﻫﻮ ﻟﻴﺲ ﻛﺴﺎﺑﻘﻪ ،ﻭ ﻟﻜﻨﻪ ﻣﺸﺎﺑﻪ ﻟﻠﻤﺆﺛﺮ ORﺇﻻ ﺃﻧﻪ ﺳﻴﻜﻮﻥ ﺍﻟﻨﺎﺗﺞ ٠ﺇﺫﺍ ﻛـﺎﻥ ﻛﻼ ﺍﻟﺒﺘﺎﺕ ﺑﻪ ﺍﻟﻘﻴﻤﺔ ،١ﻭ ﺫﻟﻚ ﻋﱪ ﺍﻟﺮﻣﺰ ^ ،ﺻﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ:
ﺍﻟﺸﻜﻞ :١,٦,٥ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮ
^ XOR
59
ﻫﻨﺎ ﺇﺫﺍ ﻛﺎﻥ ﺑﺖ ﺑﻪ ﺍﻟﻘﻴﻤﺔ ٠ﻭ ﺍﻟﺜﺎﱐ ﺑﻪ ﺍﻟﻘﻴﻤﺔ ٠ﻓﺴﻴﻜﻮﻥ ﺍﻟﻨﺎﺗﺞ ،٠ﻭ ﺇﺫﺍ ﻛﺎﻥ ﺑﺖ ﺑﻪ ﻗﻴﻤﺔ ١ﻭ ﺍﻵﺧﺮ ﺑـﻪ ﺍﻟﻘﻴﻤـﺔ ٠ ﻓﺴﻴﻜﻮﻥ ﺍﻟﻨﺎﺗﺞ ،١ﺃﻣﺎ ﺇﺫﺍ ﻛﺎﻥ ﻛﻼ ﺍﻟﺒﺘﺎﺕ ﺑﻪ ﺍﻟﻘﻴﻤﺔ ١ﻓﺴﻴﻜﻮﻥ ﺍﻟﻨﺎﺗﺞ ٠ﺃﻱ ﺧﺎﻃﺊ ﻭ ﻫﺬﺍ ﻫﻮ ﺍﻟﻔﺮﻕ ﺑﲔ ﻫﺬﺍ ﺍﳌﺆﺛﺮ ﻭ ﻣﺆﺛﺮ .ORﻣﺜﺎﻝ: >#include<stdio.h )(main { int x = 4; /* 4 decimal = 00000100 Binary*/ ;x = x^4 /* 4 decimal = 00000100 Binary*/ */ = 00000000 Binary, x = 0*/ ;)printf("x = %d\n", x }
ﺍﻟﱪﻧﺎﻣﺞ :١,٦,١٥ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮ
1 2 3 4 5 6 7 8 9
^ XOR
ﻭ ﺃﺧﲑﺍ ﺍﳌﺆﺛﺮ "ﻻ" NOTﻋﱪ ﺍﻟﺮﻣﺰ ~ ،ﻭ ﻻ ﻳﺴﺘﻌﻤﻞ ﻫﺬﺍ ﺍﳌﺆﺛﺮ ﻟﻮﺣﺪﻩ ،ﻭ ﻳﺴﺘﻌﻤﻞ ﺑﻜﺜﺮ ﻣﻊ ﺍﳌﺆﺛﺮ "ﻭ" ANDﻟﺘﺜﺒﻴﺖ ﺑﺖ ﻣﺎ ﻋﻠﻰ ٠ﺑﺪﻭﻥ ﺍﻟﺘﺄﺛﲑ ﻋﻠﻰ ﺑﺎﻗﻲ ﺍﻟﺒﺘﺎﺕ .ﻭ ﻣﺜﺎﻻ ﻋﻠﻰ ﺫﻟﻚ ﺇﺫﺍ ﻛﺎﻥ ﻟﺪﻳﻦ ﺍﻟﻘﻴﻤﺔ ١ﰲ ﺑﺖ ﺛﺎﻟﺚ ﻧﺮﻳﺪ ﺗﺼﻔﲑﻩ ﻓﺴﻴﻜﻮﻥ ﺫﻟﻚ ﻛﺘﺎﱄ: >#include<stdio.h )(main { int x = 5; /* 5 decimal = 101 Binary*/ x = x& ~4; /* 4 decimal = 100 Binary*/ */ = 001 Binary, x = 1*/ ;)printf("x = %d\n", x }
١,٦,٦ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ:
ﺍﻟﱪﻧﺎﻣﺞ :١,٦,١٦ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮ ﻻ
ﻻ ﺗﻮﺟﺪ ﺃﺧﻄﺎﺀ ﳏﺘﻤﻠﺔ ﰲ ﻫﺬﺍ ﺍﻟﺪﺭﺱ.
١,٦,٧ﲤﺎﺭﻳﻦ: .١ﻫﻞ ﳝﻜﻦ ﺃﻥ ﻧﻘﻮﻡ ﺑﺎﻟﺘﺰﺍﻳﺪ ﻭ ﺍﻟﺘﻨﺎﻗﺺ ﺩﺍﺧﻞ ﺍﻟﺪﺍﻟﺔ printf؟ .٢ﻣﺎﺫﺍ ﺗﻌﲏ ﺍﻟﻘﻴﻤﺔ ٠ﻭ ﺍﻟﻘﻴﻤﺔ ١ﰲ ﺍﳌﺆﺛﺮﺍﺕ ﺍﻟﻌﻼﻗﻴﺔ ؟ .٣ﻣﺎﺫﺍ ﺗﻌﲏ ﻛﻞ ﻣﻦ && ﻭ || ﻭ ! ؟
~ NOT
1 2 3 4 5 6 7 8 9
60
ﺗﺴﺘﻌﻤﻞ ﺍﻟﻘﺮﺍﺭﺍﺕ )ﻭ ﳝﻜﻦ ﺗﺴﻤﻴﺘﻬﺎ ﺑﺎﳉﻤﻞ ﺍﻟﺸﺮﻃﻴﺔ( ﻟﻠﻤﻘﺎﺭﻧﺔ ﺑﲔ ﻋﻼﻗﺔ ﺣﻴﺚ ﺗﻜﻮﻥ ﺇﻣﺎ ﺻﺤﻴﺤﺔ ﺃﻭ ﺧﺎﻃﺌﺔ ،ﰲ ﻛﻞ ﻣﻦ ﺣﺎﻟﺔ ﳍﺎ ﺃﻭﺍﻣﺮ ﺧﺎﺻﺔ ﻧﻘﻮﻡ ﺑﺘﺤﺪﻳﺪﻫﺎ ،ﻣﺜﻼ ﺇﺫﺍ ﻛﺎﻧﺖ ﺍﳌﻘﺎﺭﻧﺔ ﺻﺤﻴﺢ ﻓﺴﻴﺘﻢ ﺗﻨﻔﻴﺬ ﺍﻷﻭﺍﻣﺮ ﺍﻟﱵ ﺣﺪﺩﻧﺎﻫﺎ ﰲ ﺣﺎﻟﺔ ﺃﻥ ﺍﳌﻘﺎﺭﻧﺔ ﺻﺤﻴﺤﺔ ،ﺃﻣﺎ ﺇﺫﺍ ﻛﺎﻧﺖ ﺍﳌﻘﺎﺭﻧﺔ ﺧﺎﻃﺌﺔ ﻓﺴﻴﺘﻢ ﺗﻨﻔﻴﺬ ﺍﻷﻭﺍﻣﺮ ﺍﳌﻌﺎﻛﺴﺔ. ١,٧,١ﺍﺳﺘﻌﻤﺎﻝ :if
ﻟﻜﻲ ﺗﻔﻬﻢ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻝ ifﺃﻟﻘﻲ ﻧﻈﺮﺓ ﻋﻠﻰ ﺍﻟﺼﻮﺭﺓ ﺍﻟﺘﺎﻟﻴﺔ:
ﺍﻟﺸﻜﻞ :١,٧,١ﻃﺮﻳﻘﺔ ﺇﻋﻼﻥ ﺷﺮﻁ ﺫﺍﺕ ﺃﻣﺮ ﻭﺍﺣﺪ ﺍﻟﺼﻮﺭﺓ ﺍﻟﺴﺎﺑﻘﺔ ﻳﻮﺟﺪ ﺎ ﻣﺜﺎﻝ ﺑﺪﻭﻥ ﺍﻟﺮﻣﺰ { ﻭ } ﻷﻧﻪ ﻻ ﻳﻮﺟﺪ ﺳﻮﻯ ﺃﻣﺮ ﻭﺍﺣﺪ ﻟﺘﻨﻔﻴﺬﻩ ،ﻭ ﻫﺬﻩ ﺻﻮﺭﺓ ﰲ ﺣﺎﻟﺔ ﻭﺟـﻮﺩ ﺃﻛﺜﺮ ﻣﻦ ﺃﻣﺮ:
ﺍﻟﺸﻜﻞ :١,٧,٢ﻃﺮﻳﻘﺔ ﺇﻋﻼﻥ ﺷﺮﻁ ﺫﺍﺕ ﻋﺪﺓ ﺃﻭﺍﻣﺮ ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;int usr_val ;)" printf("Enter a value: ;)scanf("%d", &usr_val
1 2 3 4 5 6 7 8
61
)if(usr_val 100 { ;)printf("%d are great than 100\n", usr_val }
ﺍﻟﱪﻧﺎﻣﺞ :١,٧,١ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ
}
9 10 11 12 13 14 15 16 17 18 19
if
ﰲ ﻫﺬﺍ ﺍﻟﱪﻧﺎﻣﺞ ﻃﻠﺒﻨﺎ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﻗﻴﻤﺔ ،ﰒ ﺍﺳﺘﻌﻤﻠﻨﺎ ﺍﻟﺸﺮﻁ ﺃﻭ ﺍﳌﻘﺎﺭﻧﺔ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﻌﺎﺷﺮ ﻭ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﻋﺸﺮ ﻭ ﻫﻮ ﺍﳌﻘﺎﺭﻧﺔ ﺑﲔ ﺍﻟﻘﻴﻤﺔ ﺍﻟﱵ ﺃﺩﺧﻠﻬﺎ ﺍﳌﺴﺘﺨﺪﻡ ﻭ ،١٠٠ﺇﺫﺍ ﻛﺎﻧﺖ ﺍﳌﻘﺎﺭﻧﺔ ﺻﺤﻴﺤﺔ ﻓﺴﻴﻘﻮﻡ ﺍﻟﱪﻧﺎﻣﺞ ﺑﺘﻨﻔﻴﺬ ﻣﺎ ﻫﻮ ﺩﺍﺧﻞ ﺍﻟـ blockﺍﳋﺎﺹ ﺑـ ،ifﻭ ﰲ ﺣﺎﻟﺔ ﺃﻥ ﺍﳌﻘﺎﺭﻧﺔ ﺧﺎﻃﺌﺔ ﻓﺴﻴﺘﻢ ﲡﺎﻫﻞ ﻣﺎ ﻫﻮ ﺩﺍﺧﻞ ﺍﻟـ blockﺍﻟﺬﻱ ﻳﻠﻲ .ifﻭ ﳝﻜـﻦ ﻛﺘﺎﺑﺔ ﺍﻟﱪﻧﺎﻣﺞ ﺬﻩ ﺍﻟﻄﺮﻳﻘﺔ: >#include<stdio.h )(main { ;int usr_val ;)" printf("Enter a value: ;)scanf("%d", &usr_val )if(usr_val 100 ;)printf("%d are great than 100\n", usr_val
ﺍﻟﱪﻧﺎﻣﺞ :١,٧,٢ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ (٢) if ﻷﻧﻪ ﰲ ﻛﻼ ﺍﻟﺸﺮﻃﲔ ﻻ ﻳﻮﺟﺪ ﻤﺎ ﺇﻻ ﺃﻣﺮ ﻭﺍﺣﺪ.
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
١,٧,٢ﺍﺳﺘﻌﻤﺎﻝ :else
ﺗﺴﺘﻌﻤﻞ ﺍﻟﻜﻠﻤﺔ elseﻣﻊ ﺍﻟﻜﻠﻤﺔ ifﺩﺍﺋﻤﺎ ﺣﻴﺚ ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﳍﺎ ﻟﻮﺣﺪﻫﺎ ،ﺳـﻨﻜﺘﺐ ﺍﻵﻥ ﺍﻟﱪﻧـﺎﻣﺞ ﺍﻟـﺴﺎﺑﻖ ﺑﺎﺳﺘﺨﺪﺍﻡ :else >#include<stdio.h )(main {
1 2 3 4
62 ;int usr_val ;)" printf("Enter a value: ;)scanf("%d", &usr_val )if(usr_val#include<stdio.h
1 2
63 )(main { ;int usr_val ;)" printf("Enter a value: ;)scanf("%d", &usr_val )if(usr_val