1. In the following program, what would be the final output? Explain in
detail.
v oid c o p y a r r ( ch a r ∗p1 , ch a r p2 [ ] ) {
memcpy ( p2 , p1 , s i z e o f ( p1 ) ) ;
memcpy ( p2 , ‘ ‘ABCD’ ’ , 4 ) ;
}
i n t main ( ) {
ch a r a r r 1 [ 1 0 0 ] ;
ch a r a r r 2 [ 1 0 0 ] ;
p r i n t f ( ‘ ‘ Enter a s t r i n g : ’ ’ ) ;
s c a n f ( ‘ ‘%[ ˆ\n ] s ’ ’ , a r r 1 ) ;
c o p y a r r ( a r r 1 , a r r 2 ) ;
p r i n t f ( ‘ ‘ \ n %s ’ ’ , a r r 2 ) ;
r e t u r n 0 ;
}
2. Consider the following program:
i n t main ( v oid ) {
i n t a = 2 , ∗b = NULL;
b = &a ;
p r i n t f ( ‘ ‘%p ’ ’ , b + 1 ) ;
p r i n t f ( ‘ ‘%p ’ ’ , ( ch a r ∗) b + 1 ) ;
p r i n t f ( ‘ ‘%p ’ ’ , ( v oid ∗) b + 1 ) ;
}
Suppose the address of a is equal to 0x1000. What is the output of the
above program? Explain in detail.
What to submit:
• Write-up describing an explanation for the output (i.e. why you observe
what you observe), for both the cases.
Let us say that you have a program that uses SCHED_FIFO scheduling. How
would the vruntime variable for such a program be computed or updated ?
How is this different from how vruntime would be updated for SCHED_RR and
SCHED_NORMAL ?
What would be the output of the following program? Explain.
i n t main ( )
{
p i d t pid 1 ;
p r i n t f ( ‘ ‘ b e f o r e f o r k ( ) ’ ’ ) ;
i f ( ( pid 1=f o r k ()) >0)
{
w ai t pi d ( pid1 , NULL, 0 ) ;
}
e l s e i f ( pid 1 == 0 ) {
e x e c l ( ‘ ‘ / u s r / bin / bash ’ ’ , ‘ ‘ bash ’ ’ ,NULL ) ;
p r i n t f ( ‘ ‘ done l a u n c hi n g the s h e l l ’ ’ ) ;
}
e l s e {
p e r r o r ( ‘ ‘ f o r k ( ) ’ ’ ) ;
}
}
What to submit:
• Write-up describing an explanation for the output (i.e. why you observe
what you observe).
Two code snippets are being presented to you.
1. mov rax, 0x1234567812345678
xor ax, 0x11
mov rdi, ax
call printf
xor rax, 0x11
mov rdi, rax
call printf
2. int x=-2;
unsigned int y = -33;
int z;
z = x + y;
printf(‘‘%u %u %u’’, x,y,z);
printf(‘‘%d %d %d’’, x,y,z);
In both the parts (1) and (2), explain what the two printf function calls
result in. Explain the reasons for any differences in the two cases.
Try to compile the following code snippet (no need to link).
char add(float a,float b)
{
return (int)(round (a)+round (b)) ;
}
Would the compilation of this code snippet result in errors or warnings?
Would this code, if compiled and linked with a full fledged program result in
any logical errors? Answer both parts accurately.
What to submit:
• Command (with appropriate arguments) that were used to compile the
snippet.
• A writeup showing all the compilation errors and warnings that you may
have encountered and their possible explanations, along with the logical
errors (if any if you think there are, i.e.).
+findLongestSubString(StringBuilder) : StringBuilder
-Should accept StringBuilder as input and return StringBuilder
-Should find the longest substring that appears at both ends of a given StringBuilder
-Should return "Longest substring is not present in the given StringBuilder" if longest substring does not exist
-Should return "Give proper input" if input is empty StringBuilder
Sample Input:
playerplay
Sample Output:
Play
Sample Input:
playerplays
Sample output:
Longest substring is not present in the given StringBuilder
write a C code to add two polynomials having n number of unknown variables
Write a java program that will satisfy the given requirements using while loop:
A. It will display the given menu:
A - Arithmetic Series
B - Geometric Series
C - Harmonic Mean
D - Largest Prime Number
E - Largest Prime Number
Q - Quit the Program
B. The program will ask the user his/her choice.
C. If the choice is A,B,C,D or E, It will prompt the user for the required inputs, then compute and display the required outputs. If the choice is Q, the program will terminate
D. Validate all your inputs by promptingg for a new value if input is invalid.
E. Display also a description of your program
F. Program should execute for as long as the user wants to continue
G. Use of arrays is not allowed
Create a list of Employees(List can be as long as user wants) Program should save the
following information for each Employee: Name, Emp. No., Experience, Designation and
Salary. Now perform the following tasks:
a) Your program should save the information of only those employees whose experience is at least 2 years.
b) Display only those Employees whose Salary is greater than 50,000
c) Display the Employees alphabetically
Write a C++ program to create two pointers of integer type, now take values in these pointers and pass them to a function.Function will update both the values by adding “1” to them. Display the updated values in main.