1. C Programming for Beginners: Writing Your First Hello World Program in C in 2023 2. Mastering Datatypes in C Programming: A Comprehensive Guide for Beginners in 2023 3. Complete Guide to % Format Specifiers in C for Beginners in 2023 4. A Comprehensive Guide to Operators in C Programming: Learn Everything About Operators in C in 2023 5. Master C Operator Precedence and Associativity in 2023: Definition, Examples, and Code 6. Learn Increment and Decrement Operators in C: A Beginners Guide with Examples - Codzify 7. Mastering Bitwise Operators in C: A Comprehensive Guide with Examples - Codzify 8. Ternary Operators in C Programming: A Beginners Guide (2023) 9. Switch Statements in C 2023: Complete Guide for Beginners 10. Learn Functions in C Programming - A Complete Tutorial for Beginners in 2023 11. Call by Value and Call by Reference in C Programming - A Complete Tutorial for Beginners in 2023 12. Storage Classes in C Programming: A Comprehensive Guide for 2023 13. Arrays in C Programming: A Comprehensive Guide for 2023 14. Basics of 2D Array in C Programming in 2023: Definition, Initialization, and Accessing Elements 15. Beginners Guide to Strings in C Programming with Codes and Examples 16. Strings Functions in C Language - strlen, strcpy,strcmp,strcat functions 17. A Comprehensive Guide to Structures in C Programming in 2023 18. Learn Unions in C Programming with Codes, Examples, and Explanations in 2023 19. Dynamic Memory Allocation in C: Understanding malloc, calloc, realloc, and free Functions 20. Introduction to C Programming 21. Hello world program in C 22. String functions in C - strncat, strcpy, strncpy, strchr, strrchr, strstr functions 23. Program for Fibonacci number in C - Codzify.com 24. What is palindrome number in C? 25. Write a C program to find a factorial of a given number 26. Write a C program to check whether a given number is prime or not 27. Write a C program to check whether a given number is an Armstrong number or not. 28. Write a C Program to transpose a matrix 29. C Programming Tutorial: Understanding Comments and Identifiers with Code Examples 30. Master String Handling Functions in C in 2023 - Codzify Topics

C Programming Tutorial: Understanding Comments and Identifiers with Code Examples

Article by: Manish Methani

Last Updated: September 23, 2021 at 8:04am IST
3 min 7 sec

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:

Step 1: Understanding Comments

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:

  • Single-line comments: These comments start with "//" and continue until the end of the line.
// This is a single-line comment
  • Multi-line comments: These comments start with "/" and end with "/". Multi-line comments can span multiple lines.
/*
This is a multi-line comment
that can span multiple lines
*/

Step 2: Understanding Identifiers

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:

  • Identifiers can only contain letters, digits, and underscores.
  • Identifiers must begin with a letter or an underscore.
  • Identifiers are case sensitive.

Here are some examples of valid identifiers in C programming:

int age;
float temperature;
char first_name[20];
void calculate_discount();

Step 3: Using Comments and Identifiers in C Programming

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.

 

Explore Tech Guide:

Codzify Logo

Terms and Conditions    Cookie Policy   Refund Policy   Adsense Disclaimer

Contact: teamcodzify@gmail.com