In C programming, Comments are used to explain, describe, or annotate parts of the code for human readers, making the code easier to understand and maintain. Comments are ignored by the compiler and do not affect the program’s execution.
There are two types of Comments in C
Single-line comment
This comment starts with //. Everything after // on that line is treated as a comment.
Example:
// This is a single-line comment
printf("Welcome techfliez.com");
Multi-line comment
This comment begins with /* and ends with */. Everything between these symbols is treated as a comment, even if it spans multiple lines.
/* This is a multi-line comment
show welcome message
*/
printf("Welcome techfliez.com");
Note: It is used for longer explanations or to temporarily disable parts of code.
C Comments – Interview Questions
Q 1: What are comments in C?
Ans: Comments are non-executable statements used to explain code.
Q 2: How many types of comments are there in C?
Ans: Two types: single-line (//) and multi-line (/* */).
Q 3: Are comments executed by the compiler?
Ans: No, comments are ignored during compilation.
Q 4: Can comments improve code readability?
Ans: Yes, comments help developers understand and maintain code.
Q 5: Can we use comments inside a function?
Ans: Yes, comments can be used anywhere in a C program.
C Comments – Objective Questions (MCQs)
Q1. Which of the following is a valid single-line comment in C?
Q2. Which of the following is a valid multi-line comment in C?
Q3. Can comments be nested in C (a comment inside another comment)?
Q4. What happens to comments when a C program is compiled?
Q5. Which of the following is not a valid comment in C?