Professional Documents
Culture Documents
Homework 7: Solutions Will Be Uploaded Tommorow
Homework 7: Solutions Will Be Uploaded Tommorow
main( )
{
static int a = 1; /* Line 1 */
prtFun( );
a += 1; Question 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);
}
int a, b, c = 0;
void prtFun(void); Question. What output will be generated by
the given code segment if:
Line 1 is replaced by auto int a = 1; and
main( ) Line 2 is replaced by register int a = 2;
{
static int a = 1; /* Line 1 */
prtFun( );
a += 1; Question 2
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);
}
#include<stdio.h>
auto int var=200;
main()
{
printf(”The value of var is %d",var);
}
a) 200 Question 3
b) garbage value
c) compilation error
d) 0
What will be output of the program on
#include<stdio.h> execution?
fib_term()
{
static int a=0,b=1;
int c;
c=a+b;a=b;b=c;
return c;
}
main()
Question 4
{
int count=0,i;
for(i=0;i<5;i++)
printf(“%d “,fib_term());
}
a) x=0, y=0
#include<stdio.h> x=1, y=1
int main() x=2, y=2
{
int i;
for(i=0;i<3;i++) b) x=0, y=0
{ x=0, y=1
int x=0; x=0, y=2
static int y=0;
printf("x=%d, y=%d\n",x++,y++);
} c) x=0, y=0
return 0; x=0, y=0
} x=0, y=0
d) x=1, y=1
x=2, y=2
x=3, y=3
Question 5
a) x=0, y=0
#include<stdio.h> x=1, y=1
int main() x=2, y=2
{
int i;
for(i=0;i<3;i++) b) x=0, y=0
{ x=0, y=1
int x=0; x=0, y=2
static int y;
y=0;
printf("x=%d, y=%d\n",x++,y++); c) x=0, y=0
} x=0, y=0
return 0; x=0, y=0
}
d) x=1, y=1
x=2, y=2
x=3, y=3
Question 6
#include<stdio.h>
a) 200 200
b) 200 0
c) 200 garbage
d) Compilation error
Question 8
Question 9
#include <stdio.h>
int main() {
int k = 0;
Which of the following is true ?
int j = 0;
while (k == j)
{
A. There is compilation error.
int k;
B. There is no compilation error and 31 is
for (k = 0; k < 3; k++)
printed.
j = j+k;
C. There is run time error.
}
D. There is no compilation error and 34 is
k++;
printed.
printf("%d", j) ;
printf("%d", k) ;
return 0;
}
Question 10