st08-array-sol

st08-array-sol - CSC 1111 Introduction to Computing using...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CSC 1111 Introduction to Computing using C++ Arrays (Self-test questions)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Array Initialization int foo[10] = { 10, 9, 8, 7 }; int bar[] = { 1, 2, 3, 4 }; cout << foo [ 0 ] << endl; cout << foo [ 9 ] << endl; cout << bar [ 1 ] << endl; cout << foo [ bar [ 0 ] ] << endl; What's the size of foo[] and bar[] respectively? foo[] has 10 elements bar[] has 4 elements What's is the output? 10 0 2 9
Background image of page 2
3 Arrays as parameters string foo[1000]; bar(foo, 1000); Which of these definition of function bar() is syntactically correctly? A. void bar(string x[], int n) { … } B. void bar(string x[100], int n) { … } C. void bar(string x[1000], int m) { … } D. int bar(string x[], int foo) { … } Answer: A, B, C, D B, C: Array size (for 1-D array) in parameter is ignored by compiler. D: Return type and parameter list are independent of each other. bar() can return an integer but we do not always need to use the returned value.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Arrays as parameters string foo[1000][20]; bar(foo, 1000); Which of these definition of function bar() is syntactically correctly? A. void bar(string x[][], int n) { … } B. void bar(string x[100][20], int n) { … } C.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/28/2010 for the course CSC CSC1110 taught by Professor Cjyuan during the Fall '06 term at CUHK.

Page1 / 15

st08-array-sol - CSC 1111 Introduction to Computing using...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online