![]() This practice will prove to be very advantageous while writing big programs. Note: It’s always considered best practice to either use macros or constant variables to assign array size. Now instead of editing at multiple places, we only change the value of constant variable N from 5 to 7, and the program works as intended. Output: Enter 7 integer numbers 1 2 3 4 5 6 7 Array elements are: 1 2 3 4 5 6 7Īssume that the requirement changes and the client wants a list size of 7. Without using Macros and/or constants #include After the macro is defined, the compiler can substitute the token string for each occurrence of the identifier in the source file. YouTube Link: Source Code: Size of Array using Macro and Constant: C Program The define creates a macro, which is the association of an identifier or parameterized identifier with a token string. Video Tutorial: Assign Size of Array using Macro and Constant: C Program Watch the video below for demonstration of effectiveness of using macros and constants for assigning size of an array. ![]() You can make the change at one place and it’ll take effect at all the places in your source code. It’ll take unnecessary time and effort to make it work correctly once again.īy making use of Macros or constant variables you can handle this very efficiently. ![]() Even if you skip changing the array size information at one place, you’ll start getting wrong results.Īnd if you have any business logic which makes use of array size, then you’ll have hard time rectifying and debugging the code. If requirement of the program/software changes and you need to increase or decrease the array size, then you’ll have to be very careful and scan through the entire source code and make changes at multiple locations. Source Code: Size of Array using Macro and Constant: C Programĭisadvantage of Not Using Macro or Constant To Assign Array Size.Video Tutorial: Assign Size of Array using Macro and Constant: C Program.Disadvantage of Not Using Macro or Constant To Assign Array Size.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |