tailieunhanh - Lecture Introduction to computer and programming - Lecture No 26

The contents of this chapter include all of the following: Functions and the lambda calculus; haskell: Introduction, expressions, lists and list comprehensions, elementary types and values, control flow, defining functions, tuples. | CSC103: Introduction to Computer and Programming Lecture No 26 Previous lecture Pointer to a structure Dynamic memory allocation for structure Passing a structure to a function Today’s lecture outline Example program – structure C preprocessor directives Macro expansion File inclusion Conditional Compilation Example Program Create a structure to specify data on students given below: Roll number, Name, Department, Course, Year of joining Create a variable of that structure, input value from user and then display those values. Write a program Preprocessor directive Preprocessor directives are the special instruction to C compiler Preprocessor directive are resolved before compilation of program Each preprocessor directive begins with # and can be placed anywhere in the program Following preprocessor directives are used mostly Macro expansion File inclusion Conditional Compilation Macro expansion Preprocessor Macro definition Cont. && || Cont. A #define directive could be used to replace a condition Cont. A #define directive could be used to replace an entire C statement. Macros with Arguments Preprocessor Multi line marcos Go to program Macros versus Functions It seams that macro calls are ‘like’ function calls, they are not really the same things In a macro call the preprocessor replaces the macro template with its macro expansion In function call control is transferred to a function, function do processing and then control is returned back Macro call and expansion Cont. when is it best to use macros with arguments and when is it better to use a function Usually macros make the program run faster but increase the program size whereas functions make the program smaller and compact . if we used macro 100 times, then macro expansion goes in source code 100 time before compilation process If a function is called 100 times, it will make same amount of space in the program Cont Conclusion: If macro is simple and small than it can be used to avoid function calls . | CSC103: Introduction to Computer and Programming Lecture No 26 Previous lecture Pointer to a structure Dynamic memory allocation for structure Passing a structure to a function Today’s lecture outline Example program – structure C preprocessor directives Macro expansion File inclusion Conditional Compilation Example Program Create a structure to specify data on students given below: Roll number, Name, Department, Course, Year of joining Create a variable of that structure, input value from user and then display those values. Write a program Preprocessor directive Preprocessor directives are the special instruction to C compiler Preprocessor directive are resolved before compilation of program Each preprocessor directive begins with # and can be placed anywhere in the program Following preprocessor directives are used mostly Macro expansion File inclusion Conditional Compilation Macro expansion Preprocessor Macro definition Cont. && || Cont. A #define directive could be used to replace

TỪ KHÓA LIÊN QUAN