C-Programming Operators and Keywords
C Operators, Keywords and the Preprocessor
An operator is a symbol that performs some operation on one or more operands. Operators are used to assign values, compare values or perform calculations with values.
Keywords (or) Reserved Words
Keywords or reserved words are words that have a special meaning in a programming language. They are reserved by the compiler and cannot be used as variable names, function names, class names, etc.
Keywords can be classified as:
Pre-defined data types
User-defined data type
Words used in C programs are either keywords or identifiers.
Identifiers are names given to entities in a program like variables, functions, constants, etc. They are used to identify these entities.
Some rules for identifiers in C are:
An identifier must start with the letter A-Z, a-z or underscore ( _ ).
After the first character, identifiers can contain letters, digits and underscore.
Identifiers are case-sensitive. age and Age are two different identifiers.
Keywords cannot be used as identifiers.
Identifiers cannot start with a digit.
Some valid identifiers:
Some invalid identifiers:
1age - starts with a digit
class - is a keyword
func# - contains special character #
The C preprocessor is a text substitution tool that performs macro definition, macro expansion, file inclusion, and conditional compilation. It is not part of the compiler itself but rather a separate step in the compilation process.
The preprocessor uses directives that start with # to instruct the compiler to perform required preprocessing before actual compilation. Using the preprocessor has the following advantages:
It makes programs easier to develop by:
Allowing macro definitions to reduce redundant code
Allowing file inclusion to split large programs into multiple files
It makes programs easier to read and maintain by:
Using macros and #defines for constants
Giving variables and functions meaningful names
It makes programs easier to modify by:
Allowing conditional compilation to compile different versions
Allowing macro parameters to change behaviour
|Used to define a macro
|Used to undefine a macro
|Used to include a file in the source code program
|Used to include a section of code if a certain macro is defined by #define
|Used to include a section of code if a certain macro is not defined by #define
|Check for the specified condition
|Alternate code that executes when #if fails
|Used to mark the end of #if, #ifdef, and #ifndef
Defines a macro substitution. It performs simple textual substitution of the macro name before actual compilation.
#define macro_name replacement_text
#define PI 3.14
#define square(x) x*x
Used to insert the contents of a header file into the source code at the location of the #include statement.
#include <filename> // For system header files
#include "filename" // For user-defined header files
Allows splitting large programs into multiple files.
Header files contain function prototypes and macro definitions that are shared across multiple source files.
Did you find this article valuable?
Support Vishesh Raghuvanshi by becoming a sponsor. Any amount is appreciated!