C - Functions - Discussion

You Are Here :: Home > C > Functions - Discussion

 



Q.

void swap(int,int);
void main()
{
int a=10,b=15;
clrscr();
printf("Befor swap a=%d ,b=%d",a,b);
swap(a,b);
printf("\nAfter swap a=%d ,b=%d",a,b);
getch();
}
void swap(int a,int b)
{
int c;
c=a;
a=b;
b=c;
}

A. Before swap a=10,b=15
After swap a=10,b=20
B. Before swap a=10,b=15
After swap a=10,b=15
C. Before swap a=10,b=15
After swap a=15,b=20
D. Before swap a=10,b=15
After swap a=15,b=10

Answer: Option A
Explaination:

a and b are auto variable (default storage class is auto) .Here its scope is only within main function.After the main function both a and b will die.We are swapping outside the main function so value of a and b is not changing.



Discussion

Your Comments Goes here...
NameDiscussion