Deck 11: Arrays, Addresses, and Pointers

ملء الشاشة (f)
exit full mode
سؤال
Pointers, both as variables and function parameters, are used to store addresses.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
Pointers are closely associated with array names.
سؤال
Offsets may be included in expressions using pointers.
سؤال
If gPtr is a pointer that points to the first element of an integer array (and each integer requires four bytes of storage), *(gPtr + 4 * 4) references the variable that is four integers beyond the variable pointed to by gPtr.
سؤال
When working with pointers and offsets, the correspondence between the number of bytes and number of variables is not handled by the compiler, so you must perform the conversions yourself.
سؤال
Any subscript used by a programmer is automatically converted to an equivalent pointer expression by the compiler.
سؤال
The parentheses in the pointer expression *(gPtr + 3) are not necessary to access the desired array element correctly.
سؤال
The expression *(gPtr + 3) changes the address stored in gPtr.
سؤال
A pointer constant is equivalent to a symbolic constant, in that the address stored in the pointer constant cannot be changed once it is set.
سؤال
Access to an array using a subscript can always be replaced by an equivalent access using the array name as a pointer.
سؤال
In every respect, an array name and a pointer can be used interchangeably.
سؤال
The address stored in the array name cannot be changed by an assignment statement.
سؤال
Attempting to assign the address of an array name is invalid.
سؤال
A pointer access can sometimes (but not always) be replaced using subscript notation.
سؤال
One advantage of using subscripts for array processing is that they are more efficient than using pointers directly.
سؤال
By adding numbers to and subtracting numbers from pointers, we can obtain different addresses.
سؤال
The addresses in pointers can be compared using any of the relational operators (==, !=, <, >, etc.) that are valid for comparing other variables.
سؤال
When adding or subtracting numbers to pointers, the computer automatically adjusts the number to ensure that the result still "points to" a value of the original data type.
سؤال
Addresses cannot be incremented or decremented using prefix or postfix increment and decrement operators.
سؤال
When initializing pointers you must be careful to set an address in the pointer.
سؤال
When an array is passed to a function, the array address is the only item actually passed.
سؤال
If nums is a two-dimensional integer array, *(*(nums + 2) + 1) refers to element nums[1][2].
سؤال
The following code is valid in C:
char *message;
strcpy(message,"abcdef");
سؤال
Instead of initially creating a string as an array it is possible to create a string using a pointer.
سؤال
The declaration char *seasons[4]; creates an array of four elements, where each element is a pointer to a character.
سؤال
&grade[3] is equivalent to ____; assume that grade is an array of integers, and each integer requires 4 bytes of storage..

A)&grade[0] + 3
B)&grade[0] + 4
C)&grade[0] + (3 * 4)
D)&grade[0] + (3 / 4)
سؤال
The address operator in C is ____.

A)&
B)*
C)->
D))
سؤال
The indirection operator in C is ____.

A)&
B)*
C)->
D))
سؤال
If we store the address of grade[0] in a pointer named gPtr (using the assignment statement gPtr = &grade[0];), then, the expression ____ references grade[0].

A)gPtr(0)
B)gPtr
C)&gPtr
D)gPtr
سؤال
The ____ in the expression *(gPtr + 1) is an offset.

A)*
B)gPtr
C)+
D)1
سؤال
If gPtr is a pointer that points to the first element of an integer array (and each integer requires four bytes of storage), ____ references the variable that is three integers beyond the variable pointed to by gPtr.

A)*gPtr + 3
B)*(gPtr + 3)
C)*(gPtr + 3 * 4)
D)*(gPtr + 3 / 4)
سؤال
When working with pointers, the ____ tells the number of variables that are to be skipped over.

A)indirection operator
B)address operator
C)offset
D)address
سؤال
The expression ____ adds 3 to "the variable pointed to by gPtr."

A)*(gPtr + 3)
B)*gPtr + 3
C)gPtr + 3
D)&gPtr + 3
سؤال
When an array is created, the compiler automatically creates an internal ____ for it and stores the base address of the array in it.

A)pointer constant
B)pointer
C)symbolic constant
D)location
سؤال
Assuming grade is an array of ten integers, the statement ____ is invalid.

A)grade = &grade[2];
B)*grade = *(grade + 2);
C)*grade = *grade + 2;
D)*grade = *(&grade[2]) + 2;
سؤال
If numPtr is declared as a pointer variable, the expression ____ can also be written as numPtr[i].

A)*numPtr + i
B)(numPtr + i)
C)*numPtr
D)*(numPtr + i)
سؤال
Pointers ____ be initialized when they are declared.

A)must
B)must not
C)can
D)cannot
سؤال
In performing ____ on pointers, we must be careful to produce addresses that point to something meaningful.

A)comparisons
B)arithmetic
C)subscript operations
D)duplication
سؤال
Consider the declarations
Int nums[100];
Int *nPtr;
The statement ____ produces the same result as nPtr = nums;.

A)nPtr = &nums[0];
B)nPtr = nums[0];
C)nPtr = *nums[0];
D)nPtr = &nums;
سؤال
Adding ____ to a pointer causes the pointer to point to the next element of the original data type being pointed to.

A)1
B)1 * sizeof(data type being pointed to)
C)2
D)2 * sizeof(data type being pointed to)
سؤال
Of the following expressions, ____ is the most commonly used. This is because such an expression allows each element in an array to be accessed as the address is "marched along" from the starting address of the array to the address of the last array element.

A)*ptNum--
B)*--ptNum
C)*ptNum++
D)*++ptNum
سؤال
int *ptNum = &miles; is ____.

A)always valid
B)never valid
C)only valid if miles is declared as an integer variable before ptNum is declared
D)only valid if miles is declared as an array of integers before ptNum is declared
سؤال
Consider the following declarations of a function that receives an array of integers and finds the element with the maximum value:
(i) findMax(int *vals, int numEls)
(ii) findMax(int vals[], int numEls)
The address in vals may be modified ____.

A)only if the function is declared as in (i)
B)only if the function is declared as in (ii)
C)if either (i) or (ii) is used
D)in neither case because an array variable cannot be modified (it is a pointer constant)
سؤال
If nums is a two-dimensional integer array, ____ refers to element nums[0][0].

A)*nums
B)*(*nums)
C)*(&nums)
D)&(*nums)
سؤال
If nums is a two-dimensional integer array, ____ refers to element nums[1][0].

A)*nums[1]
B)*nums[0]
C)*nums + 1
D)*nums++
سؤال
A suitable equivalent to the function header calc(int pt[2][3]) is ____.

A)calc(int *(*pt))
B)calc(int (*pt)[])
C)calc(int (*pt)[2])
D)calc(int (*pt)[3])
سؤال
The header line ____ declares calc to be a pointer to a function that returns an integer.

A)int *calc()
B)int (*calc)()
C)int &calc()
D)int calc(*)
سؤال
You can replace lines 5 and 6 in the following function with ____.
1 /* copy string2 to string1 */
2 void strcopy(char string1[], char string2[])
3 {
4 int i = 0;
5 while (string1[i] = string2[i])
6 i++;
7 }

A) while (*string1 = *string2) ;
B) while (*string1 = string2) ;
C) while (*string1++ = *string2++) ;
D) while (*++string1 = *++string2) ;
سؤال
After creating two variables as follows:
Char message1[81] = "this is a string";
Char *message2 = "this is a string";
The statement ____ is not valid in C.

A) message1 = "A new message";
C) message2 = message1;
B) message2 = "A new message";
D) message2[0] = 'T';
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/49
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 11: Arrays, Addresses, and Pointers
1
Pointers, both as variables and function parameters, are used to store addresses.
True
2
Pointers are closely associated with array names.
True
3
Offsets may be included in expressions using pointers.
True
4
If gPtr is a pointer that points to the first element of an integer array (and each integer requires four bytes of storage), *(gPtr + 4 * 4) references the variable that is four integers beyond the variable pointed to by gPtr.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
5
When working with pointers and offsets, the correspondence between the number of bytes and number of variables is not handled by the compiler, so you must perform the conversions yourself.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
6
Any subscript used by a programmer is automatically converted to an equivalent pointer expression by the compiler.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
7
The parentheses in the pointer expression *(gPtr + 3) are not necessary to access the desired array element correctly.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
8
The expression *(gPtr + 3) changes the address stored in gPtr.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
9
A pointer constant is equivalent to a symbolic constant, in that the address stored in the pointer constant cannot be changed once it is set.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
10
Access to an array using a subscript can always be replaced by an equivalent access using the array name as a pointer.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
11
In every respect, an array name and a pointer can be used interchangeably.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
12
The address stored in the array name cannot be changed by an assignment statement.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
13
Attempting to assign the address of an array name is invalid.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
14
A pointer access can sometimes (but not always) be replaced using subscript notation.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
15
One advantage of using subscripts for array processing is that they are more efficient than using pointers directly.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
16
By adding numbers to and subtracting numbers from pointers, we can obtain different addresses.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
17
The addresses in pointers can be compared using any of the relational operators (==, !=, <, >, etc.) that are valid for comparing other variables.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
18
When adding or subtracting numbers to pointers, the computer automatically adjusts the number to ensure that the result still "points to" a value of the original data type.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
19
Addresses cannot be incremented or decremented using prefix or postfix increment and decrement operators.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
20
When initializing pointers you must be careful to set an address in the pointer.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
21
When an array is passed to a function, the array address is the only item actually passed.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
22
If nums is a two-dimensional integer array, *(*(nums + 2) + 1) refers to element nums[1][2].
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
23
The following code is valid in C:
char *message;
strcpy(message,"abcdef");
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
24
Instead of initially creating a string as an array it is possible to create a string using a pointer.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
25
The declaration char *seasons[4]; creates an array of four elements, where each element is a pointer to a character.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
26
&grade[3] is equivalent to ____; assume that grade is an array of integers, and each integer requires 4 bytes of storage..

A)&grade[0] + 3
B)&grade[0] + 4
C)&grade[0] + (3 * 4)
D)&grade[0] + (3 / 4)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
27
The address operator in C is ____.

A)&
B)*
C)->
D))
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
28
The indirection operator in C is ____.

A)&
B)*
C)->
D))
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
29
If we store the address of grade[0] in a pointer named gPtr (using the assignment statement gPtr = &grade[0];), then, the expression ____ references grade[0].

A)gPtr(0)
B)gPtr
C)&gPtr
D)gPtr
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
30
The ____ in the expression *(gPtr + 1) is an offset.

A)*
B)gPtr
C)+
D)1
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
31
If gPtr is a pointer that points to the first element of an integer array (and each integer requires four bytes of storage), ____ references the variable that is three integers beyond the variable pointed to by gPtr.

A)*gPtr + 3
B)*(gPtr + 3)
C)*(gPtr + 3 * 4)
D)*(gPtr + 3 / 4)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
32
When working with pointers, the ____ tells the number of variables that are to be skipped over.

A)indirection operator
B)address operator
C)offset
D)address
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
33
The expression ____ adds 3 to "the variable pointed to by gPtr."

A)*(gPtr + 3)
B)*gPtr + 3
C)gPtr + 3
D)&gPtr + 3
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
34
When an array is created, the compiler automatically creates an internal ____ for it and stores the base address of the array in it.

A)pointer constant
B)pointer
C)symbolic constant
D)location
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
35
Assuming grade is an array of ten integers, the statement ____ is invalid.

A)grade = &grade[2];
B)*grade = *(grade + 2);
C)*grade = *grade + 2;
D)*grade = *(&grade[2]) + 2;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
36
If numPtr is declared as a pointer variable, the expression ____ can also be written as numPtr[i].

A)*numPtr + i
B)(numPtr + i)
C)*numPtr
D)*(numPtr + i)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
37
Pointers ____ be initialized when they are declared.

A)must
B)must not
C)can
D)cannot
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
38
In performing ____ on pointers, we must be careful to produce addresses that point to something meaningful.

A)comparisons
B)arithmetic
C)subscript operations
D)duplication
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
39
Consider the declarations
Int nums[100];
Int *nPtr;
The statement ____ produces the same result as nPtr = nums;.

A)nPtr = &nums[0];
B)nPtr = nums[0];
C)nPtr = *nums[0];
D)nPtr = &nums;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
40
Adding ____ to a pointer causes the pointer to point to the next element of the original data type being pointed to.

A)1
B)1 * sizeof(data type being pointed to)
C)2
D)2 * sizeof(data type being pointed to)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
41
Of the following expressions, ____ is the most commonly used. This is because such an expression allows each element in an array to be accessed as the address is "marched along" from the starting address of the array to the address of the last array element.

A)*ptNum--
B)*--ptNum
C)*ptNum++
D)*++ptNum
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
42
int *ptNum = &miles; is ____.

A)always valid
B)never valid
C)only valid if miles is declared as an integer variable before ptNum is declared
D)only valid if miles is declared as an array of integers before ptNum is declared
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
43
Consider the following declarations of a function that receives an array of integers and finds the element with the maximum value:
(i) findMax(int *vals, int numEls)
(ii) findMax(int vals[], int numEls)
The address in vals may be modified ____.

A)only if the function is declared as in (i)
B)only if the function is declared as in (ii)
C)if either (i) or (ii) is used
D)in neither case because an array variable cannot be modified (it is a pointer constant)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
44
If nums is a two-dimensional integer array, ____ refers to element nums[0][0].

A)*nums
B)*(*nums)
C)*(&nums)
D)&(*nums)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
45
If nums is a two-dimensional integer array, ____ refers to element nums[1][0].

A)*nums[1]
B)*nums[0]
C)*nums + 1
D)*nums++
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
46
A suitable equivalent to the function header calc(int pt[2][3]) is ____.

A)calc(int *(*pt))
B)calc(int (*pt)[])
C)calc(int (*pt)[2])
D)calc(int (*pt)[3])
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
47
The header line ____ declares calc to be a pointer to a function that returns an integer.

A)int *calc()
B)int (*calc)()
C)int &calc()
D)int calc(*)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
48
You can replace lines 5 and 6 in the following function with ____.
1 /* copy string2 to string1 */
2 void strcopy(char string1[], char string2[])
3 {
4 int i = 0;
5 while (string1[i] = string2[i])
6 i++;
7 }

A) while (*string1 = *string2) ;
B) while (*string1 = string2) ;
C) while (*string1++ = *string2++) ;
D) while (*++string1 = *++string2) ;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
49
After creating two variables as follows:
Char message1[81] = "this is a string";
Char *message2 = "this is a string";
The statement ____ is not valid in C.

A) message1 = "A new message";
C) message2 = message1;
B) message2 = "A new message";
D) message2[0] = 'T';
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.