Functions


Q21.

Consider the C functions foo and bar given below: int foo (int val ) { int x = 0; while (val > 0) { x = x + foo(val--); } return val ; } int bar (int val ) { int x = 0; while (val > 0) { x = x + bar(val-1);} return val ; } Invocations of foo(3) and bar(3) will result in:
GateOverflow

Q22.

What is the output of the C++ program? #include < iostream > using namespace std; void square(int *x){ *x = (*x)++ * (*x); } void square(int *x, int *y){ *x = (*x) * --(*y); } int main() { int number = 30; square(&number, &number); cout < < number; return 0; }
GateOverflow

Q23.

In the following procedure Integer procedure P(X,Y); Integer X,Y; value x; begin K=5; L=8; P=x+y; endX is called by value and Y is called by name. If the procedure were invoked by the following program fragment K=0; L=0; Z=P(K,L);then the value of Z will be set equal to
GateOverflow

Q24.

Consider the following two functions. The output printed when fun1(5) is called is
GateOverflow

Q25.

What is the output in a 32 bit machine with 32 bit compiler? #include < stdio.h > rer(int **ptr2, int **ptr1) { int *ii; ii=*ptr2; *ptr2=*ptr1; *ptr1=ii; **ptr1*=**ptr2; **ptr2+=**ptr1; } void main(){ int var1=5, var2=10; int *ptr1=&var1,*ptr2=&var2 rer(&ptr1,&ptr2); printf("%d %d",var2,var1); }
GateOverflow

Q26.

What will be the output of the following C program? void count(intn){ static intd=1; printf("%d ",n); printf("%d ",d); d++; if(n&gt1) count(n-1); printf("%d ",d); } void main(){ count(3); }
GateOverflow

Q27.

What is the output of the following program? #include < stdio.h > int tmp=20; main() { printf("%d", tmp); func(); printf("%d", tmp); } func() { static int tmp=10; printf("%d", tmp); }
GateOverflow

Q28.

Consider the following program written in pseudo-code. Assume that x and y are integers. Count(x,y) { if (y != 1){ if (x != 1) { print("*"); Count(x/2, y); } else { y = y-1; Count(1024, y); } } } The number of times that the print statement is executed by the call Count(1024,1024) is _____.
GateOverflow

Q29.

What does the following C-statement declare? int (*f) (int * );
GateOverflow

Q30.

Consider the following C functions. The return value of fun2(5) is ______
GateOverflow