Consider the following ANSI-C program.
#include <stdio.h>
int main(){
int *ptr, a, b, c;
a=5; b=11; c=20;
ptr=&a; *ptr=c; ptr=&c;
a=*(&b); c=*ptr-a;
printf("%d",c);
return(0);
}
The output of this program is ____________. (answer in integer)
Note: Assume that the program compiles and runs successfully.
We trace the program line by line, tracking the values of the variables \(a\), \(b\), \(c\) and the pointer \(ptr\).
Step 1: Initial assignments.
\[ a = 5, \quad b = 11, \quad c = 20 \]
Step 2: Execute ptr = &a;
Now \(ptr\) holds the address of \(a\), so \(ptr\) points to \(a\).
Step 3: Execute *ptr = c;
This stores the current value of \(c\) (which is 20) into the location pointed to by \(ptr\), i.e. into \(a\). So now:
\[ a = 20 \]
Step 4: Execute ptr = &c;
Now \(ptr\) is redirected to point to \(c\) instead of \(a\).
Step 5: Execute a = *(&b);
The expression \(*(\&b)\) is simply \(b\) (dereferencing the address of \(b\) gives back \(b\)). Since \(b = 11\):
\[ a = 11 \]
Step 6: Execute c = *ptr - a;
Since \(ptr\) points to \(c\), \(*ptr\) is the current value of \(c\), which is still 20 (unchanged since Step 1). So:
\[ c = 20 - a = 20 - 11 = 9 \]
Step 7: The printf("%d", c); statement prints the current value of \(c\).
Final boxed answer:
\[ \boxed{c = 9} \]
A schedule of three database transactions \(T_1\), \(T_2\), and \(T_3\) is shown. \(R_i(A)\) and \(W_i(A)\) denote read and write of data item A by transaction \(T_i\), \(i = 1, 2, 3\). The transaction \(T_1\) aborts at the end. Which other transaction(s) will be required to be rolled back?

In C runtime environment, which one of the following is stored in heap?
Consider the following three ANSI-C programs, P1, P2, and P3.
P1
P2
P3
#include <stdio.h>
int a=5;
int main(){
int a=7;
return(0);
}
#include <stdio.h>
int main(){
int a=5;
int a=7;
return(0);
}
#include <stdio.h>
int main(){
int a=5;
float a=7;
return(0);
}
Which one of the following statements is true?
Consider the following C statements:
char *str1 = "Hello; /* Statement S1 */
char *str2 = "Hello;"; /* Statement S2 */
int *str3 = "Hello"; /* Statement S3 */
Which of the following options is/are correct?
Consider the following program in C:
#include <stdio.h>
void func(int i, int j) {
if(i < j) {
int i = 0;
while (i < 10) {
j += 2;
i++;
}
}
printf("%d", i);
}
int main() {
int i = 9, j = 10;
func(i, j);
return 0;
}
The output of the program is _________. (answer in integer)
Note: Assume that the program compiles and runs successfully.
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.