FINAL EXAM REVIEW!!

34
FINAL EXAM REVIEW!! Lets play C-eopardy!!! (Answer in the form of answers!!) Feel free to hum along!

description

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: - PowerPoint PPT Presentation

Transcript of FINAL EXAM REVIEW!!

Page 1: FINAL EXAM REVIEW!!

FINAL EXAM REVIEW!!

Lets play C-eopardy!!!

(Answer in the form of answers!!)

Feel free to hum along!

Page 2: FINAL EXAM REVIEW!!

200

300

100

200

300

100

200

300

100

200

300

100

200

300

100

ArraysFunctions

& Macros

Strings Pointers Loops

Page 3: FINAL EXAM REVIEW!!

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 2-dimensional array to a function?

1. my_func(X);

2. my_func(&X[0][0]);

3. my_func(X[0]);

Page 4: FINAL EXAM REVIEW!!

Answer

All of them

Page 5: FINAL EXAM REVIEW!!

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]);

Page 6: FINAL EXAM REVIEW!!

Answer

0 1 0

Page 7: FINAL EXAM REVIEW!!

QuestionWhat 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;

}

Page 8: FINAL EXAM REVIEW!!

Answer

2

Page 9: FINAL EXAM REVIEW!!

Question

Given the following:

#define DOUBLE(x) (2*x)

What is the output for

printf(“%d”,DOUBLE(1+2));

Page 10: FINAL EXAM REVIEW!!

Answer

4

Page 11: FINAL EXAM REVIEW!!

Question

Write the following equation as a C statement using functions from the math.h library.

y=(en ln(b))2

Page 12: FINAL EXAM REVIEW!!

Answer

y=pow(exp(n*log(b)),2);

Page 13: FINAL EXAM REVIEW!!

QuestionGiven 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 ?

Page 14: FINAL EXAM REVIEW!!

Answer

55

Page 15: FINAL EXAM REVIEW!!

QuestionGiven the following program:#include <stdio.h>#define ROWS 3#define COLUMNS 4int 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?

Page 16: FINAL EXAM REVIEW!!

Answer

1 5 9

(smallest value within each row)

Page 17: FINAL EXAM REVIEW!!

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]);

Page 18: FINAL EXAM REVIEW!!

Answer

giraffe

gorillagiraffe

gorillagiraffe

Page 19: FINAL EXAM REVIEW!!

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';

Page 20: FINAL EXAM REVIEW!!

Answer

computers

Page 21: FINAL EXAM REVIEW!!

Question

If ‘i’ is a variable and ‘p’ points to ‘i’, which of the following expression are aliases for ‘i’ ?

a) *p e) *i

b) &p f) &i

c) *&p g) *&i

d) &*p h) &*i

Page 22: FINAL EXAM REVIEW!!

Answer

a) g)

Page 23: FINAL EXAM REVIEW!!

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));

Page 24: FINAL EXAM REVIEW!!

Answer

2.1

Page 25: FINAL EXAM REVIEW!!

QuestionGiven:

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));

Page 26: FINAL EXAM REVIEW!!

Answer

B

Page 27: FINAL EXAM REVIEW!!

Question

Given the following:int i=0,n=465;do{

n/=10;i++;

}while(n>0);printf(“i=%d\n”,i);

What is printed?

Page 28: FINAL EXAM REVIEW!!

Answer

3

Page 29: FINAL EXAM REVIEW!!

Question

What is printed:

int i=10;

while(i-- +2);

printf(“%d”,i);

Page 30: FINAL EXAM REVIEW!!

Answer

-3

Page 31: FINAL EXAM REVIEW!!

QuestionWhat 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);

}

Page 32: FINAL EXAM REVIEW!!

Answer

0x = 0

Page 33: FINAL EXAM REVIEW!!
Page 34: FINAL EXAM REVIEW!!

200

300

100

200

300

100

200

300

100

200

300

100

200

300

100

ArraysFunctions

& Macros

Strings Pointers Loops