
Program Analysis:
We can determine the output by examining the scope and the effect of the pointer indirection within the function call.
Step 1: Memory Initialization in main
Two integer variables are allocated in the stack: a (20) and b (25).A pointer z is then initialized to store the memory address of a ($\&a$).
Step 2: Function Scope Analysis (foo)
The function foo(int *p, int x) is invoked.
p is a copy of z, meaning p now also holds the address of a.x is a local copy of b (value 25). Changes to x would not affect b.
Step 3: Pointer Indirection and Dereferencing
Inside the function, the instruction *p = x; is executed.This does not change the pointer itself, but rather the value stored at the address p is holding.Since p points to a, the memory location of a is overwritten with the value of x (25).
Final Answer:
When control returns to main, the printf retrieves the current value from a's memory address. Output = 25
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).
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:
What is printed by the following ANSI C program?
#include<stdio.h>
int main(int argc, char argv[])
{
int a[3][3][3] = {
{1, 2, 3, 4, 5, 6, 7, 8, 9},
{10, 11, 12, 13, 14, 15, 16, 17, 18},
{19, 20, 21, 22, 23, 24, 25, 26, 27}};
int i = 0, j = 0, k = 0;
for( i = 0; i < 3; i++){
for(k = 0; k < 3; k++)
printf("%d ", a[i][j][k]);
printf("\n");
}
return 0;
}
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
