Variables and Constants in C Programming
Tags: cprogramming, tutorial, beginners, programming
Published: 2021-02-12 08:44:59

<p>In this tutorial, we will learn variables and <a href="https://usemynotes.com/variables-and-constants-in-c-programming/">constants in c programming</a>, and the rules for naming a variable, and the difference between variables and constant. So let us start.</p>
<h2>What are the variables in a c programming language?</h2>
<p>A Variable is a strong area that is used to store the data. The Variable stores the data and during the time of program execution the value of the variable can be changed. The value of the Variable can be changed even after the declaration of value.</p><p>Every variable should have a unique name to indicate the storage area properly. Variables are just a symbolic representation of the memory location at which the data is stored.</p>
<h2>What are the types of variables in c?</h2>
<h3>Global variable</h3>
<p>It is a variable of the function which is declared outside. It can be used in any of the functions. It can be declared anywhere outside the block. The value of the global variable can be changed by any function inside the code.</p>
<h3>Local variable</h3>
<p>This variable is declared inside the function. The local variable is used only where the function is declared. It should be declared at the starting of the block.</p>
<h2>What are the rules for naming a variable?</h2>
<ol>
<li>A variable name can only consist of letters (it can be both uppercase and lowercase letters), digits, and underscore.</li>
<li>The first letter of a variable should only be either a letter or an underscore.</li>
<li>There is no such rule on how long a variable name (identifier) can be. However, we may run into problems in some of the compilers if the variable name is longer than 31 characters.</li>
</ol>
<h2>What is constant in c programming?</h2>
<p>Constant is a variable whose value can not be changed. As we can see from the name itself that these are the variables that will not change or we can say will remain fixed. Every constant has some range.there are various ranges depending upon the unsigned to signed bits. When we declare any constant its value remains the same throughout the function.<br> The constant can be of any type like integers, characters, float, octal, hexadecimal, etc. there is a range for every constant.</p>
<h2>What are the types of constants in c?</h2>
<p>There are two types of constant. They are user-defined and constant keyboard.</p>
<h3>User # define</h3>
<p>Define is a type of Pre-processor which is used to declare constant declare.</p>
<h3>Using const keyboard</h3>
<p>By using the Const keyword we can declare constant.</p>
<h2>What is the difference between constant and variable?</h2>
<table class="table table-bordered table-striped">
  <tbody>
    <tr>
      <th>Constant</th>
      <th>Variable</th>
    </tr>
    <tr>
      <td>It is a value that can not be altered throughout the program</td>
      <td>It is a storage location which is paired with an associated symbolic value consisting of a value </td>
    </tr>
    <tr>
      <td>Value can not be changed</td>
      <td>Value can be changed according to the requirement of the user</td>
    </tr>
  </tbody>
</table>