Variable Declarations

Practice Questions

Computer Science › Variable Declarations

Questions
9
1
  • Declare a string set to the the word cat.
  • Declare a list of strings with the words hello, mama, and meow in it.
  • Declare a hashmap of <string, string> <key, value> pairs with the word world having a value of earth.
2

#include

using namespace std;

int main()
{
string str("ComputerScience");
string mystr;
str = str + "SampleQuestionCS";
mystr = str.substr(7,8);

return 0;
}

What is the value of mystr after this code is run?

3

int x=2;

double y=2.1;

float z=3.0;

int c=(x*y) + z;

What is the value of c

4

Which of these produce a typecasting error?

  1. float f = double d;

  2. double d = int i;

  3. int i = byte b;

  4. long l = short s;

5

What are the 3 different manners (in terms of accessibilitiy) in which you can declare a variable and what are the differences between the 3?

6

// ^ is Exclusive-Or (XOR) operator

x = x ^ y

y = x ^ y

x = x ^ y

What is the effect of the above snippet of code?

7

Which of the following code snippets declares an array of integers using an array literal?

8

What is the difference between double and int?

9

Which of the following declares a String array of size i? (Presume Java syntax.)

Return to subject