CoolInterview.com - World's Largest Collection of Interview Questions & Answers, FAQs, queries, sample papers, exam papers, dumps, what, why, how, where, when questions
Our Services
Get 9,000 Interview Questions & Answers in an eBook.




Get it now !!
Send your Resume to 6000 Companies
Variables in C Interview Questions & Answers - Learning Mode
COOLINTERVIEW.COM C INTERVIEW QUESTIONS VARIABLES IN C INTERVIEW QUESTIONS QUESTIONS & ANSWERS - LEARNING MODE

Variables in C Interview Questions & Answers - Learning Mode

C variable is a named location in a memory where a program can manipulate the data. This location is used to hold the value of the variable. The value of the C variable may get change in the program. C variable might be belonging to any of the data type like int, float, char etc. Variable in C Programming is also called as container to store the data. Variable name may have different data types to identify the type of value stored. Suppose we declare variable of type integer then it can store only integer values. Variable is considered as one of the building block of C Programming which is also called as identifier.

Try Variables in C Interview Questions & Answers - Exam Mode

1 2 Next

Sort By : Latest First | Oldest First | By Rating

Variables in C Interview Questions & Answers - Learning Mode
Try Variables in C Interview Questions & Answers - Exam Mode
Question: What is the benefit of using an enum rather than a #define constant?

Answer: The use of an enumeration constant (enum) has many advantages over using the traditional symbolic constant style of #define. These advantages include a lower maintenance requirement, improved program readability, and better debugging capability.

1) The first advantage is that enumerated constants are generated automatically by the compiler. Conversely, symbolic constants must be manually assigned values by the programmer.

For instance, if you had an enumerated constant type for err Source: CoolInterview.com
Question: Can static variables be declared in a header file?

Answer: You can?t declare a static variable without defining it as well (this is because the storage class modifiers
static and extern are mutually exclusive). A static variable can be defined in a header file, but this would cause each source file that included the header file to have its own private copy of the variable, which is probably not what was intended. Source: CoolInterview.com
Question: Constant volatile variable declaration is possible or not? if give any one example and reason.

Answer: Constants can be defined by placing the keyword const in front of any variable declaration. If the keyword volatile is placed after const, then this allows external routines to modify the variable (such as hardware devices). This also forces the compiler to retrieve the value of the variable each time it is referenced rather than possibly optimizing it in a register.

Example: An input-only buffer for an external device could be declared as const volatile (or volatile const, order is not i Source: CoolInterview.com
Question: What are the advantages of auto variables?

Answer: 1)The same auto variable name can be used in different blocks

2)There is no side effect by changing the values in the blocks

3)The memory is economically used

4)Auto variables have inherent protection because of local scope Source: CoolInterview.com
Question: 1)What is static identifier?


2)Where are the auto variables stored?


Answer: static variables retain there value through out the execution. Source: CoolInterview.com
Question: Differentiate between an internal static and external static variable?

Answer: An internal static variable is declared inside a block with static storage class whereas an external static variable is declared outside all the blocks in a file.An internal static variable has persistent storage,block scope and no linkage.An external static variable has permanent storage,file scope and internal linkage. Source: CoolInterview.com
Question: Where does global, static, local, register variables, free memory and C Program instructions get stored?

Answer: local variables-->stack
global variable-->data memory
register variable-->register
static variable-->main memory Source: CoolInterview.com
Question: Can a variable be both const and volatile?

Answer: Yes. The const modifier means that this code cannot change the value of the variable, but that does not mean that the value cannot be changed by means outside this code. For instance, in the example in
FAQ 8, the timer structure was accessed through a volatile const pointer. The function itself did not change the value of the timer, so it was declared const. However, the value was changed by hardware on the computer, so it was declared volatile. If a variable is both const and volatile, the t Source: CoolInterview.com
Question: Difference between : -
1)Global variable and Local variable ,
2)Static variable and Global variable ?


Answer: 1)Global variable and Local variable-
A) Global variables once declared they can be used any where in the program i.e. even in many functions. If possible u can use the global variables in the different user defined header files as like in packages in java.
On the other hand global variables values can be changed programmatically

local variables are local to a functional and cant be used beyond that function.


2)Static variable and Global variable ?
Static variables on Source: CoolInterview.com
Question: How can you determine the maximum value that a numeric variable can hold?

Answer: For integral types, on a machine that uses two?s complement arithmetic (which is just about any machine you?re likely to use), a signed type can hold numbers from ?2(number of bits ? 1) to +2(number of bits ? 1) ? 1. An unsigned type can hold values from 0 to +2(number of bits) ? 1. For instance, a 16-bit signed integer can hold numbers from ?2^15 (?32768) to +2^15 ? 1 (32767). Source: CoolInterview.com
Question: What is difference between static and global static variable?

Answer: Local static defines the scope with in the functions,incaseof global static will be module level scope.

both will store in a data segments Source: CoolInterview.com
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
Question: Are the variables argc and argv are local to main()?

Answer: Yes both argc and argv are local to main method.Any thing you write within the parenthesis is local to the function. Source: CoolInterview.com
Question: What is the difference between declaring a variable and defining a variable?

Answer: Declaring a variable means describing its type to the compiler but not allocating any space for it. Defining a variable means declaring it and also allocating space to hold the variable. You can also initialize a variable at the time it is defined. Source: CoolInterview.com
Question: What is the benefit of using #define to declare a constant?

Answer: Using the #define method of declaring a constant enables you to declare a constant in one place and use it throughout your program. This helps make your programs more maintainable, because you need to maintain only the #define statement and not several instances of individual constants throughout your program.

For instance, if your program used the value of pi (approximately 3.14159) several times, you might want to declare a constant for pi as follows:

#define PI 3.14159

Us Source: CoolInterview.com
Question: What is the benefit of using const for declaring constants?

Answer: The benefit of using the const keyword is that the compiler might be able to make optimizations based on the knowledge that the value of the variable will not change. In addition, the compiler will try to ensure that the values won?t be changed inadvertently.

Of course, the same benefits apply to #defined constants. The reason to use const rather than #define to define a constant is that a const variable can be of any type (such as a struct, which can?t be represented by a #defined const Source: CoolInterview.com
Question: What is the benefit of using const for declaring constants?




Answer: If we use const variable instead of #define, we can specify the scope of the variable.

Source: CoolInterview.com
Question: Can static variables be declared in a header file?




Answer: Yes there is difference between declaring a static variable as global and local. If it is local, it can be accessed only in the function where it's declared. But if it is global, all functions can access it. But, what ever be the case, its value will be retained between functions.
Source: CoolInterview.com
Question: What is storage class and what are storage variable ?

Answer: A storage class is an attribute that changes the behavior of a variable. It controls the lifetime, scope and linkage.

There are five types of storage classes

1) auto

2) static

3) extern

4) register

5) typedef Source: CoolInterview.com
Question: How pointer variables are initialized ?

Answer: int a;
int *p;
int p=&a;
this is initialization n if its not initialized its called as dangling pointer Source: CoolInterview.com

1 2 Next



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
Cache = 0.4375 Seconds