Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


1.what are local and global variables?
2.what is the scope of static variables?
3.what is the difference between static and global variables?
4.what are volatile variables?
5.what is the use of 'auto' keyword?
6.how do we make a global variable accessible across files?
Explain the extern keyword?
7.what is a function prototype?
8.what does keyword 'extern' mean in a function declaration?

Answers were Sorted based on User's Feedback



1.what are local and global variables? 2.what is the scope of static variables? 3.what is the diff..

Answer / vignesh1988i

LOCAL variables:
these variables are also called as auto variables....
this will be having life only inside a particular block.
for ex:
int i=45;
{
i=34;
printf("%d",i);
}
printf("%d",i);
here the output will be for 1st printf it will be 34 & for
second will be 45. since 34 is local to that block of
coding.. after it comes out it dies. the default value is
garbage value.

GLOBAL variables:
these are those variables which will have life
until the program ends.... the scope will be throught....
it must be declared outside the first executable
statement... the default value is 0;. but when it comes to
prority wise local only will get the first place.......
for ex:
int i=21;
void main()
{
int i=99;
{
printf("%d",i);
}
printf("%d",i);
printf("%d",i);
}
the output will be for 1st printf it will print as 99.. for
second also 99 since local variable gets the first
prority.... then the last printf will print 21.

STATIC variables:
the scope of the static variables is with in the
particular block of code. for ex:
main()
{
for(static int i=0;i<3;)
i++;
i=34;
printf("%d",i);
}

this wont print 'i' as 34... this will give an error that
UNDEFINED SYMBOL 'i'. since when 'i' comes out this will
dies... this 'i' cant be referred by the compailer.. but
this will work when we do it in other way::
void main()
{
static int i=0;
for(;i<3;)
i++;
i=34;
printf("%d",i);
}
this will print i=34..... since we have defined as
static inside main block.... instead of FOR block ... till
main block prevails this i wont die..... so i=34 prints.

STATIC GLOBAL
1)this must be declared must be declared outside
inside the main function only main only
2)this is one time but here it will take the
initilization... last initilization
3)this is local to a block this has life til the
coding ends

AUTO:
this is as equal as local variables..... as mentioned for
local variables above

EXTERN:
this is declaration for global variable.. this can also be
declared as:
extern int i;
main()
{
----
---
}

FUNCTION PROTOTYPE:
this says a outer layer of , how the function definition of
the above prototype lies......

Is This Answer Correct ?    7 Yes 1 No

1.what are local and global variables? 2.what is the scope of static variables? 3.what is the diff..

Answer / rajan

Explain the out put
#include<stdio.h>
extern int i;
main()
{
printf("%d",i);
}
#include<stdio.h>
extern int i;
main()
{
printf("%d",i);
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

What library is sizeof in c?

0 Answers  


What does the message "warning: macro replacement within a string literal" mean?

1 Answers  


How can you check to see whether a symbol is defined?

0 Answers  


What is identifiers in c with examples?

0 Answers  


How to write a program for swapping two strings without using 3rd variable and without using string functions.

7 Answers   iGate, Infotech,


What is double pointer in c?

0 Answers  


WHY DO WE USE A TERMINATOR IN C LANGUAGE?

2 Answers  


main() { int a=4,b=2; a=b<<a + b>>2; printf("%d", a); }

4 Answers   CTS,


An application package has been provided to you without any documents for the following application. The application needs to be tested. How will you proceed?

0 Answers   Aspire, Infogain,


What is the default value of local and global variables in c?

0 Answers  


how can i access hard disk address(physical address)? are we access hard disk by using far,near or huge pointer? if yes then please explain.....

0 Answers  


How do you determine if a string is a palindrome?

1 Answers  


Categories