UGC NET JULY 2018 (Computer Science And Applications Paper-II) (Question 3-4)
Q3. What is the output of the following JAVA program ?
(1) 12:15
(2) 15:12
(3) 12:12
(4) 15:15
(1) 5 ,2, 1282
(2) 5 ,2, 52
(3) 5 ,2, 25
(4) 5 ,2, 517
Reason : This is one is interesting question in exam. First we have to know about Big-endian and little-endian are terms that describe the order in which a sequence of bytes are stored in computer memory. Big-endian is an order in which the "big end" (most significant value in the sequence) is stored first (at the lowest storage address). Little-endian is an order in which the "little end" (least significant value in the sequence) is stored first. For example, in a big-endian computer, the two bytes required for the hexadecimal number 4E52 would be stored as 4E52 in storage (if 4E is stored at storage address 1000, for example, 52 will be at address 1001). In a little-endian system, it would be stored as 524E (52 at address 1000, 4E at 1001).
Here we have little - endian in our question. In code we have two union members short int one and char two[2]. In line 11,12 we have numeric values 5 and 2 in char array (without single quote '5' and '2'). In line 13 the output also shows result with %d (i.e. represents for numeric values) which is okay for output 5, 2 but how third values came because we did not provided any value to union member short int one. Just suppose binary conversion of
5 is 00000101 and 2 is 00000010
Now as per question requirement little - endian representation of multi-byte data in which Least Significant Byte (LSB) is stored at the lowest memory address. Therefore
Now 00000010-00000101 convert this to Decimal value
After converting the combination of both numbers we have 517 at third location and final result 5, 2, 517.
Q3. What is the output of the following JAVA program ?
class simple
{
public static void main(String []args)
{
simple obj = new simple();
obj.start();
}
void start()
{
long [] P ={3,4,5};
long []Q = method(P);
System.out.print(P[0]+P[1]+P[2]+" : ");
System.out.print(Q[0]+Q[1]+Q[2]+" : ");
}
long [] method(long []R)
{
R[1] = 7;
return R;
}
}//end of class
(1) 12:15
(2) 15:12
(3) 12:12
(4) 15:15
Reason : Initially array P as {3,4,5}. When we pass array P to method as method(P); the method function replaces the value of index 1 i.e. 4 with 7. Now new updated array is value {3,7,5}.
This new returned value reflects on both arrays respectively P and Q. Last the print function adds all index location values of both arrays separately and shows output 15:15.
Q4. What is the output of following 'C' program? (Assuming little - endian representation of multi-byte data in which Least Significant Byte (LSB) is stored at the lowest memory address.)
1. #include <stdio.h> 2. #include <stdlib.h>/**/ 3. int main() 4. { 5. union saving 6. { 7. short int one; 8. char two[2]; 9. }; 10. union saving m; 11. m.two[0] = 5; 12. m.two[1] = 2; 13. printf("%d, %d, %d\n",m.two[0],m.two[1],m.one); 14. return 0; 15. }
(1) 5 ,2, 1282
(2) 5 ,2, 52
(3) 5 ,2, 25
(4) 5 ,2, 517
Reason : This is one is interesting question in exam. First we have to know about Big-endian and little-endian are terms that describe the order in which a sequence of bytes are stored in computer memory. Big-endian is an order in which the "big end" (most significant value in the sequence) is stored first (at the lowest storage address). Little-endian is an order in which the "little end" (least significant value in the sequence) is stored first. For example, in a big-endian computer, the two bytes required for the hexadecimal number 4E52 would be stored as 4E52 in storage (if 4E is stored at storage address 1000, for example, 52 will be at address 1001). In a little-endian system, it would be stored as 524E (52 at address 1000, 4E at 1001).
Here we have little - endian in our question. In code we have two union members short int one and char two[2]. In line 11,12 we have numeric values 5 and 2 in char array (without single quote '5' and '2'). In line 13 the output also shows result with %d (i.e. represents for numeric values) which is okay for output 5, 2 but how third values came because we did not provided any value to union member short int one. Just suppose binary conversion of
5 is 00000101 and 2 is 00000010
Lowest Address (1000) | Highest Address(1001) |
00000101 | 00000010 |
Now as per question requirement little - endian representation of multi-byte data in which Least Significant Byte (LSB) is stored at the lowest memory address. Therefore
Lowest Address (1000) | Highest Address(1001) |
00000010 | 00000101 |
512+0+0+0+0+0+0+4+0+1 = 517 |
0 comments:
Post a Comment