Saturday 31 December 2016

Breif description about static storage class


The static storage class is very important in C language so i'm going to discuss it in brief 
just have a glance below and i have compared it with an example::
The features of static storage class are as following:
StorageMemory
Keywordstatic
Default initial valueZero
ScopeLocal to the block, in which the variable is defined
LifeValue of the variable persists between different function calls.
#include<stdio.h>
void add();
int main()
{
add();
add();
add();
add();
return 0;
}
void add()
{
 static int i=1;
 printf("\n%d",i);
 i=i+1;
}
OUTPUT : 1 2 3

 static variable do not disappear when the function is no longer active. There value persist. If control comes back to the same function again , the static variables have the same values they had last time around.
Note:
if the storage class is static, then the statement static int i = 1 is executed only once, irrespective of how many times the same function is called.

Storage classes in C



Storage Classes in C

In C language, each variable has a storage class which decides scope, visibility and lifetime of that variable. The following storage classes are most oftenly used in C programming,
  1. Automatic variables
  2. External variables
  3. Static variables
  4. Register variables

Storage Classes are used to describe about the features of a variable/function. These features basically include the scope, visibility and life-time which help us to trace the existence of a particular variable during the runtime of a program.
C language uses 4 storage classes, namely:
auto: This is the default storage class for all the variables declared inside a function or a block. Hence, the keyword auto is rarely used while writing programs in C language. Auto variables can be only accessed within the block/function they have been declared and not outside them (which defines their scope). Of course, these can be accessed within nested blocks within the parent block/function in which the auto variable was declared. However, they can be accessed outside their scope as well using the concept of pointers given here by pointing to the very exact memory location where the variables resides. They are assigned a garbage value by default whenever they are declared.

extern: Extern storage class simply tells us that the variable is defined elsewhere and not within the same block where it is used. Basically, the value is assigned to it in a different block and this can be overwritten/changed in a different block as well. So an extern variable is nothing but a global variable initialized with a legal value where it is declared in order to be used elsewhere. It can be accessed within any function/block. Also, a normal global variable can be made extern as well by placing the ‘extern’ keyword before its declaration/definition in any function/block. This basically signifies that we are not initializing a new variable but instead we are using/accessing the global variable only. The main purpose of using extern variables is that they can be accessed between two different files which are part of a large program.
First File: main.c
#include <stdio.h>
 
int count ;
extern void write_extern();
 
main() {

   count = 5;
   write_extern();
}
Second File: support.c
#include <stdio.h>
 
extern int count;
 
void write_extern(void) {
   printf("count is %d\n", count);
}
Here, extern is being used to declare count in the second file, where as it has its definition in the first file, main.c. Now, compile these two files as follows −
$gcc main.c support.c
It will produce the executable program a.out. When this program is executed, it produces the following result −
count is 5
static: This storage class is used to declare static variables which are popularly used while writing programs in C language. Static variables have a property of preserving their value even after they are out of their scope! Hence, static variables preserve the value of their last use in their scope. So we can say that they are initialised only once and exist till the termination of the program. Thus, no new memory is allocated because they are not re-declared. Their scope is local to the function to which they were defined. Global static variables can be accessed anywhere in the program. By default, they are assigned the value 0 by the compiler.

void test();   //Function declaration (discussed in next topic)
 
main()
{
 test();
 test();
 test();
}
void test()
{
 static int a = 0;        //Static variable
 a = a+1;
 printf("%d\t",a);
}
output :
1 2 3
register: This storage class declares register variables which have the same functionality as that of the auto variables. The only difference is that the compiler tries to store these variables in the register of the microprocessor if a free register is available. This makes the use of register variables to be much faster than that of the variables stored in the memory during the runtime of the program. If a free register is not available, these are then stored in the memory only. Usually few variables which are to be accessed very frequently in a program are declared with the register keyword which improves the running time of the program. An important and interesting point to be noted here is that we cannot obtain the address of a register variable using pointers.
To specify the storage class for a variable, the following syntax is to be followed:
Syntax:
storage_class var_data_type var_name; 

Sunday 18 December 2016

Today  I would like to share a very interesting topic related to future gadgets and its hell breathtaking,Let's take a glance.
Imagination is more important than intellect… This was the conclusion Albert Einstein arrived to, one of the most important genius ever. Designers agree with this statement, it’s extremely hard nowadays to imagine new and new gadgets or at least new features for the existent products.Much more, there are so many competent designers that it is practically impossible to create something without being already sketched by other individuals. In spite of this context, every day a new and original gadget is created and amazes people. 

Future of Mobile Search for Diet

Future of Mobile Search for Diet

Apple Black Hole, the holographic phone for the year

Apple Black Hole, the holographic phone for the year

Glassy Glassy phones

Glassy Glassy phones

Ringen watch

Ringen watch

Siafu: Metamophing Computer Interface

Siafu: Metamophing Computer Interface

Blue Bee

Blue Bee

Stealthy Kayak

Stealthy Kayak

WristPC

WristPC

Tharula Electric Bike By Diana Lumbasyo

Tharula Electric Bike By Diana Lumbasyo

The Intelligent Power Strip

The Intelligent Power Strip

Light Bulb Radio

Light Bulb Radio

REC

REC

Solaris watch

Solaris watch

The Piggy Bank

The Piggy Bank

Flexible Mobile

Flexible Mobile

The Smartphone Bicycle

The Smartphone Bicycle

Time Flies

Time Flies

Chiuet table

 Chiuet table

Fitness@Work

Fitness@Work

The Coral Reef Light

The Coral Reef Light

A man’s iron

A man's iron

The Smart Finger

The Smart Finger

AXIO camera

AXIO camera

The Mercator

The Mercator

MiCoffee

MiCoffee

The Phalanx

 The Phalanx

The Terrace Chair

The Terrace Chair

Shrieking Ball

Shrieking Ball

Water Stone Faucet

Water Stone Faucet

F.O. Clock

F.O. Clock