C tutorial - Keywords, Constant, Variables and rules for variable declaration in C programming language

Programming languages or concepts

Understanding Keywords, Constants, Variables, and Rules of Variable Declaration in C Programming Language


Keywords, constants, and variables are essential concepts in the C programming language. Keywords are reserved words with specific meanings in the language. Constants represent fixed values that do not change during program execution. Variables, on the other hand, are named memory locations used to store and manipulate data. In C, variables must be declared before they can be used, following certain rules and guidelines. This article provides a comprehensive overview of keywords, constants, variables, and the rules for variable declaration in C, aiming to enhance understanding and usage of these fundamental concepts.

 Keywords:- 

           Keywords are the reserved words in c.
  Keywords are must be written in small case otherwise the meaning of which would be changed.
     Definition and significance of keywords in C.
   - Examples of commonly used keywords in C.
   - The expansion of keywords in the ANSI C standard, including C11 additions.

auto.                                              goto
break.                                            for
case.                                               float
char.                                              while
const.                                             volatile
continue.                                       void
default.                                          unsigned
do.                                                   if
double.                                           union
else.                                                 typedef
enum.                                             switch
extern.                                            stract
int.                                                   static
long.                                                sizeof
register.                                          signed
return.                                             short

Addition keywords of C11 is 

inline                          _Alignas
_Alignof.                    _Bool
_Complex.                 _Generic
_Noretum.                _static_assert
_Automic.                 _Imaginary
_Thread_local

Constant:

 
   - Explanation of constants and their role in programming.
   - Differentiating between primary and secondary constants.
   - Examples of constant usage in C programs.
 

 C Constant divide into two types.
 1) Primary Constant.
 2) Secondary Constant.

Variables:-

A variable is a name for a piece of memory in the Random Access Memory (RAM) which can used to store and access the data. The value stored in the allocated memory may change as the program execution progresses so called variable.
 Variable is used to store the value.
 As name indicates it value can be changed or also it can be reused many times.

Syntax:-
            Data type  Variable_name;
 eg. 
         int a;


Types of Variable in c:-

1) Local variable
2) Global variable
3) Static variable
4) External variable
5) Automatic variable

1) Local variable:-
         A variable which is declared inside the function is known as local variable.
       It is used only inside the program 

2) Global variable:-
      A variable is declared outside the program is known as global variable.
    Global variable is used all over the program.

3) static variable:-
     static is a keyword . Static variable is declared using static keywords.

4) External variable:-
     We can share a variable in multiple C source files by using external variable.
     It is declared using external keyword.

5) Automatic variable:-
    Variable which is declared inside the block is known as Automatic variable by default.

Rules to declare variable in C:-

In we can declared variable for declared variable we need to follow rules and regulations.
This Rules and Regulations are listed  below


  • In c Every Variable name should start with alphabets or underscore.
     Ex. int alph;.         
     Ex. int _underscore;

  • In variable declared spaces are not allowed.
  • Keywords are not allowed as a variable.
  • Every variable name always should exist in the left hand side of assignment operators.
  • Length of variable is depending on compiler and  operating system but maximum size of variable is 8.
  • Information middle of variable declaration special symbols are not allowed except underscore (_).
Variable declaration in c
Variable declaration is a process to allocate required memory space for the data in form of variable.

Syntax for declaration of variable
     Data type variable_name;

Ex. int a;


Conclusion:
Understanding keywords, constants, variables, and the rules of variable declaration is crucial for effective C programming. Keywords provide predefined meanings, constants ensure fixed values, and variables enable dynamic data storage. Adhering to the rules of variable declaration ensures code readability and conformity. By grasping these concepts and following the guidelines presented, programmers can write efficient and well-structured C programs.

close