Welcome to our comprehensive guide on C Predefined Macros! This lesson is designed to help you understand one of the powerful features of the C programming language. By the end of this lesson, you'll be able to use predefined macros confidently in your code. Let's get started!
In C programming, macros are text replacements that allow you to define shortcuts for frequently used code segments. Predefined macros are provided by the C standard library and can be very useful in writing efficient, readable, and maintainable code.
Here are some commonly used predefined macros in C programming:
sizeof to determine the size of a data type#include <stdio.h>
int main() {
int myInt = 10;
float myFloat = 3.14;
printf("Size of an int: %ld bytes\n", sizeof(int));
printf("Size of a float: %ld bytes\n", sizeof(float));
return 0;
}__func__, __LINE__, and __FILE__ for debugging#include <stdio.h>
void myFunction() {
printf("Function: %s\n", __func__);
printf("Line: %d\n", __LINE__);
printf("File: %s\n", __FILE__);
}
int main() {
myFunction();
return 0;
}What does the `NULL` predefined macro represent?
By understanding and using predefined macros, you'll be well on your way to writing efficient and maintainable C code! Happy coding! 💻🚀