EXAM 1 REVIEW!The Gauntlet!!!!
Question 1: The following is a preprocessor directive:
a) int main (void)
b) double fct1 (double a, double b);
c) #define N 100
d) int numbers=100;
Question 2: The following demos FILE input
a) fscanf(stdin, “%d”, &data);
b) fscanf(“%d”, &data);
c) fprintf(fpout, “%d”, data);
d) fscanf(fpin, “%d”, &data);
Question 3: int a; a=31%11%3;
a) a = 0
b) a = 1.9375
c) a = Divide by zero so NaN
d) a = 1
Question 4: int b; b=14/3*3;
a) b = 14
b) b = 12
c) b = 6
d) b = 1
Question 5: How many errors can you spot?
int x,y; double sum;
scanf(“%d %d”,x,y);
x+y = sum;
printf(“Sum=%d\n”, sum);
a) None
b) 5
c) 2
d) 4
Question 6: Which is illegal?
a) int Double;
b) double return;
c) unsigned short static int x = -1;
d) char pause = 5;
Question 7: Given: double x=3.0, y= 4.0, z=2.0; Which is FALSE?
a) x = 1.0 && x == 2.0
b) x > z && y > z
c) x = 2.0 || y != 4.0
d) z < = x && x <= y
Question 8: Which function call is valid double fct(int p, double q); //function prototype
int x,y,z; double a,b,c; //declarations in main()
a) x = fct(x,y)
b) x = fct(y,a)
c) a = fct(b,c)
d) a = fct(x,a);
Question 9: printf(“$$%c\t%%\t%c”,’1’,’!’); What prints?
a) $1%!
b) $1 % !
c) $’1’%% !
d) $$1 % !
Question 10: printf(“Sum = %8.3lf”,7.8); What prints?
a) Sum = ▒ ▒ ▒ ▒ ▒ ▒ ▒ 7.800
b) Sum = ▒ ▒ ▒ ▒ ▒ 7.800
c) Sum = ▒ ▒ ▒ 7.800
d) Sum = 7.800
Question 11: What prints?
/*Section of code in main() */int n=5, m=3;
n = fct(m);printf(“n = %d m = %d\n”,n,m);
/*function*/int fct(int n){
int m = 4;return (n + m);
}
Question 12: What prints?
int n=5, m;
for(m=0; m<n; m++)if(m=n)
printf(“m=%d”,m);
Question 13: What prints?
int n=5, m=0;
while(--n)printf(“%d\t”,n);
Question 14: What prints?
//Section in main()int n[]={5,4,3}, m[]={1, 2, 3};fct1(3,n,m);printf(“%d %d”,m[2],n[0]);
void fct1(int n, int a[], int b[]){int j;for(j=0; j<(n-1); j++){
b[j] = b[j] - b[j+1];a[j] = a[j] - 2*b[j];
}}
Question 15: What prints?
//Section in main()int n[]={5,4,3}, m[]={1, 2, 3};m[2] = fct1(3,n,m);printf(“%d %d”,m[2],n[0]);
int fct1(int n, int a[], int b[]){int j;for(j=0; j<(n-1); j++){
b[j] = b[j] - b[j+1];a[j] = a[j] - 2*b[j];
}return (b[j]-1);}
EXAM 1 REVIEW!Last person standing wins!!!
Question 1: The following is a preprocessor directive:
a) int main (void)
b) double fct1 (double a, double b);
c) #define N 100
d) int numbers=100;
Question 2: The following is an example of FILE input
a) fscanf(stdin, “%d”, &data);
b) fscanf(“%d”, &data);
c) fprintf(fpout, “%d”, data);
d) fscanf(fpin, “%d”, &data);
Question 3: int a; a=31%11%3;
a) a = 0
b) a = 1.9375
c) a = Divide by zero so NaN
d) a = 1
Question 4: int b; b=14/3*3
a) b = 14
b) b = 12
c) b = 6
d) b = 1
Question 5: How many errors can you spot?
int x,y; double sum;
scanf(“%d %d”,x,y);
x+y = sum;
printf(“Sum=%d\n”, sum);
a) None
b) 5
c) 2
d) 4
int x,y; double sum;
scanf(“%d %d”,&x,&y);
sum = x+y;
printf(“Sum = %lf\n”, sum);
Question 6: Which is illegal?
a) int Double;
b) double return;
c) unsigned short static int x = -1;
d) char pause = 5;
Question 7: Given: double x=3.0, y= 4.0, z=2.0; Which is FALSE?
a) x = 1.0 && x == 2.0
b) x > z && y > z
c) x = 2.0 || y != 4.0
d) z < = x && x <= y
Question 8: Which function call is valid double fct(int p, double q); //function prototype
int x,y,z; double a,b,c; //declarations in main()
a) x = fct(x,y)
b) x = fct(y,a)
c) a = fct(b,c)
d) a = fct(x,a);
Question 9: printf(“$$%c\t%%\t%c”,’1’,’!’); What prints?
a) $1%!
b) $1 % !
c) $’1’%% !
d) $$1 % !
Question 10: printf(“Sum = %8.3lf”,7.8); What prints?
a) Sum = ▒ ▒ ▒ ▒ ▒ ▒ ▒ 7.800
b) Sum = ▒ ▒ ▒ ▒ ▒ 7.800
c) Sum = ▒ ▒ ▒ 7.800
d) Sum = 7.800
/*Section of code in main() */int n=5, m=3;
n = fct(m);printf(“n = %d m = %d\n”,n,m);
/*function*/int fct(int n){
int m = 4;return (n + m);
}
Question 11: What prints?
n = 7 m = 3
Question 12: What prints?
int n=5, m;
for(m=0; m<n; m++)if(m=n)
printf(“m=%d”,m);
m=5
Question 13: What prints?
int n=5, m=0;
while(--n)printf(“%d\t”,n);
4 3 2 1
Question 14: What prints?
//Section in main()int n[]={5,4,3}, m[]={1, 2, 3};fct1(3,n,m);printf(“%d %d”,m[2],n[0]);
void fct1(int n, int a[], int b[]){int j;for(j=0; j<(n-1); j++){
b[j] = b[j] - b[j+1];a[j] = a[j] - 2*b[j];
}}
3 7
Question 15: What prints?
//Section in main()int n[]={5,4,3}, m[]={1, 2, 3};m[2] = fct1(3,n,m);printf(“%d %d”,m[2],m[0]);
int fct1(int n, int a[], int b[]){int j;for(j=0; j<(n-1); j++){
b[j] = b[j] - b[j+1];a[j] = a[j] - 2*b[j];
}return (b[j]-1);}
2 -1
GOOD LUCK!!!