Enumerated Data Type
Enumerated Data Type
Definition: Enumerated data types in C/C++ allow you to define a set of named
constants representing integer values.
Syntax: Declared using the enum keyword followed by a list of identifiers enclosed in
curly braces.
Example:
Usage: Provides a way to create symbolic names for integer values, improving code
readability and maintainability.
Macro Expansion
Definition: Macro expansion is the process where a macro is replaced with its actual
code during the preprocessing stage.
Syntax: Defined using #define directive followed by the macro name and its
replacement text.
Example:
#define SQUARE(x) (x * x)
Usage: Macros are used for code reusability, avoiding repetitive code, and creating
constants or simple functions.
File Inclusion
Definition: File inclusion is a mechanism in C/C++ that allows you to include the
contents of one file in another file during compilation.
Directives: In C, #include directive is used to include header files or other source files.
Example:
Purpose: Facilitates code organization, reuse, and modularity by allowing the use of
functions, constants, and declarations from other files.
These notes provide a brief overview of enumerated data types, macro expansion, and
file inclusion in C/C++ programming.
Example Code
Here's an example of how bitwise shift operators are used in C:
#include <stdio.h>
int main() {
int result ;
return 0;
9. What is macro? Explain the difference between object macro and function macro with example.
10. Explain the use of bitwise operators in programming with suitable example.
#define PI 3.14159
Function Macro: A function macro is a macro that defines a function-like behavior. For
example:
#define SQUARE(x) (x * x)
#include <stdio.h>
int main() {
unsigned int num = 5; // Binary: 0101
return 0;
Conditional Directives
Conditional directives in C/C++ are used to include or exclude portions of code based
on certain conditions during compilation. These directives, such
as #ifdef, #ifndef, #if, #else, and #endif, allow for conditional compilation, enabling
developers to write code that is specific to different environments or configurations.