🖍️

C Keywords, DataTypes, Storage

TypeQuiz 4 Material

Notes

Type Qualifiers

Const

Volatile

Restrict

Memory Regions in C

Global Variables

int x = 4;
int main(void) {
    int y = 3;
    return 0;
}
//x is a global variable stored in the "data" section of our memory
//y is a local variable stored on the stack (specifically, on the stack frame for main)

Storage Class Specifiers

Auto

Static

Extern

Register

Other Keywords

Unsigned

Enum

Structs

Scope

Global vs Local

// x is a global variable stored in the "data" section of our memory
// y is a local variable stored on the stack (specifically, on the stack frame for main)
int x = 4;
int main(void) {
    int y = 3;
    return 0;
}

Static vs Extern

Functions

main()

int main(int argc, char *argv[]) {
	return 0;
}

void

void func(void) {
	printf(“Hello\n”);
}

C Data Types and Sizes

charExactly 8 bits
shortAt least 16 bits (usually 16)
intAt least 16 bits
longAt least 32 bits
long longAt least 64 bits
floatUnspecified, usually 32 bits
doubleUnspecified, usually 64 bits
long doubleUnspecified, usually 64, 96 or 128 bits

You can also safely assume the following about sizes:

  • sizeof(long long) ≥ sizeof(long)
  • sizeof(long) ≥ sizeof(int)
  • sizeof(int) ≥ sizeof(short)
  • sizeof(short) ≥ sizeof(char)
  • sizeof(long double) ≥ sizeof(double)
  • sizeof(double) ≥ sizeof(float)
  • sizeof(float) ≥ sizeof(char)
  • Pretty much, this means that no type is smaller than the one above it in the table (and float is no smaller than char).

Questions & Answers