Turn-key PCB assembly services in prototype quantities or low-volume to mid-volume production runs

Variables in embedded C programming language

What are variables in C language. Variables are simple keywords which are defined by the values. Values can be changed. Variables are like a boxes with some size where values like apples can be put in. So variables can be various forms and sizes so called variable types.

Variable type is defined by a reserved word which indicates the type and size of variable identifier:

unsigned char my_char;

long int all_my_numbers;

int number;

Why do we need variables? The basic answer is that memory is limited and compiler needs to know much space to reserve for each variable. The coder needs to specify the variable type and its size by using one of reserved words from the table:

Few statements demonstrating the usage of variables and value assignments:

    int i;      /* Define a global variable i */
    i = 1;      /* Assign i the value 0 */
    {           /* Begin new block of sentences */
      int i;    /* Define a local variable i */
      i = 2;    /* Set its value to 2 */
    }           /* Close block */
    /* Here i is again 1 from the outer block */

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.