Article by: Manish Methani
Last Updated: September 23, 2021 at 8:04am IST
Comments and identifiers are crucial elements in C programming. Comments are used to add notes and explanations in the source code, while identifiers are used to give names to various programming elements such as variables, functions, and arrays.
Here's a step-by-step tutorial to help you understand how to use comments and identifiers in C programming:
Comments in C programming are used to add notes or explanations in the source code. Comments are ignored by the compiler and have no effect on the execution of the program. They are simply there to make the code more readable and understandable.
There are two types of comments in C programming:
// This is a single-line comment
/* This is a multi-line comment that can span multiple lines */
Identifiers in C programming are used to give names to various programming elements such as variables, functions, and arrays. Identifiers must follow certain rules in C programming, including:
Here are some examples of valid identifiers in C programming:
int age; float temperature; char first_name[20]; void calculate_discount();
Now that you understand the basics of comments and identifiers in C programming, let's see how you can use them in your programs.
#include <stdio.h> // This is a global variable int num; int main() { // This is a local variable int count = 0; /* This is a multi-line comment that explains what the program does */ // Increment the count variable count++; printf("The value of count is %d", count); return 0; }
In this example, we have used comments to explain the purpose of the program and to provide more information about the variables. We have also used identifiers to give names to the variables and the function.
In conclusion, comments and identifiers are essential components in C programming. Comments help to explain the code and make it more readable, while identifiers give names to various programming elements. By following this tutorial, you have learned the basics of comments and identifiers in C programming and how to use them effectively in your programs.