What would be the output of the following program (in 32-bit systems)?
1. #include 2. using namespace std; 3. int main() 4. { 5. cout
1 4 4
1 4 8
1 8 8
none of the mentioned
Explanation:-
Answer: Option A. -> 1 4 4
Character is 1 byte, integer 4 bytes and float 4 bytes.
Question 2.
What is the output of the following program?
1. #include 2. using namespace std; 3. int main() 4. { 5. int a = 5; 6. float b; 7. cout
2 6
4 6
2 5
4 5
Explanation:-
Answer: Option D. -> 4 5
The a as a integer will be converted to float while calculating the size. The value of any variable doesn’t modify inside sizeof operator. Hence value of variable a will remain 5. Output: $ g++ size3.cpp $ a.out 4 5
Question 3.
What is the output of the following program?
1. #include 2. using namespace std; 3. int main() 4. { 5. int num1 = 10; 6. float num2 = 20; 7. cout
2
4
8
garbage
Explanation:-
Answer: Option B. -> 4
In this program, integer is converted into float. Therefore the result of num1 and num2 is float. And it
is returning the size of the float. Output: $ g++ size2.cpp $ a.out 4
Question 4.
What is the output of the following program?
1. #include 2. using namespace std; 3. int main ( ) 4. { 5. static double i; 6. i = 20; 7. cout
4
2
8
garbage
Explanation:-
Answer: Option C. -> 8
The size of the double data type is 8. $ g++ size1.cpp $ a.out 8
Question 5.
What is the output of the following program?
1. #include 2. using namespace std; 3. int main() 4. { 5. int num = 0x20 + 020 + 20; 6. cout
2
4
Depends on compiler.
garbage
Explanation:-
Answer: Option C. -> Depends on compiler.
The sum of three numbers are belongs to different number systems, so the result is typecasted into integer. Output: $ g++ size.cpp $ a.out 4
Question 6.
Identify the incorrect option.
1
sizeof(float)
sizeof(char)
sizeof(N) = sizeof(signed N) = sizeof(unsigned N)
Explanation:-
Answer: Option C. -> sizeof(char)
sizeof(char) <= sizeof(wchar_t) <= sizeof(long)
Question 7.
Size of C++ objects are expressed in terms of multiples of the size of a ____ and the size of a char
is ____.
char, 1
int, 1
float, 8
char, 4
Explanation:-
Answer: Option A. -> char, 1
None.
Question 8.
Implementation dependent aspects about an implementation can be found in ____
Explanation:-
Answer: Option A. -> char, 1
The limit header holds the details of the machine dependent details.
Question 9.
It is guaranteed that a ____ has atleast 8bits and a ____ has atleast 16 bits.
int, float
char, int
bool, char
char, short
Explanation:-
Answer: Option D. -> char, short
None.
Question 10.
The size of an object or a type can be determined using which operator?
malloc
sizeof
malloc
calloc
Explanation:-
Answer: Option B. -> sizeof
The sizeof operator gives the size of the object or type.