C Variable definition and declaration


C Variable definition and declaration

A variable is nothing more than a name for a storage region that our programmes can access. Each variable in C has a type that governs the memory size and layout, the range of values that can be stored inside that memory, and the operations’ set that you may apply to the variable.

Letters, numerals, and the underscore character can all be used in a variable's name. Either a letter or an underscore must be used as the first character. Because C is case-sensitive, lowercase and uppercase letters are distinct in it.

Definition of Variables in C

A variable definition instructs the compiler where to store the variable and how much of it to create. A variable definition describes a data type and lists one or more variables of that kind.

Declaration of Variables in C

A variable declaration assures the compiler that a variable of the provided type and name exists, allowing the compiler to continue compiling without needing to know all of the details about the variable. Only at the time of compilation does a variable definition have any meaning; at the time of linking the programme, the compiler need the real variable definition.

When using multiple files, a variable declaration is handy because you can specify your variable in one of the files that will be available when the programme is linked. The keyword extern will be used to declare a variable at any time. A variable can be declared numerous times in a C programme, but it can only be defined once in a file, a function, or a block of code.

Definition and Declaration of Variables in C

#include<stdio.h> #include<conio.h> void main() { char ab12='q'; /* declaration and definition of variable ab12 */ float c; /* this is also declaration and definition of variable */ printf("%d ", ab12); /* print a variable */ getch(); }

output:

q