Home » Programming & Data Structure » Programming and data structure miscellaneous » Question

Programming and data structure miscellaneous

Programming & Data Structure

  1. The output of the following C program is ______.
    void f1(int a, int b)
    {
       int c;
    c=a; a=b; b=c;
    }
    void f2(int *a, int *b)
    {
       int c;
       c=*a; *a=*b; *b=c;
    }
    int main ()
    {
       int a=4, b=5, c=6;
       f1(a, b);
       f2(&b, &c);
       printf(“%d”, c–a–b);
    }
    1. -5
    2. 4
    3. 5
    4. -4
Correct Option: A

In function "main ()"
f1 is called by value, so local variables a, b, c of f1 are customized but not the local variables a, b, c of main function.
f2 is called by reference.
int main () {
int a = 4, b = 5, c = 6
f1(a, b)
f2(&b, &c)
printf ("%d", c-a-b);
}
f2(int *a, int *b)
{
int c;
c = * a; c 5
* a = b; [will change 'b' value of main to c value of main]
*b = c; [will change 'c' value of main to c value of f2]
}



Your comments will be displayed only after manual approval.