What is variable? How is it different from constant? How do you write comments in c?

This answer is restricted. Please login to view the answer of this question.

Login Now

variable is a name of the memory location. It is used to store data. Its value can be changed, and it can be reused many times.

It is a way to represent memory location through symbol so that it can be easily identified.

Syntax:

type variable_name;

Example:

int a;  
float b;  
char c;

The difference between variable and constant are

Variables Constants
It is a variable that stores data type value in a program. It is similar to a variable and cannot be changed during program execution.
It is a variable that can be changed after defining the variable in a program It is a fixed variable that cannot be changed after defining the variable in a program.
The value of a variable can change depending on the conditions. In constants, the value cannot be changed.
Typically, it uses int, float, char, string, double, etc. data types in a program. It can be express in two ways: #define pre-processor and the const keyword.
Example: int a = 5; float radius = 5.2; char ‘A’; Example: const int Len = 5;
#define PI 3.14

comment is an explanation or description of the source code of the program. It helps a developer explain logic of the code and improves program readability. At run-time, a comment is ignored by the compiler.

There are two types of comments in C:

  1. A comment that starts with a slash asterisk /* and finishes with an asterisk slash */ and you can place it anywhere in your code, on the same line or several lines.
  2. Single-line Comments which uses a double slash // dedicated to comment single lines

Single Line Comment

// This is single line comment example

Multi Line Comment

/* Sample Multiline Comment
Line 1
Line 2
….
…
*/

 

If you found any type of error on the answer then please mention on the comment or report an answer or submit your new answer.
Leave your Answer:

Click here to submit your answer.

Discussion
0 Comments
  Loading . . .