edited by
894 views
2 votes
2 votes
#include <stdio.h>

int main(void) {
	int a=5, b=10;
	printf("%d%d",a,b);
	make_it(b,a,a+b);
	printf("%d%d",a,b);
	return 0;
}
int make_it(int x,int y, int z){
	x*=y+z;
	y=x<<1;
	z=x+y;

}
edited by

2 Answers

Best answer
3 votes
3 votes
Answer is 5 & 10.

Inside function make_it() we are not passing address of x,y,z back to main function. So, values of x,y & z do changes but only within make_it() func...not passed to main function. Therefore values of a & b remains same.

And the values inside make_it() function are:

$x = 10*(5+15) = 200; binary(x) = 11001000; y = x<<1; binary(y) = 110010000;  i.e. y = 400; z = 200+400 = 600;$
selected by
2 votes
2 votes

Answer will be 5, 10 and 5 , 10

At first of the C program when main will call , value of a will declare as 5 and value of b will be 10 and will print it for first time

Now, function make_it will call and passes the value b,a,a+b as value of x,y,z.

So, x=10 , y=5 , z=15

But here variable passed as call by value (not call by reference). So, x=x*(y+z) will be equal to 200

Next is a shift operation

There are two shift operation

Left Shift(<<) and right shift(>>). Shift operation done bitwise.So, we need to convert the number in binary and then have to do shift operation

Value of x is 200, and it's binary is 11001000 and if we do left shift , it will be 10010000 , which is 144

And finally z=x+y=200+144=344

But all these changes are for local variables and for function make_it() itself. So, there is no change in main() function. And that is why it will print 5 and 10 again in 2nd printf statement

edited by

Related questions

7 votes
7 votes
3 answers
2
Parshu gate asked Nov 20, 2017
792 views
What is the output of the following program?#include<stdio.h int main() { int array[]={10, 20, 30, 40}; printf(“%d”, -2[array]); return 0; }$-60$$-30$$60$Garbage valu...
0 votes
0 votes
1 answer
3
radha gogia asked Jul 25, 2015
449 views
#include<stdio.h int fun() { static int num = 16; return num ; } int main() { for(fun(); fun(); fun()) printf("%d ", fun()); return 0; }