EBK DATA STRUCTURES AND ALGORITHMS IN C
EBK DATA STRUCTURES AND ALGORITHMS IN C
4th Edition
ISBN: 9781285415017
Author: DROZDEK
Publisher: YUZU
bartleby

Concept explainers

Question
Book Icon
Chapter 1, Problem 7E
Program Plan Intro

Templates and Macros:

Macros:

  • A macro can be stated as a string that compiler would replace with the defined value.
    • Example: #define STRING "Value"
  • Macros are not safe type, that is, float data is not accepted by a macro that is defined for integer operations. Type checking is not performed while expansion.
  • Finding errors in macros is difficult.
  • When a variable is post incremented or decremented, operation is been performed twice.

Templates:

  • A template is a way of making functions with independency in data type. Macros could not accomplish this task.
    • Example: A sorting function does not bother the type of data it is sorting, since the applied algorithm is same.

Syntax for Templates and Macros:

The syntax for template definition is shown below

Syntax for template:

template <class type>

type class-name<type>:: macro_name(arguments)

{

}

The syntax for macro definition is shown below

Syntax for macro:

#define macro_name replacement-text

return-type main()

{

  Variable-name = macro_name(arguments);

}

Expansion is performed twice for the above macro. It denotes a limitation of macros. All occurrences of macro in file would be replaced by “replacement-text” before compilation of program. The template removes the macro limitations.

Blurred answer
Students have asked these similar questions
Information Security Risk and Vulnerability Assessment 1- Which TCP/IP protocol is used to convert the IP address to the Mac address? Explain 2-What popular switch feature allows you to create communication boundaries between systems connected to the switch3- what types of vulnerability directly related to the programmer of the software?4- Who ensures the entity implements appropriate security controls to protect an asset?         Please do not use AI and add refrence
Find the voltage V0 across the 4K resistor using the mesh method or nodal analysis. Note: I have already simulated it and the value it should give is -1.714V
Resolver por superposicion
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
CMPTR
Computer Science
ISBN:9781337681872
Author:PINARD
Publisher:Cengage
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT