- 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

Variables in C++ Interview Questions & Answers - Learning Mode

Each variable in C++ has a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable. The name of a variable can be composed of letters, digits, and the underscore character. A variable is a way of referring to a memory location used in a computer program. This memory location holds values- perhaps numbers or text or more complicated types of data like a payroll record.

Try Variables in C++ Interview Questions & Answers - Exam Mode


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 can I safely assume about the initial values of variables which are not explicitly initialized?

Answer: It depends on complier which may assign any garbage value to a variable if it is not initialized. Source:
Question: what are auto static variables and auto extern variables?

Answer: In theory these are called storage classes. These will define the scope and life time of variables or functions.<br><br>There are mainly 4 of them:<br><br>auto is the default storage class for local variables. <br><br>register is used to define local variables that should be stored in a register instead of RAM. This means that the variable has a maximum size equal to the register size say a word.<br><br>static can also be defined within a function Source:
Question: Are there any new intrinsic (built-in) data types?

Answer: Yes. The ANSI committee added the bool intrinsic type and its true and false value keywords. Source:
Question: I was trying to use an "out int" parameter in one of my functions. How should I declare the variable that I am passing to it?

Answer: You should declare the variable as an int, but when you pass it in you must specify it as 'out', like the following:
int i;
foo(out i);
where foo is declared as follows:
[return-type] foo(out int o) { } Source:
Question: When you inherit a protected class-level variable, who is it available to?

Answer: Classes in the same namespace. Source:
Question: Are private class-level variables inherited?

Answer: Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited. But they are. Source:
Question: How many ways are there to initialize an int with a constant?

Answer: Two.
There are two formats for initializers in C++ as shown in the example that follows. The first format uses the traditional C notation. The second format uses constructor notation.
int foo = 123;
int bar (123); Source:
Question: How is static variable stored in the memory?
( if there are 2 functions in a file,and the static variable name is same (ex var) in both the function. how is it keep seperately in the memory).

Answer: C++ uses name mangling when storing both local and global static variables at the same place. The local static variables have function name and the global variables will have file name. Essentially the compiler uses namespace to distinguish between local and global static variables.

Question: What is the difference between declaration and definition?

Answer: The declaration tells the compiler that at some later point we plan to present the definition of this declaration.
E.g.: void stars () //function declaration
The definition contains the actual implementation.
E.g.: void stars () // declarator
for(int j=10; j > =0; j--) //function body
cout << *;
cout << endl; } Source:
Question: What is difference between followin intialization.

int iVar1;
int iVar2 = int();

and which one of two should we prefer always and why?

Answer: In first case a variable will be create in memeory with the default base type value (depending upon compiler 2 compiler) bcoz it is not initialized. in second case the variable will be created in the memory with the value retuned by the function int() (if int is a user define function) the second statement should have been int *i = new int();

Question: How do you decide which integer type to use?

Answer: It depends on our requirement. When we are required an integer to be stored in 1 byte (means less than or equal to 255) we use short int, for 2 bytes we use int, for 8 bytes we use long int.

A char is for 1-byte integers, a short is for 2-byte integers, an int is generally a 2-byte or 4-byte integer (though not necessarily), a long is a 4-byte integer, and a long long is a 8-byte integer. Source:
Question: What?s the auto keyword good for?

Answer: Local variables occur within a scope; they are ?local? to a function. They are often called automatic variables because they automatically come into being when the scope is entered and automatically go away when the scope closes. The keyword auto makes this explicit, but local variables default to auto auto auto auto so it is never necessary to declare something as an auto auto auto auto. Source:
Question: What is an algorithm (in terms of the STL/C++ standard library)?

Answer: Algorithm in STL consist diffrent searching and sorting algos implementation, which takes start and end iterators of STL container

on which algo is going to work.


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.140625 Seconds