stddef
1. Null Pointer
void* ptr = nullptr;Explanation: Sets ptr to a null pointer, indicating it does not point to any valid memory location.
2. Size of Data Type
size_t size = sizeof(int);Explanation: Gets the size of the int data type in bytes.
3. Alignment Requirements
ptrdiff_t align = alignof(double);Explanation: Gets the alignment requirements for the double data type, which indicates the minimum byte boundary on which it can be stored.
4. Pointer Arithmetic
int* ptr = new int[10];
ptr += 5;
*ptr = 10; // Assigns 10 to the 6th elementExplanation: Pointer arithmetic allows you to increment or decrement a pointer to access different elements in an array.
5. Pointer to Function
int sum(int a, int b) { return a + b; }
int (*ptr_to_sum)(int, int) = ∑
int result = ptr_to_sum(3, 5); // Calls the `sum` function through the pointerExplanation: A pointer to a function points to the memory location where the function code is stored.
6. Pointer to Member Function
Explanation: A pointer to a member function points to a specific member function of a class.
7. Type Trait: is_same
Explanation: Checks if two types are the same. In this example, int and int are the same type.
8. Type Trait: is_integral
Explanation: Checks if a type is an integral type, such as int, long, or short.
9. Type Trait: is_floating_point
Explanation: Checks if a type is a floating-point type, such as float or double.
10. Type Trait: is_array
Explanation: Checks if a type is an array type.
11. Type Trait: is_pointer
Explanation: Checks if a type is a pointer type.
12. Type Trait: is_reference
Explanation: Checks if a type is a reference type.
13. Type Trait: remove_reference
Explanation: Removes the reference from a type. In this example, it gets the type int from the reference type int&.
14. Type Trait: remove_pointer
Explanation: Removes the pointer from a type. In this example, it gets the type int from the pointer type int*.
15. Type Trait: remove_const
Explanation: Removes the const qualifier from a type. In this example, it gets the type int from the constant type const int.
16. Type Trait: remove_volatile
Explanation: Removes the volatile qualifier from a type. In this example, it gets the type int from the volatile type volatile int.
17. Type Trait: decay
Explanation: Gets the decayed type of a type. In this example, it gets the pointer type int* from the array type int[10].
18. Zero Initialization
Explanation: Initializes all elements of an array to zero.
19. Constant Initialization
Explanation: Initializes a variable with a constant value.
20. Template Metaprogramming
Explanation: Computes the value of 2n using template metaprogramming.
21. Fixed-size Buffer
Explanation: Creates a fixed-size array with a specified number of elements.
22. Dynamic Array
Explanation: Creates a dynamic array that can grow and shrink as needed.
23. Linked List
Explanation: Implements a linked list data structure.
24. Binary Tree
Explanation: Implements a binary tree data structure.
25. Hash Table
Explanation: Implements a hash table data structure for storing key-value pairs.
26. Bit Manipulation
Explanation: Performs bitwise operations on integers.
27. Thread-safe Data Structure
Explanation: Creates a thread-safe data structure using the std::atomic class.
28. Multi-Threading
Explanation: Creates a new thread that executes a specified function.
29. Deadlock Prevention
Explanation: Prevents deadlocks by using a lock and a lock guard.
30. Memory Management
Explanation: Manually manages memory allocation and deallocation.
31. File Handling
Explanation: Opens files for reading and writing.
32. Input/Output Streams
Explanation: Reads input from and writes output to the standard input/output streams.
33. Regular Expressions
Explanation: Matches input strings against a regular expression.
34. String Manipulation
Explanation: Manipulates strings using the std::string class.
35. Date and Time
Explanation: Gets the current time as a timestamp.
36. Localization
Explanation: Sets the locale for localized formatting and parsing.
37. Math Functions
Explanation: Provides access to mathematical functions like trigonometric functions and constants.
38. Random Number Generation
Explanation: Generates pseudo-random numbers using the standard random number generator.
39. Sorting
Explanation: Sorts a container using the standard sort algorithm.
40. Searching
Explanation: Searches for an element in a container using a linear search.
41. Algorithm Execution
Explanation: Executes a function for each element in a container using the standard for_each algorithm.
42. Iterators
Explanation: Iterates over a container using iterators.
43. Function Objects
Explanation: Creates a function object that can be treated as a function.
44. Lambda Expressions
Explanation: Creates a lambda expression that represents a function.
45. Exception Handling
Explanation: Catches and handles runtime errors.
46. Assertion
Explanation: Checks a condition and terminates the program if the condition is false.
47. Preprocessor Macros
Explanation: Defines a preprocessor macro that can be used in code.
48. Conditional Compilation
Explanation: Selectively compiles code based on preprocessor conditions.
49. Inline Assembly
Explanation: Inserts inline assembly code into the C++ code.
50. Platform-Specific Code
Explanation: Writes platform-specific code using preprocessor conditionals.