Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • DSA
  • Practice Problems
  • Python
  • C
  • C++
  • Java
  • Courses
  • Machine Learning
  • DevOps
  • Web Development
  • System Design
  • Aptitude
  • Projects
Open In App
Next Article:
Data Types in Programming
Next article icon

Variable Declaration in Programming

Last Updated : 26 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Declaration of Variables is a fundamental concept in programming, where programmers define variables to store data within a program. In this article, we will provide a detailed overview about the declaration of variable, its importance how they are implemented in different programming languages.

Table of Content

  • Meaning of Variable Declaration
  • Importance of Variable Declaration
  • Variable Declaration in C
  • Variable Declaration in C++
  • Variable Declaration in Java
  • Variable Declaration in Python
  • Variable Declaration in C#
  • Variable Declaration in JavaScript

Meaning of Variable Declaration:

Variable Declaration is a statement that provides the variable name and its type, allowing the program to allocate memory for storing values.

Importance of Variable Declaration:

Declaring variables plays an important role in programming. Some of the important roles are:

  1. Memory Allocation: When we declare a variable, we tell the computer to reserve some space in memory. This space is where the data associated with the variable will be stored.
  2. Data Type Specification: Variable declaration also involves specifying the type of data the variable will hold (like a number, text, etc.). This helps the computer know how much memory to allocate for the variable.
  3. Code Readability and Maintenance: Declaring variables makes our code easier to read and maintain. It gives meaningful names to data, which makes the code self-explanatory.
  4. Avoiding Errors: If we try to use a variable that hasn’t been declared, the computer won’t know what we’re referring to, and this will lead to an error.
  5. Scope Definition: Variable declaration defines the scope of the variable, i.e., the part of the code where the variable can be accessed.

Variable Declaration in C:

Here is the implementation of Declaration of Variables in C language:

C
// Declaring an integer variable named 'a' int a; // Declaring a float variable named 'b' float b; // Declaring a character variable named 'c' char c; 

Variable Declaration in C++:

Here is the implementation of Declaration of Variables in C++ language:

C++
// Declaring an integer variable named 'a' int a; // Declaring a float variable named 'b' float b; // Declaring a character variable named 'c' char c; 

Variable Declaration in Java:

Here is the implementation of Declaration of Variables in Java language:

Java
// Declaring an integer variable named 'a' int a; // Declaring a float variable named 'b' float b; // Declaring a character variable named 'c' char c; 

Variable Declaration in Python:

Here is the implementation of Declaration of Variables in Python language:

Python
# Declaring an integer variable named 'a' a = 10 # Declaring a float variable named 'b' b = 20.5 # Declaring a string variable named 'c' c = 'hello' 

Variable Declaration in C#:

Here is the implementation of Declaration of Variables in C# language:

C#
// Declaring an integer variable named 'a' int a; // Declaring a float variable named 'b' float b; // Declaring a character variable named 'c' char c; 

Variable Declaration in JavaScript:

Here is the implementation of Declaration of Variables in Javascript language:

JavaScript
// Declaring an integer variable named 'a' let a = 10;  // Declaring a float variable named 'b' let b = 20.5;  // Declaring a string variable named 'c' let c = 'hello'; 

Conclusion:

In programming, declaring variables involves specifying their data type and name. This action allocates memory for storing values, facilitating efficient data manipulation within the program.


Next Article
Data Types in Programming

S

singhdivya5
Improve
Article Tags :
  • Programming

Similar Reads

  • Variable in Programming
    In programming, we often need a named storage location to store the data or values. Using variables, we can store the data in our program and access it afterward. In this article, we will learn about variables in programming, their types, declarations, initialization, naming conventions, etc. Table
    11 min read
  • Type Casting in Programming
    In programming, variables hold data of specific types, such as integers, floating-point numbers, strings, and more. These data types determine how the computer interprets and manipulates the information. Type casting becomes necessary when you want to perform operations or assignments involving diff
    14 min read
  • Variables in Scratch Programming
    Scratch is a high-level visual programming language tool that interacts with users through diagrams and blocks that have the basics of a program inbuilt in it. Scratch is used to make interactive programs especially for kids using the block kind of interfaces so that they can easily learn languages
    7 min read
  • Functions in Programming
    Functions in programming are modular units of code designed to perform specific tasks. They encapsulate a set of instructions, allowing for code reuse and organization. In this article, we will discuss about basics of function, its importance different types of functions, etc. Table of Content What
    14 min read
  • Data Types in Programming
    In Programming, data type is an attribute associated with a piece of data that tells a computer system how to interpret its value. Understanding data types ensures that data is collected in the preferred format and that the value of each property is as expected. Table of Content What are Data Types
    11 min read
  • Programming Construction in COBOL
    COBOL is a compiled, imperative, procedural programming language designed for business use. It can handle very large numbers and strings. COBOL is still in use today because it's robust, with an established code base supporting sprawling enterprise-wide programs. Learning to program in COBOL will se
    5 min read
  • What is Imperative Programming?
    The computer programming paradigm defines the style of programming, approach to solve problem and method of computer systems towards providing solutions use programming. There is a classification of programming paradigms into two broad paradigms i.e., imperative and declarative. This article is base
    6 min read
  • Iteration Statements in Programming
    Iteration statements, commonly known as loops, are statements in programming used to execute part of code repeatedly based on condition or set of conditions. These constructs are important for performing repetitive tasks efficiently. In this article, we will discuss various types of iteration statem
    5 min read
  • If Else Statement in Programming
    An if else statement in programming is a basic programming technique that allows you to make decisions based on certain conditions. It allows your program to execute different pieces of code depending on whether the specified condition evaluates to true or false. This capability is crucial in buildi
    5 min read
  • While loop in Programming
    While loop is a fundamental control flow structure in programming, enabling the execution of a block of code repeatedly as long as a specified condition remains true. While loop works by repeatedly executing a block of code as long as a specified condition remains true. It evaluates the condition be
    11 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences