Categories
Variables and Keywords

sizeof, union, register, static, type of, void and volatile

The sizeof keyword evaluates the size of data (a variable or a constant).

#include <stdio.h>
int main()
{
    printf("%u bytes.",sizeof(char));
}

To learn more, visit C operators.

Output

1 bytes.

register

The register keyword creates register variables which are much faster than normal variables.

register int var1;

static

The static keyword creates a static variable. The value of the static variables persists until the end of the program. For example:

static int var;

struct

The struct keyword is used for declaring a structure. A structure can hold variables of different types under a single name.

struct student{
    char name[80];
     float marks;
     int age;
}s1, s2;

To learn more, visit C structures.


typedef

The typedef keyword is used to explicitly associate a type with an identifier.

typedef float kg;
kg bear, tiger;

union

A union is used for grouping different types of variables under a single name.

union student {
    char name[80];
    float marks;
    int age;
}

To learn more, visit C unions.


void

The void keyword meaning nothing or no value.

void testFunction(int a) {
  .....
}

Here, the testFunction() function cannot return a value because its return type is void.


volatile

The volatile keyword is used for creating volatile objects. A volatile object can be modified in an unspecified way by the hardware.

const volatile number

Here, number is a volatile object.

Sincenumber is a constant, the program cannot change it. However, hardware can change it since it is a volatile object.

Leave a Reply

Your email address will not be published. Required fields are marked *