cs31s11mid

cs31s11mid - CS31 Introduction to Computer Science I Spring...

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

View Full Document Right Arrow Icon
Midterm Practice Problems TA: Brian Choi ([email protected]) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 ENJOY! Problem 1 True False Variable names can begin with an alphabet or a digit. True False A string cannot be empty. True False A character cannot be empty. True False An array can have a size of 0. True False int m = 5.6; won’t compile because types do not match. True False int n = 11 / 5; will create n and initialize it with the value of 2. True False An array index begins with 0. True False for (int i = 0; i <= 49; i++) will run the loop 50 times (assuming i is not modified within the loop). True False If there is a function that does not require any parameters, you can omit parentheses when calling it. True False Constant variables can be modified only in the main() function. True False int x = ‘0’; sets x to an integer 0. True False int x = 0; sets x to an integer 0. True False int x = 0.0; sets x to an integer 0. True False int x = 0.5; sets x to an integer 0. True True You will ace the exam. Problem 2 What does the following code do, in a brief English sentence ? int mystery(int k) { int i = 0; if (k < 0) return -1; while (k > 0) { if (k % 3 == 0) i++; k--; } return i; } CS31: Introduction to Computer Science I Spring 2011 Copyright Brian Choi 2011. All Rights Reserved. Week 5, Page 1/5
Background image of page 1

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

View Full Document Right Arrow Icon
Problem 3 What happens if you compile and run the following code? For each case, choose one of the options and
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 5

cs31s11mid - CS31 Introduction to Computer Science I Spring...

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

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