Constants and Variables in C

Variables in C

The variable is used to store the value. As the name indicates its value can be changed or also it can be reused many times. We have to define its Data Types in C as shown below.
Syntax 

Data type variable_name;<br>

e.g. 
int a;<br>

Where ‘a’ is the variables.

Types of Variables in C:

There are many types of variables in c:

  • local variable
  • global variable
  • static variable
  • external variable
  • Automatic variable

1. Local variable – A variable which is declared inside the function is known as local variable. It is used only inside the function in which it is declared.
2. Global variable – A variable which is declared outside the function is known as global variable. It can be used throughout the program.
3. Static variable – It is used to retain its value between multiple function calls. It is declared using static keyword.
4. External variable – You can share a variable in multiple C source files by using external variable. It is declared using extern keyword.
5. Automatic variable – Variable which is declared inside the block is known as automatic variable by default.

Learn the basics of Loops in C through this blog!

Constants in C

Its value is fixed throughout the program that means constants are those variables which value is not changed throughout the program.
C constants can be divided into two major categories:

  • Primary Constants
  • Secondary Constants

C constants
There are two simple ways in C to define constants:

1. Using#define 

e.g.

#include <stdio.h><br>
#define value 10<br>
void main() {<br>
int data;<br>
data = value*value;<br>
printf("value of data : %d",data);<br>
}<br>

Output
value of data : 100
Get the most out of C and become a better developer through this C Tutorial!

2. Using const keyword

e.g.

#include <stdio.h><br>
void main() {<br>
const int  value = 10;<br>
int data;<br>
data =value*value;<br>
printf("value of data : %d",value);<br>
}<br>

Output
value of data : 100
 

Related Blogs What’s Inside
PyCharm Installation Explains how to set up PyCharm for Python development tasks.
Spring Boot Interview Questions Offers Spring Boot interview questions for Java programming roles.
Doubly Linked List in C Guides on creating doubly linked lists in C for efficient data handling.
JUnit Interview Questions Details JUnit questions for mastering Java testing interviews.
PyCharm Tutorial Details PyCharm tools for enhancing Python programming productivity.
SOA Interview Questions Lists SOA interview questions for service-oriented architecture roles.
Keywords and Comments in C Details C keywords and comments for writing clear code.
C Installation Provides instructions for installing a C programming environment.
Some Programs in C Features C programs to illustrate basic coding principles.
Mockito Annotations Explains Mockito annotations for effective Java unit testing.

Our Data Science Courses Duration and Fees

Program Name
Start Date
Fees
Cohort Starts on: 8th Jun 2025
₹85,044

About the Author

Technical Research Analyst - Full Stack Development

Kislay is a Technical Research Analyst and Full Stack Developer with expertise in crafting Mobile applications from inception to deployment. Proficient in Android development, IOS development, HTML, CSS, JavaScript, React, Angular, MySQL, and MongoDB, he’s committed to enhancing user experiences through intuitive websites and advanced mobile applications.