Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

STATTIC Storage Class IN C

Status
Not open for further replies.

sacrpio

Member level 3
Member level 3
Joined
May 24, 2004
Messages
56
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
500
Dear friends,

#include<stdio.h>

static int a=1;
void main()
{
static int a=2;
fun();
printf("%d", a);
}

fun()
{
static int a=3;
}

In above example at how many places in data area variable a will be stored.
 

Hi,
I think it should be 3 places as each are static and need to be existent through out the life time of the program.
 

3 different independent variables;
look at this

Code:
#include <stdio.h> 

static int a=1;
void main()
{
static int a=2;
fun();
fun2();
printf("\n%d", a);
}

fun()
{
static int a=3;
printf( "\n%d",a);
}

fun2()
{
printf("\n%d", a);

}


now look at this

Code:
#include <stdio.h> 

static int a=1;
void main()
{
static int a=2;
fun();
fun2();
printf( "\n%lx",&a);
}

fun()
{
static int a=3;
printf( "\n%lx",&a);
}

fun2()
{
printf("\n%lx", &a);

}
 

Static is also used for scope control. Declaring a global variable static limits it's scope to that file, equaly, declaring a function prototype and function static limits it's scope to that file. You can use this to implement Namespaces.
Who needs C++?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top