Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

A. Explain The Role of Static Variable B. Explain Working of This Code With Its Output? (1+ 3 Marks)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

THE LNM INSTITUTE OF INFORMATION TECHNOLOGY, JAIPUR

Final Paper (Part IV)


Computer Programming

Name:.......................................................Roll No.......................................

1. void fun(int n, int sum)


{
int k = 0;
static int j = 0;
if (n == 0) return;
k = n % 10; j = n / 10;
sum = sum + k;
fun (j, sum);
printf ("K=%d\n,", k);
printf("j=%d\n" j);
}
int main ()
{
int a = 2048, sum = 0;
fun (a, sum);
printf ("Sum is %d\n", sum);

}
a. Explain the role of static variable
b. Explain working of this code with its output? (1+ 3 Marks)

1
2. Consider the following C declaration
struct {
short s [5]
union {
float y;
long z;
}u;
} t;

Assume that variable of the type short,


float and long occupy 2 bytes, 4 bytes and
8 bytes, respectively. What will be the
memory requirement for variable t?
Specify with reason. (2 Marks)

3. Consider the following three C functions as P1, P2, P3. Explain what each of these functions
are performing. Will they work properly or not explain with specific reason. Give Justification
of return value (IF THEY WORK) for each function individually. (3 Marks)

P1: P2: P3:


int * g ( ) int * g () int *g ()
{ { {
int x = 10; int * px; int *px;
return (&x); *px = 10; px = (int *) malloc (sizeof(int));
} return px; *px = 10;
} return px;
}

2
4. Consider the following C function
void swap (int a, int b)
{
int temp;
temp = a;
a = b;
b = temp;
}

In order to exchange the values of two variables x and y what are the correct options from given
below. Give Justification for each option (4 Marks)
i. call swap (x, y)
ii. call swap (&x, &y)
iii. swap (x,y) cannot be used as it does not return any value
iv. swap (x,y) cannot be used as the parameters are passed by value

3
Write a function calculate which takes an array of n element and return its sum,
average and maximum (without using structure and array for these values). Write
complete program including function calling. (7 marks)

(Hint : Use call by address method of parameter passing)

You might also like