13. How much total space is required for the following C++ code fragment?
{
int a,b,c;
{
int d,e;
{
int f;
}
}
int g,h,i;
}
Assume each integer occupies 4 bytes.
When we exit the inner scopes, the variable memory is deallocated and hence, only outer variables have memory. Thus, the above code fragment requires at most 24 bytes of memory as at any given time, not more than 6 integer values are alive.
14. State whether the following statements are True or False:
(i) C++ programs use dynamic scoping when accessing a macro
[True] This is because macros are expanded textually.
(ii) In C++ expressions, operands in binary evaluation are evaluated in a left-to right order.
[False] This statement is false because the evaluation order isn't specified in C++ unlike Java, which is from left-right.
15. Why do Java compilers generate byte code instead of machine code?
Java compilers generate byte code instead of machine code to impart portability to the code.
16. What does the following C code do?
int i=2, j=4;
int list[]={6,7,18,-8,22,104};
list[++i,j]=77;
The above C code modifies the above values as:
i=3
j=4
list[]={6,7,18,-8,77,104}
17. What is the output of the following Java program?
System.out.println(1.0 + 1.0 + 1.0e17 - 1.0e17);
System.out.println(1.0e17 - 1.0e17 + 1.0 +1.0);
The o/p for the first statement is justified because of the Left-right execution in expression evaluation in Java. Here, boundary limits are crossed and hence 0.
In the second statement, answer is 2 because of the 1+1 evaluation.
18. What is type completeness principle?
The type completeness principle states that no operations should be arbitrarily restricted in the types of values involved.
19. What are the differences between Java and C++ arrays?
There are main 3 differences between C++ Arrays and Java Arrays:
(i) C++ arrays are static type(i.e., user needs to provide size at compile time itself), while Java arrays are of flexible type(because of obj.type declaration)
(ii) One can determine the length of arrays in Java easily through the syntax: arrayname.length; while this is not possible in C++.
(iii) C++ Arrays are either stored in the Stack/Heap/Static area, while Java arrays are stored only in the Heap area.
20. Explain the difference between type declaration and type definition in C++ with an example.
(i) A declaration introduces names into a translation unit or redeclares names introduced by previous declarations. A declaration specifies the interpretation and attributes of these names.
(ii) A declaration is a definition unless it declares a function without specifying the function's body, it contains the extern specifier or a linkage-specification and neither an initializer nor a function-body, it declares a static data member in a class declaration , it is a class name declaration, or it is a typedef declaration, a using-declaration, or a using-directive.
21. What does the following Java statement do? (where marks is of type int)
boolean is A = (90<=marks<=100); This code produces a syntax error as logical comparisons in Java produce Boolean values, and Boolean values can't be compared with integer types. For correct of code, we can write: boolean is A: ((90 <= marks) && (marks <= 100))
22. What is the output of the following Java program?
double x = double (3/5);
System.out.println(x);
The output is 0
23. What happens when you evaluate the following expressions in Java? 17/0
17%0
17.0/0.0
17.0%0.0
All the 4 statements produce errors.
The 1st and 2nd expressions produce exceptions.
While, the 3rd gives Infinite number.
Lastly, 4th expression gives Not a number.
Please post answers to these questions as comments for this post. They will be later integrated in it.
{
int a,b,c;
{
int d,e;
{
int f;
}
}
int g,h,i;
}
Assume each integer occupies 4 bytes.
When we exit the inner scopes, the variable memory is deallocated and hence, only outer variables have memory. Thus, the above code fragment requires at most 24 bytes of memory as at any given time, not more than 6 integer values are alive.
14. State whether the following statements are True or False:
(i) C++ programs use dynamic scoping when accessing a macro
[True] This is because macros are expanded textually.
(ii) In C++ expressions, operands in binary evaluation are evaluated in a left-to right order.
[False] This statement is false because the evaluation order isn't specified in C++ unlike Java, which is from left-right.
15. Why do Java compilers generate byte code instead of machine code?
Java compilers generate byte code instead of machine code to impart portability to the code.
16. What does the following C code do?
int i=2, j=4;
int list[]={6,7,18,-8,22,104};
list[++i,j]=77;
The above C code modifies the above values as:
i=3
j=4
list[]={6,7,18,-8,77,104}
17. What is the output of the following Java program?
System.out.println(1.0 + 1.0 + 1.0e17 - 1.0e17);
System.out.println(1.0e17 - 1.0e17 + 1.0 +1.0);
The o/p for the first statement is justified because of the Left-right execution in expression evaluation in Java. Here, boundary limits are crossed and hence 0.
In the second statement, answer is 2 because of the 1+1 evaluation.
18. What is type completeness principle?
The type completeness principle states that no operations should be arbitrarily restricted in the types of values involved.
19. What are the differences between Java and C++ arrays?
There are main 3 differences between C++ Arrays and Java Arrays:
(i) C++ arrays are static type(i.e., user needs to provide size at compile time itself), while Java arrays are of flexible type(because of obj.type declaration)
(ii) One can determine the length of arrays in Java easily through the syntax: arrayname.length; while this is not possible in C++.
(iii) C++ Arrays are either stored in the Stack/Heap/Static area, while Java arrays are stored only in the Heap area.
20. Explain the difference between type declaration and type definition in C++ with an example.
(i) A declaration introduces names into a translation unit or redeclares names introduced by previous declarations. A declaration specifies the interpretation and attributes of these names.
(ii) A declaration is a definition unless it declares a function without specifying the function's body, it contains the extern specifier or a linkage-specification and neither an initializer nor a function-body, it declares a static data member in a class declaration , it is a class name declaration, or it is a typedef declaration, a using-declaration, or a using-directive.
21. What does the following Java statement do? (where marks is of type int)
boolean is A = (90<=marks<=100); This code produces a syntax error as logical comparisons in Java produce Boolean values, and Boolean values can't be compared with integer types. For correct of code, we can write: boolean is A: ((90 <= marks) && (marks <= 100))
22. What is the output of the following Java program?
double x = double (3/5);
System.out.println(x);
The output is 0
23. What happens when you evaluate the following expressions in Java? 17/0
17%0
17.0/0.0
17.0%0.0
All the 4 statements produce errors.
The 1st and 2nd expressions produce exceptions.
While, the 3rd gives Infinite number.
Lastly, 4th expression gives Not a number.
Please post answers to these questions as comments for this post. They will be later integrated in it.
No comments:
Post a Comment