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
What is the use of generic pointers in c?discuss with the help of an example?
Why there is no virtual constructor in C++? Illustrate with example.
Define a class template. When would a programmer want to use class templates in C++?
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
- What Ada construct provides support for abstract data types?arrow_forwardWhen 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_forwardGive brief definitions of formal interfaces, information hiding, encapsulation, and abstraction. Show examples of how these ideas are used in C++ classes and objects. Modifiers for access should be included in your analysis.arrow_forward
- What is the use of generic pointers in c?discuss with the help of an example? Computer sciencearrow_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_forwardParagraph-length clarifications of abstraction, encapsulation, information hiding, and formal interfaces, please. The use of these concepts in C++ classes and objects has to be explained. Be sure to factor in access modifiers in your calculations.arrow_forward
- Compare the advantages of early type binding in C and Java to the advantages of late type binding in languages such as JavaScript and python (type less languages). (Give short answer) Like for the correct answer.arrow_forwardWhat causes a C++ template function to be instantiated?arrow_forwardWhich is preferred when referencing subprograms, variables, and objects in code—fully qualified or unqualified references? An explanation of the problems with basic encapsulation in C and how they affect C++.arrow_forward
- How does data binding work in reactive programming paradigms like RxJS or Kotlin Flow? Explain the benefits of using reactive data binding in modern application development.arrow_forwardIn a single paragraph, please elaborate on the concepts of abstraction, encapsulation, information hiding, and formal interfaces. The use of these concepts in C++ classes and objects has to be explained. Don't forget to factor in access modifiers.arrow_forward
arrow_back_ios
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