50.2k views
5 votes
Shift the variables in the following around: char c1, c2, c3; to: c1 should contain the value of c2, and c2 should contain the value of c3, and c3 should contain the value of c1.

User Exasm
by
7.0k points

1 Answer

2 votes

Final answer:

To shift the variables c1, c2, and c3 as described, use a temporary variable to hold one of the values, swap the required values, and assign the stored value from the temporary variable to the last variable.

Step-by-step explanation:

To shift the variables around so that c1 should contain the value of c2, and c2 should contain the value of c3, and c3 should contain the value of c1, we need to use a temporary variable to hold one of the values during the swapping process. Here's how you can do it:

  1. Create a temporary variable to hold the value of one of the characters, for example, c1.
  2. Assign the value of c2 to c1.
  3. Assign the value of c3 to c2.
  4. Assign the value stored in the temporary variable (originally c1) to c3.

The code in C would look something like this:

char temp = c1;
c1 = c2;
c2 = c3;
c3 = temp;
User Definity
by
8.1k points