FINAL EXAM REVIEW Jeopardy

Download Report

Transcript FINAL EXAM REVIEW Jeopardy

FINAL EXAM REVIEW!!
Lets play C-eopardy!!!
(Answer in the form of answers!!)
Feel free to hum along!
Arrays
Functions
&
Macros
Strings
Pointers
Loops
100
100
100
100
100
200
200
200
200
200
300
300
300
300
300
Question:
Given the following:
function prototype: void my_func(int array[][3]);
variable declaration: int X[2][3];
Which function call can you use to pass a 2dimensional array to a function?
1. my_func(X);
2. my_func(&X[0][0]);
3. my_func(X[0]);
Answer
All of them
Question
What is printed:
int a[3][3]={0}, i,j;
for(i=0;i<3;i++)
for(j=i;j<3;j++)
a[i][j]=i*j;
for(i=0;i<3;i++)
printf(“%d\t”,a[i][1]);
Answer
0
1
0
Question
What is printed:
int a[10]={0}, n=27212, abc;
while(n>0)
{
abc=n%10;
if(a[abc])
{
printf(“%d\t”,abc);
break;
}
a[abc]=1;
n/=10;
}
Answer
2
Question
Given the following:
#define DOUBLE(x) (2*x)
What is the output for
printf(“%d”,DOUBLE(1+2));
Answer
4
Question
Write the following equation as a C statement
using functions from the math.h library.
y=(en ln(b))2
Answer
y=pow(exp(n*log(b)),2);
Question
Given the following program:
main()
{
int n = 10;
printf(“%d”,funct1(n));
}
int funct1(int n)
{
if(n>0) return(n + funct1(n-1));
}
What is the o/p ?
Answer
55
Question
Given the following program:
#include <stdio.h>
#define ROWS 3
#define COLUMNS 4
int z[ROWS][COLUMNS] = {1,2,3,4,5,6,7,8,9,10,11,12};
int main()
{
int a, b, c;
for(a=0;a<ROWS,++a) {
c = 999;
for(b=0;b<COLUMNS;++b)
if(z[a][b] < c) c = z[a][b];
printf(“%d ”,c);
}
What is the o/p?
Answer
159
(smallest value within each row)
Question
What is the output of the following code fragment:
int i;
char x[80] = “gorilla”;
char y[80] = “giraffe”;
char z[3][80];
strcpy(z[0],y);
strcpy(z[1],strcat(x,y));
strcpy(z[2],x);
for(i=0;i<3;i++)
printf(“%s\n”,z[i]);
Answer
giraffe
gorillagiraffe
gorillagiraffe
Question
What is the final value of string s1?
strcpy(s1,"computer");
strcpy(s2,"science");
if(strcmp(s1,s2) < 0)
strcat(s1,s2);
else
strcat(s2,s1);
s1[strlen(s1)-6] = '\0';
Answer
computers
Question
If ‘i’ is a variable and ‘p’ points to ‘i’, which of the
following expression are aliases for ‘i’ ?
a)
b)
c)
d)
*p
&p
*&p
&*p
e)
f)
g)
h)
*i
&i
*&i
&*i
Answer
a) g)
Question
Consider following declaration:
float table[2][3] = {
{1.1, 1.2, 1.3},
{2.1, 2.2, 2.3}
};
What is the value of ?
*(*(table+1));
Answer
2.1
Question
Given:
int x[]={-1,-2,-3,-4}, *px, **ppx;
px=x; ppx=&px;
Which command will display -3.
A: printf(“%d”,**ppx+2);
B: printf(“%d”,*(*ppx+2));
C: printf(“%d”,*ppx+2);
D: printf(“%d”,*(ppx+2));
Answer
B
Question
Given the following:
int i=0,n=465;
do
{
n/=10;
i++;
}
while(n>0);
printf(“i=%d\n”,i);
What is printed?
Answer
3
Question
What is printed:
int i=10;
while(i-- +2);
printf(“%d”,i);
Answer
-3
Question
What is displayed by the following code:
#include <stdio.h>
main()
{
int i,j,x=0;
for (i=0; i<5; ++i) {
for(j=0;j<i;++j)
x += (i+j-1);
printf(“%d”, x);
break;
}
printf(“\nx = %d”,x);
}
Answer
0
x=0
Arrays
Functions
&
Macros
Strings
Pointers
Loops
100
100
100
100
100
200
200
200
200
200
300
300
300
300
300