Consider the following ANSI-C function.
int func(int start, int end){
int length=end+1-start;
if((length<1)||(start<0)||(end<0)){ return(0); }
if(length%3==0){
return(func(start+1, end));
} else if(length%3==1){
return(1+func(start, end-1));
} else {
return(func(start+2, end));
}
}
The maximum possible value that can be returned from this function is
____________. (answer in integer)
Note: Ignore syntax errors (if any) in the function.
This problem asks for the largest value that a self-recursive C function can produce, and the trick is to notice that the plus-one contribution to the answer is extremely rare.
Setting up a single-variable model: let \(n = end - start + 1\) denote how many integers lie in the current range. The function short-circuits to 0 once \(n\) drops below 1 (or once start or end goes negative, which we can always avoid by starting with a big enough range). Looking at the three branches:
1. \(n \bmod 3 = 0\) moves to length \(n-1\) with no bonus added.
2. \(n \bmod 3 = 1\) moves to length \(n-1\) and adds exactly 1 to the eventual answer.
3. \(n \bmod 3 = 2\) moves to length \(n-2\) with no bonus added.
Key observation (invariant): suppose at some point the length becomes a multiple of 3, say \(n = 3k\). Then the very next step uses branch 1 (since \(3k \bmod 3 = 0\)), landing on length \(3k - 1\), which is congruent to 2 mod 3. Branch 3 then fires, landing on \(3k - 3\), again a multiple of 3. So from a multiple of 3, the sequence of lengths cycles strictly between residues 0 and 2 modulo 3 all the way down to 0, and it can never land back on a length congruent to 1 modulo 3. Since only a length congruent to 1 mod 3 ever triggers the bonus, once you pass through a multiple of 3 you can never earn another bonus.
Consequence: the only chance to earn a +1 is at the very first call, if the initial length \(n_0 = end - start + 1\) happens to be congruent to 1 mod 3. After that single possible bonus, the length becomes \(n_0 - 1\), a multiple of 3, and by the invariant above the rest of the recursion contributes nothing more before hitting the base case.
Verifying with the smallest case: take \(start = 0, end = 0\), so \(n_0 = 1\). Then \(func(0,0) = 1 + func(0,-1)\), and \(func(0,-1)\) has length \(0\), which is less than 1, so it returns 0 immediately. The total is \(1 + 0 = 1\).
Since no chain of recursive calls can ever earn more than a single +1 bonus, the value returned by this function is always either 0 or 1, for any valid start and end. The maximum possible value it can return is therefore:
\(\boxed{1}\)
Arrange the following data types available in C language according to their size (smallest to largest):
A. signed long int
B. long double
C. unsigned char
D. unsigned int
Choose the correct answer from the options given below:

Suppose in a multiprogramming environment, the following C program segment is executed. A process goes into the I/O queue whenever an I/O related operation is performed. Assume that there will always be a context switch whenever a process requests an I/O, and also whenever the process returns from an I/O. The number of times the process will enter the ready queue during its lifetime (not counting the time the process enters the ready queue when it is run initially) is _________ (Answer in integer).
What is printed by the following ANSI C program?
#include<stdio.h>
int main(int argc, char argv[])
{
char a = 'P';
char b = 'x';
char c = (a & b) + '';
char d = (a | b) - '-';
char e = (a ^ b) + '+';
printf("%c %c %c\n", c, d, e);
return 0;
}
ASCII encoding for relevant characters is given below
