Consider the following code fragment
void foo(int x, int y) {
x+=y;
y+=x;
}
main() { int x=5.5; foo(x,x); } What is the final value of x in both call by value and call by reference, respectively?
GATE CSE · Programming In C
Practice problems for Function in Programming in C.
114 questions · 20 PYQs · 0 AI practice · GATE CSE 2027
Consider the following code fragment
void foo(int x, int y) {
x+=y;
y+=x;
}
main() { int x=5.5; foo(x,x); } What is the final value of x in both call by value and call by reference, respectively?
Consider the following function written in the C programming language.
void foo(char *a) {
if ( *a && *a != ' ') {
foo(a+1);
putchar(*a);
}
}
The output of the above function on input is
Consider the following recursive C function.
void get(int n) {
if (n<1) return;
get(n-1);
get(n-3);
printf("%d", n);
}
If get(6) function is being called in main()then how many times will the get()function be invoked before returning to the main()?
The following program main() { inc(); inc(); inc(); } inc() { static int x; printf("%d", ++x); }
Suppose c=(c[0],...,c[k-1]) is an array of length k, where all the entries are from the set {0,1}. For any positive integers a and n, consider the following pseudocode. If k=4, c=(1,0,1,1), a=2 and n=8, then the output of DOSOMETHING(c,a,n) is _____.

Consider the following C program. #include < stdio.h > int f1(void); int f2(void); int f3(void); int x = 10;
int main( ) {
int x = 1;
x += f1( ) + f2( ) + f3( ) + f2( );
printf("%d", x);
return 0;
}
int f1() {
int x = 25;
x++;
return x;
}
int f2() {
static int x = 50;
x++;
return x;
}
int f3() {
x *= 10;
return x
}
; The output of the program is ________.
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);
}
Consider the following C function.
int fun(int n) {
int x=1,k;
if (n==1) return x;
for (k=1; k < n; ++k) x = x + fun(k) * fun(n-k);
return x;
}
The return value of fun(5) is ________.
Consider the following function
double f (double x) {
if ( abs (x*x - 3) < 0. 01) return x;
else return f (x / 2 + 1.5/x);
}
Give a value q (to 2 decimals) such that f(q) will return q:______
Consider the function func shown below:
int func(int num) {
int count = 0;
while (num) {
count++;
num >> = 1;
}
return (count);
}
The value returned by func(435)is __________.
Consider the C function given below
int f(int j) {
static int i = 50;
int k;
if (i == j) {
printf("something");
k = f(i);
return 0;
} else return 0;
}
Which one of the following is TRUE?
Which of the following is true with respect to Reference?
What is the time complexity for the following C module? Assume that .
int module(int n) {
if (n == 1) return 1;
else return (n + module(n-1));
}
Consider the following psuedocode: x: integer := 1 y: integer := 2 procedure add x:= x + y procedure second (P: Procedure) x: integer := 2 p() procedure first y: integer := 3 second (add) first () write_integer(x) What does it print if the language uses dynamic scoping with deep binding?
What is the return value of f(p,p), if the value of p is initialized to 5 before the call? Note that the first parameter is passed by reference, whereas the second parameter is passed by value.
int f (int &x, int c) {
c = c - 1;
if (c==0) return 1;
x = x + 1;
return f(x,c) * x;
}
Consider the following C code segment. int a, b, c = 0; void prtFun(void); main( ) { static int a = 1; /* Line 1 */ prtFun( ); a += 1; prtFun( ); printf(" \n %d %d ", a, b); }
void prtFun(void) {
static int a = 2;
/* Line 2 */ int b = 1;
a += ++b;
printf(" \n %d %d ", a, b);
}
What output will be generated by the given code segment if: Line 1 is replaced by auto int a = 1; Line 2 is replaced by register int a = 2;
Consider the following C code segment. int a, b, c = 0; void prtFun(void); main( ) { static int a = 1; /* Line 1 */ prtFun( ); a += 1; prtFun( ); printf(" \n %d %d ", a, b); }
void prtFun(void) {
static int a = 2;
/* Line 2 */ int b = 1;
a += ++b;
printf(" \n %d %d ", a, b);
}
What output will be generated by the given code segment?
Consider the following recursive C function that takes two arguments
unsigned int foo(unsigned int n, unsigned int r) {
if (n > 0) return (n%r + foo (n/r, r ));
else return 0;
}
What is the return value of the function foo when it is called as foo (513, 2)?
Consider the following recursive C function that takes two arguments
unsigned int foo(unsigned int n, unsigned int r) {
if (n > 0) return (n%r + foo (n/r, r ));
else return 0;
}
What is the return value of the function foo when it is called as foo (345, 10) ?
What does the following program print? #include < stdio.h >
void f (int *p, int * q) {
p=q;
*p=2;
}
int i= 0, j= 1;
int main ( ) {
f(&i, & j);
printf( "%d%d \ n", i,j);
return 0;
}
Want unlimited AI-generated Function questions?
Sign up free and practice with adaptive difficulty — Easy, Medium, Hard. New questions every session.
Start practising for free →