User Tools

Site Tools


embedded:c

This is an old revision of the document!


C

VARIABLES

  • char - 1 byte - is used to store a single character (ASCII) value
char Temp;    // Variable definition or declaration (letting compiler know we will need it in the future)
Temp = 25;    // Variable initialisation (assigning a value)
extern int my_var // Declaration. It tells the compiler that my_var is defined outside this file

Address of the variable

char a1 = 'A';
&a1                 // Gives you an address - memory location of the variable temp. Type is char* 
printf("%p\n", &a1) // %p - is the special format specifier for pointers

Storage Class of the variable defines:

  • Scope of the variable
  • Visibility of the variable
  • Life time of the variable

static - creates global variable but private to the specific function.

void myFunc(void)
{
  static int count = 0;
  count = count + 1;
  printf("Function was called %d times\n", count);
}

Another use case for static - prevent access to the global variables from another files:

static int internal_global_var; // Won't be accessible outside this file, even with extern

extern - is used to access the global variable, which is defined outside the scope of a file

embedded/c.1757601451.txt.gz · Last modified: by v1ctor