In: Computer Science
Question 3: What do the following vim commands do in command mode?
ZZ
:w!
i
dd
x
yy
p
Question 4: Review the following code. If you were to print out all the dereferenced values of the three pointer variables and the array, what is the output?
(note: if possible explain how the output changed.)
int array[] = { 30, 40, 50, 60, 70, 80 };
int *ptrA = array;
int *ptrB = ptrA + 4;
int *ptrC = ptrB--;
array[ 1 ] = 2;
*ptrB = *ptrC - 2;
*ptrC = 100;
array[ 3 ] = *ptrA++;
ptrC = ptrB + 2;
1)
ZZ
Write current file, if modified, and exit.
:W!
Write the current file and exit always.
i
Insert text before the cursor [count] times.
dd
Delete [count] lines
x
Delete [count] characters before the cursor.
yy
it copies the line for you to put into the file immediately. This command "yanks" the current line into the vi general buffer.
p
it paste the previously deleted text after the cursor.
2)
usage of 'int' here is not the correct method.
using 'int' ("%d") with pointers is incorrect and invokes undefined behavior.
Pointers should be printed with %p not %d because the number might be too big , so it became overflow.
if you print with "%d" then the values are:
array values are: -2112859744
-2112859740
-2112859736
-2112859732
-2112859728
-2112859724
ptr A -2112859740
ptr B -2112859732
ptr C -2112859724