Sponsored Links

Interview Questions



INTERVIEW QUESTIONS C VARIABLES IN C DETAILS

Question: How much memory does a static variable takes?

Answer: If you declare with in a function: it retain the value between function call.

Category Variables in C Interview Questions & Answers - Exam Mode / Learning Mode
Rating (0.2) By 8859 users
Added on 11/29/2012
Views 76823
Rate it!

Question: How much memory does a static variable takes?

Answer:

If you declare with in a function: it retain the value between function call. Source: CoolInterview.com

Answered by: padmaja | Date: 11/30/2007 | Contact padmaja Contact padmaja

2 bytes Source: CoolInterview.com

Answered by: pankaj sharma | Date: 12/4/2007 | Contact pankaj sharma Contact pankaj sharma

static variable takes the memory of the type.

say,
static int will occupy size of int
static char will ocupy size of char

The following program proves that.

#include<stdio.h>

int main()
{
static int array[2]={10,20};
static char string[10]="Hello";
printf("
Address of element %d is %u",array[0],&array[0]);
printf("
Address of element %d is %u",array[1],&array[1]);
printf("

Address of element in string %c is %u",string[0],&string[0]);
printf("

Address of element in string %c is %u",string[1],&string[1]);
system("pause");
return 0;
}
Source: CoolInterview.com

Answered by: Syed Baseer Ahmed | Date: 12/4/2007 | Contact Syed Baseer Ahmed Contact Syed Baseer Ahmed

as much as a single variable takes Source: CoolInterview.com

Answered by: viijay jain | Date: 12/6/2007 | Contact viijay jain Contact viijay jain

static is a storage class specifier it does't take any memory it says that the variable of type static is stored on data segment . Source: CoolInterview.com

Answered by: devesh kumar | Date: 12/11/2007 | Contact devesh kumar Contact devesh kumar

1 byte Source: CoolInterview.com

Answered by: rupa | Date: 12/12/2007 | Contact rupa Contact rupa

The amount of memory taken by the static variable is depend on data type not depends on
static. Static is a storage specifier where the variable store( it is data segment or BSS or code area)

eg:
static int i;
static char c;
static float f;
static short int si;
printf(" %d %d %d %d ", sizeof(i), sizeof(c), sizeof(f), sizeof(si));
output: 4 1 4 2 Source: CoolInterview.com

Answered by: pearl | Date: 12/13/2007 | Contact pearl Contact pearl

2bytes Source: CoolInterview.com

Answered by: musthafa | Date: 12/13/2007 | Contact musthafa Contact musthafa

It depends on data type of static
e.g static int i;
occupies 2 bytes Source: CoolInterview.com

Answered by: satish | Date: 12/13/2007 | Contact satish Contact satish

It depends on the variable type u define as static.
Static variables can be declare only outside the class for c++.

Source: CoolInterview.com

Answered by: Mohmad A Rah | Date: 12/14/2007 | Contact Mohmad A Rah Contact Mohmad A Rah

A variable which is declared static occupies the same amount of memory that the variable would take when declared without the static keyword.
Eg:
int takes 2 bytes
static int also occupies two bytes.
static only secures the data in the variable. It does not modify the amount of memory occupied. Source: CoolInterview.com

Answered by: dhivya | Date: 12/15/2007 | Contact dhivya Contact dhivya

A variable which is declared static occupies the same amount of memory that the variable would take when declared without the static keyword.
Eg:
int takes 2 bytes
static int also occupies two bytes.
static only secures the data in the variable. It does not modify the amount of memory occupied. Source: CoolInterview.com

Answered by: dhivya | Date: 12/15/2007 | Contact dhivya Contact dhivya

Static Variable size is 4 bytes
intial value is zero Source: CoolInterview.com

Answered by: venkatesh | Date: 12/15/2007 | Contact venkatesh Contact venkatesh

As it is stored in the memory of cpu so it will take very few memory space. Source: CoolInterview.com

Answered by: Pratyush kumar | Date: 12/20/2007 | Contact Pratyush kumar Contact Pratyush kumar

64 K of memory can take a static variable

Source: CoolInterview.com

Answered by: bharat biswal | Date: 12/26/2007 | Contact bharat biswal Contact bharat biswal

the size of static variable depends on its data type.if it is an integer than it will take 4 bytes on linux and windows or 2 bytes on DOS. Source: CoolInterview.com

Answered by: Dheeraj | Date: 12/27/2007 | Contact Dheeraj Contact Dheeraj

4 Source: CoolInterview.com

Answered by: srinivasa | Date: 1/7/2008 | Contact srinivasa Contact srinivasa

The static variable occupies the same space as any other variable of same data type.
The only difference is, even if it is declared local to a function the space for it is allocated in Data segment instead of stack.Hence its value is retained between function calls. Source: CoolInterview.com

Answered by: Ashutosh | Date: 1/21/2008 | Contact Ashutosh Contact Ashutosh

Memory allocation of a variable depends upon its data type not on static keyword
i.e. int-2,float-4,etc.. for 32 bit compiler
but if variable is static its persistence is through out the current program . Source: CoolInterview.com

Answered by: Vijay | Date: 1/23/2008 | Contact Vijay Contact Vijay

static int takes 2bytes.
static char takes 4bytes. Source: CoolInterview.com

Answered by: arun | Date: 1/25/2008 | Contact arun Contact arun

Static char size =1
Static int size =2
Static float =4 Source: CoolInterview.com

Answered by: Jayakumar | Date: 2/3/2008 | Contact Jayakumar Contact Jayakumar

You can find the size of static.

with the help of sizeof()

static int takes 2 bytes.
static char takes 1 byte.
static float takes 4 bytes. Source: CoolInterview.com

Answered by: Mahesh Kumar | Date: 2/17/2010 | Contact Mahesh Kumar Contact Mahesh Kumar


If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification Enter the above shown code: *
Inform me about updated answers to this question

Related Questions
View Answer
Where does global, static, local, register variables, free memory and C Program instructions get stored?
View Answer
1)What is static identifier?


2)Where are the auto variables stored?
View Answer
What is the benefit of using const for declaring constants?


View Answer
What is the difference between declaring a variable and defining a variable?


View Answer
What is an lvalue?


View Answer
Can static variables be declared in a header file?


View Answer
Can a variable be both const and volatile?


View Answer
What is the type of the variable b in the following declaration?
#define FLOATPTR float*
FLOATPTR a,b;

a) float
b) float pointer
c) int
d) int pointer

View Answer
A switch statement cannot include

a) constants as arguments
b) constant expression as arguments
c) string as an argument
d) None of the above

View Answer
How to swap the content of two variables without a temporary variable

View Answer
Where are the auto variables stored? What is the use of register variables?

View Answer
What is an lvalue?
View Answer
Can a variable be both const and volatile?
View Answer
How can you determine the maximum value that a numeric variable can hold?
View Answer
Is it acceptable to declare/define a variable in a C header?
View Answer
What is the difference between declaring a variable and defining a variable?
View Answer
Can static variables be declared in a header file?
View Answer
What is the benefit of using const for declaring constants?
View Answer
What is the benefit of using #define to declare a constant?
View Answer
What is the benefit of using an enum rather than a #define constant?
View Answer

Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.

View All Variables in C Interview Questions & Answers - Exam Mode / Learning Mode



User Options
India News Network

Latest 20 Questions
Payment of time- barred debt is: (a) Valid (b) Void (c) Illegal (d) Voidable
Consideration is defined in the Indian Contract Act,1872 in: (a) Section 2(f) (b) Section 2(e) (c) Section 2(g) (d) Section 2(d)
Which of the following is not an exception to the rule, "No consideration, No contract": (a) Natural love and affection (b) Compensation for involuntary services (c) Completed gift (d) Agency
Consideration must move at the desire of: (a) The promisor (b) The promisee (c) The promisor or any other party (d) Both the promisor and the promisee
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal



Fresher Jobs | Experienced Jobs | Government Jobs | Walkin Jobs | Company Profiles | Interview Questions | Placement Papers | Companies In India | Consultants In India | Colleges In India | Exams In India | Latest Results | Notifications In India | Call Centers In India | Training Institutes In India | Job Communities In India | Courses In India | Jobs by Keyskills | Jobs by Functional Areas

Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes

Gate Articles | Gate Books | Gate Colleges | Gate Downloads | Gate Faqs | Gate Jobs | Gate News | Gate Sample Papers | Gate Training Institutes

MBA Articles | MBA Books | MBA Case Studies | MBA Business Schools | MBA Current Affairs | MBA Downloads | MBA Events | MBA Notifications | MBA FAQs | MBA Jobs
MBA Job Consultants | MBA News | MBA Results | MBA Courses | MBA Sample Papers | MBA Interview Questions | MBA Training Institutes

GRE Articles | GRE Books | GRE Colleges | GRE Downloads | GRE Events | GRE FAQs | GRE News | GRE Training Institutes | GRE Sample Papers

IAS Articles | IAS Books | IAS Current Affairs | IAS Downloads | IAS Events | IAS FAQs | IAS News | IAS Notifications | IAS UPSC Jobs | IAS Previous Question Papers
IAS Results | IAS Sample Papers | IAS Interview Questions | IAS Training Institutes | IAS Toppers Interview

SAP Articles | SAP Books | SAP Certifications | SAP Companies | SAP Study Materials | SAP Events | SAP FAQs | SAP Jobs | SAP Job Consultants
SAP Links | SAP News | SAP Sample Papers | SAP Interview Questions | SAP Training Institutes |




Copyright ©2003-2024 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions