Q. Why we use macros?
Ans. First of all What is macros?
Macros are used to define something before the execution starts and its values are never changed during the execution.
Ex: in c/c++
#define max_size 100
#ifndef
#include<something.h>
#end if
Imagine the scenario you write a program where you assume the size of the input to 1000 at max and u use every where 1000 . Then some one asked you to modify that program for 10000 elements then you have to go to all places where you write that 1000 and replaced it by 10000 instead of that we can use macros we define variable in starting outside the main function and use that variable in our function if some one asked to change the size we change only that variable and the changes at all the places are taken care of automatically.
Macros are predefine variables or function. Compiler replaces all the macros in its pre processing with its corresponding values in the entire program.
Ans. First of all What is macros?
Macros are used to define something before the execution starts and its values are never changed during the execution.
Ex: in c/c++
#define max_size 100
#ifndef
#include<something.h>
#end if
Imagine the scenario you write a program where you assume the size of the input to 1000 at max and u use every where 1000 . Then some one asked you to modify that program for 10000 elements then you have to go to all places where you write that 1000 and replaced it by 10000 instead of that we can use macros we define variable in starting outside the main function and use that variable in our function if some one asked to change the size we change only that variable and the changes at all the places are taken care of automatically.
Macros are predefine variables or function. Compiler replaces all the macros in its pre processing with its corresponding values in the entire program.
No comments:
Post a Comment