EBK DATA STRUCTURES AND ALGORITHMS IN C
4th Edition
ISBN: 9781285415017
Author: DROZDEK
Publisher: YUZU
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
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.
- Example: A sorting function does not bother the type of data it is sorting, since the applied
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.
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
Can you explain DMA for object and array of object in C++ with an easy short example?I am having a hard time understanding it.
Explore the concept of custom operator overloading in C++ and its implications for creating user-defined data types with unique behaviors. Provide an example of such an implementation.
Define a function template in C++. When would a programmer want to use function templates?
Chapter 1 Solutions
EBK DATA STRUCTURES AND ALGORITHMS IN C
Knowledge Booster
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
- Why there is no virtual constructor in C++? Illustrate with example.arrow_forwardLearn about weak references in Java. How do they interact with garbage collection? How do they compare to weak_ptr objects in C++? Describe several scenarios in which they may be useful.arrow_forwardExplain in more detail why C++ only allows arrays to be passed as reference parameters.arrow_forward
- Develop a function template in C++ that would sort an array of the data types that are provided.arrow_forwardExplain the type of inheritances with C++ code.arrow_forwardDiscuss the impact of function objects on performance, especially when used heavily in languages that don't optimize for functional constructs.arrow_forward
- Explain Abstract Data Type and briefly explain how we can achieve ADT in C++.arrow_forwardEach of abstraction, isolation, information hiding, and formal interfaces should be explained in a single paragraph. Explain how these ideas are used in classes and objects in C++. When doing your research, you should think about access factors.arrow_forwardExplain the type of inheritance in C++ with code.arrow_forward
- When referring to coded components like subprograms, variables, and objects, is it better to use fully qualified references or unqualified references? Issues with C's primitive encapsulation and how they influenced C++ are discussed.arrow_forwardwrite code Give a C++ code example showing the concept of software reusability. Give an example of polymorphism in C++ code using the concept of virtual functions, late binding and overriding.arrow_forwardWhy the distinction between primitive and reference types? Why not just have reference types?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education