Źródło: Arkusze CKE
Przedstawiony fragment dotyczy funkcji resize w języku C++. Ta funkcja obniży długość elementu string, gdy wartość parametru
Resize string
Resizes the string to a length of n characters.
If n is smaller than the current string length, the current value is shortened to its first n character, removing the characters beyond the nth.
If n is greater than the current string length, the current content is extended by inserting at the end as many characters as needed to reach a size of n. If c is specified, the new elements are initialized as copies of c; otherwise, they are value-initialized characters (null characters).
Parameters
n
New string length, expressed in number of characters.
size_t is an unsigned integral type (the same as member type string::size_type).
c
Character used to fill the new character space added to the string (in case the string is expanded).
Źródło: http://www.cplusplus.com/reference/string/string/resize/
Warianty odpowiedzi
-
A
n jest większa od aktualnej długości łańcucha
-
B
c jest mniejsza od aktualnej długości łańcucha
-
C
n jest mniejsza od aktualnej długości łańcucha
-
D
c jest większa od aktualnej długości łańcucha
Wyjaśnienie
Dokumentacja wyraźnie wyjaśnia zachowanie metody resize w zależności od wartości przekazanego parametru n.
Gdy podany parametr n jest mniejszy od bieżącej długości napisu, funkcja po prostu obcina ciąg znaków do pierwszych n pozycji, a całą resztę definitywnie usuwa.
W sytuacji odwrotnej, gdy n byłoby większe, napis zostałby wydłużony o dodatkowe znaki. Dlatego skracanie zachodzi wyłącznie wtedy, gdy n jest mniejsze od aktualnego rozmiaru.