C for macro4/7/2023 Generally for macros, use of Capital Letters makes programmers easy to pick while going through the program. Whenever the program sees a #define directive, it searches for the macro template over the entire program, and replaces with the physical value there. Macros make it easy to replace the required value. Today you may limit the value of pi to 3.141, but might want to change it tomorrow to 3.141592653589 for more accuracy. The program replaces the instances of the word PI in program by the number 3.141. In the above program, since the value of PI is universally same, it can be defined with the help of pre-processor. Printf("The area of circle is %f\n", area) The following video will help you understand Macros with the help of its use in a program. During pre-processing, the program replaces all NO_OF_STUDENTS by the number defined with it. Such statements are often called as macro definitions or simply macros. Thus, we avoid the problem of missing out update at some places and the code also becomes to maintain and work upon. Now, anytime the number of students change, we just have to make the change at one place and it will be reflected everywhere. In the above code, what we have is a name for the value, for the number of students. Printf ("Student %d has an average of %d\n",i 1,avg) And the program is written to calculate the average mark obtained by each student. Let us look at macro expansion through an example. That is because, to define a macro, we use the statement “ #define”
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |