Q6 Write C programs to compare the execution time & compilation time for all the four storage classes variables.

Lets compare the compilation time for all the four storage classes of variable in c.

Program: 144

Write C programs to compare the execution time & compilation time for all the four storage classes variables

Variable Storage Class tells us:

  1. Storage (location)
  2. Default Initial Value of the variable
  3. Scope of the variable
  4. Life of the variable

1. Storage: Where the variable would be stored.

2. Default Initial Value: What will be the initial value of the variable, if initial value is not specifically assigned. (i.e. the default initial value)

3. Scope: What is the scope of the variable: i.e. in which functions the value of the variable would be available.

4. Life: What is the life of the variable: i.e. how long would the variable exist.

https://youtu.be/HcqJZMEwEvU

Automatic Storage Class Variable

//Automatic Storage Class Variable
//Speed Test
#include<stdio.h>
#include<time.h>
int main()
{
    auto int i;

    for(i=1;i<=100000000;i++);

    int ticks=clock();
    printf("%f\n",(float)ticks/CLOCKS_PER_SEC);
    return 0;
}

Output:

0.293000

Register Storage Class Variable

//Register Storage Class Variable
//Speed Test
#include<stdio.h>
#include<time.h>
int main()
{
    register int i;

    for(i=1;i<=100000000;i++);

    int ticks=clock();
    printf("%f\n",(float)ticks/CLOCKS_PER_SEC);
    return 0;
}

Output:

0.053000

Static Storage Class Variable

//Static Storage Class Variable
//Speed Test
#include<stdio.h>
#include<time.h>
int main()
{
    static int i;

    for(i=1;i<=100000000;i++);

    int ticks=clock();
    printf("%f\n",(float)ticks/CLOCKS_PER_SEC);
    return 0;
}

Output:

0.282000

External Storage Class Variable

//External Storage Class Variable
//Speed Test
#include<stdio.h>
#include<time.h>
int i;
int main()
{
    for(i=1;i<=100000000;i++);

    int ticks=clock();
    printf("%f\n",(float)ticks/CLOCKS_PER_SEC);
    return 0;
}

Output:

0.305000

So the Winner is Register Storage Class

Lokesh Kumar: Being EASTER SCIENCE's founder, Lokesh Kumar wants to share his knowledge and ideas. His motive is "We assist you to choose the best", He believes in different thinking.
Related Post
Leave a Comment

This website uses cookies.