CDS Q8
CDS Q8
CDS Q8
int f(int n)
{
static int r = 0;
if (n <= 0) return 1;
if (n > 3)
{
r = n;
return f(n-2)+2;
}
return f(n-1)+r;
}
int main()
{
printf("%d", f(5));
}
(a) 5 (b) 7
(c) 9 (d) 18
int main()
{
static int i=5;
if(--i){
main();
printf("%d ",i);
1
}
}
(a) 4 3 2 1 (b) 1 2 3 4
(c) 0 0 0 0 (d) Compiler Error
4.
#include <stdio.h>
int main()
{
static int i=5;
if (--i){
printf("%d ",i);
main();
}
}
(a) 4 3 2 1 (b) 1 2 3 4
(c) 4 4 4 4 (d) 0 0 0 0
5.
int main()
{
int x = 5;
int * const ptr = &x;
++(*ptr);
printf("%d", x);
return 0;
}
6.
2
#include<stdio.h>
int main()
{
typedef static int *i;
int j;
i a = &j;
printf("%d", *a);
return 0;
}
7. Output?
#include<stdio.h>
int main()
{
typedef int i;
i a = 0;
printf("%d", a);
return 0;
}
8.
#include<stdio.h>
int main()
{
typedef int *i;
int j = 10;
i *a = &j;
printf("%d", **a);
3
return 0;
}
9. Output?
#include<stdio.h>
int fun()
{
static int num = 16;
return num--;
}
int main()
{
for(fun(); fun(); fun())
printf("%d ", fun());
return 0;
}
10.
#include<stdio.h>
int main()
{
int x = 10;
static int y = x;
if(x == y)
printf("Equal");
else if(x > y)
printf("Greater");
else
printf("Less");
4
return 0;
}
int f(int n)
{
static int i = 1;
if (n >= 5)
return n;
n = n+i;
i++;
return f(n);
}
(a) 5 (b) 6
(c) 7 (d) 8
#include<stdio.h>
int a, b, c = 0;
void prtFun (void);
int main ()
{
5
static int a = 1; /* line 1 */
prtFun();
a += 1;
prtFun();
printf ( "\n %d %d " , a, b) ;
}
(a) 31 (b) 42
41 61
42 61
(c) 42 (d) 31
62 52
20 52
14. What output will be generated by the given code segment if:
(a) 31 (b) 42
41 61
42 61
(c) 42 (d) 42
62 42
20 20
15. Output?
#include<stdio.h>
6
int main()
{
register int i = 10;
int *ptr = &i;
printf("%d", *ptr);
return 0;
}
16.
#include<stdio.h>
int main()
{
extern int i;
printf("%d ", i);
{
int i = 10;
printf("%d ", i);
}
}
17. Output?
#include <stdio.h>
int main(void)
{
int i = 10;
const int *ptr = &i;
*ptr = 100;
7
printf("i = %d\n", i);
return 0;
}
#include <stdio.h>
int fun(int n)
{
static int s = 0;
s = s + n;
return (s);
}
int main()
{
int i = 10, x;
while (i > 0)
{
x = fun(i);
i--;
}
printf ("%d ", x);
return 0;
}
19.
#include <stdio.h>
char *fun()
{
8
static char arr[1024];
return arr;
}
int main()
{
char *str = "ravindrababus";
strcpy(fun(), str);
str = fun();
strcpy(str, "gatessquiz");
printf("%s", fun());
return 0;
}
20.
#include <stdio.h>
int main()
{
int i = 1024;
for (; i; i >>= 1)
printf("GatesQuiz");
return 0;
}
(a) 10
(b) 11
(c) Infinite
(d) The program will show compile-time error