Cayuga Community College

Programming in C
Pop Quiz

Increment and Decrement operators - Questions

For questions 1 through 2, assume the following code:

int a;
int b;

a=1;

b=a++;

  1. What value does the variable b have after ALL of the code above executes?
    1. 1
    2. 2
    3. 3
    4. unknown/undefined

  2. What value does the variable a have after ALL of the code above executes?
    1. 1
    2. 2
    3. 3
    4. unknown/undefined

For questions 3 through 5, assume the following code:

int x;
int y;
int z;

x=3;
y=4;

z = ++x * y++;

  1. What value does the variable z have after ALL of the code above executes?
    1. 9
    2. 12
    3. 16
    4. unknown/undefined

  2. What value does the variable x have after ALL of the code above executes?
    1. 2
    2. 3
    3. 4
    4. unknown/undefined

  3. What value does the variable y have after ALL of the code above executes?
    1. 4
    2. 5
    3. 6
    4. unknown/undefined

See the answers.

Return to the CS 222 Home Page.
Return to David's Home Page.
Return to Cayuga's Home Page.

Valid HTML 3.2!