Variables tutorial in c programming-[C programming tutorial 2021]


 What are variables?

                A variable is a name given to a storage area that holds a particular value. In C programming each variable specify the types which specify the size of that variable(like int, float, char ...etc.) and by using these variables u can perform various operations.

C programming tutorial 2021
Variables in c programming-[C programming tutorial 2021]


First we a created a project in code blocks with name as variables and then we saw what are variables and how it works and how to declare the variables.

Here are few examples of variables -

int var;
- Here var is a variable of type int which can store an integer value.

float _myVar = 2.00;

- _myVar is a variables of type float which stores a floating points values(i.e decimal values).

Source code:-


#include <stdio.h>
#include <stdlib.h>

int main()
{
    //int var; it is a variable that holds an integer value

    //float _var; it is a variable that holds an floating pint values like 2.02

    //int num2;
    //double num_45;

    //int 3num; //this is an invalid varible
    //float num$; //it contains the symbol $ so it is invalid

    //int num1;
    //int Num1;

    int a;
    a = 5; //the variable a contains value 5

    float var = 88.76; // var containds the value 88.76

    //Comment whether the below variables are correct or wrong

    int number_11;
    int 1num1;

    return 0;
}

Rules for naming variables :-

  • Variables names should only contain only letters (Uppercase and Lowercase)and numbers and a special character underscore(_).
  • The first letter of the variable name should start with a letter or an underscore (you cannot start with a number).
  • variables cannot contain any special characters other then numbers, letters and underscore.
  • Variables in C programming iscase sensitive i.e Uppercase and lowercase characters are treated  differently.
Learn more about variables, read more.

Post a Comment

0 Comments