You are on page 1of 3

Quiz recursion & pass by value

Cs1
1. Trace the following code:
#include <stdio.h>
int SomeFunction(int *m)
{
*m=(*m)+1;
return(*m);
}
void main (void )
{
int *a,b=1,c=2,d=3,*e;
a=&d;
e=&c;
*a=1;
printf(“%d \t %d \t %d \n”,*e, c, d);
b=SomeFunction(&c);//3
printf(“%d \t %d \t %d \n”, d, c, *e);
}
Cs2
2. State the effect of each of the following statements in a subprogram:
#include <stdio.h>
void increase(int a){
a++;
}
void increase2(int *a){
*a = *a + 1;
}
int main(){
int x=5;
increase(x):
printf("%d ",x);
increase2(&x);
printf("%d ",x);
{
Cs3
3. Write a program in C to calculate the sum of numbers from 1
to n using recursion.

Cs4
4. Write a program in C to calculate factorial 5!

Cs5
5. Trace the following code:
#include <stdio.h>
void duplicate(int x,int y)
{
x=3;
y=2;
}
void duplicate2(int *x, int *y){
*x=3;
*y=2;
}
int main(){
int a,b;
a=b=6;
duplicate(a,b):

printf("%d,%d\n",a,b);
duplicate2(&a,&b);

printf("%d,%d",a,b);

You might also like