Câu hỏi trắc nghiệm ngôn ngữ lập trình C (tiếp theo)
What number is equivalent to -4e3?
Choice 1
-4000 [Ans]
Choice 2
-400
Choice 3
-40
Choice 4
.004
Choice 5
.0004
Q102:
Code:
void freeList( struct node *n )
{
while( n )
{
????
}
}
Which one of the following can replace the ???? for the function above to release the memory allocated to a linked list?
Choice 1
n = n->next;
free( n );
Choice 2
struct node m = n;
n = n->next;
free( m );
Choice 3
struct node m = n;
free( n );
n = m->next;
Choice 4
free( n );
n = n->next;
Choice 5
struct node m = n;
free( m );
n = n->next;
Q103:
How does variable definition differ from variable declaration?
Choice 1
Definition allocates storage for a variable, but declaration only informs the compiler as to the variable's type.
Choice 2
Declaration allocates storage for a variable, but definition only informs the compiler as to the variable's type.
Choice 3
Variables may be defined many times, but may be declared only once.[Ans]
Choice 4
Variable definition must precede variable declaration.
Choice 5
There is no difference in C between variable declaration and variable definition.
Q104:
Code:
int x[] = {1, 2, 3, 4, 5};
int u;
int *ptr = x;
????
for( u = 0; u < 5; u++ )
{
printf("%d-", x[u]);
}
printf( "\n" );
Which one of the following statements could replace the ???? in the code above to cause the string 1-2-3-10-5- to be printed when the code is executed?
Choice 1
*ptr + 3 = 10;
Choice 2
*ptr[ 3 ] = 10;
Choice 3
*(ptr + 3) = 10;[Ans]
Choice 4
(*ptr)[ 3 ] = 10;
Choice 5
*(ptr[ 3 ]) = 10;
Q105:
Code:
/*sum_array() has been ported from FORTRAN. No * logical changes have been made*/
double sum_array(double d[],int n)
{
register int i;
double total=0;
assert(d!=NULL);
for(i=l;i<=n;i++)
total+=d[i];
return total;
}
The function sum_array(), defined above, contains an error. Which one of the following accurately describes it?
Choice 1
The range of the loop does not match the bounds of the array d.
Choice 2
The loop processes the incorrect number of elements.
Choice 3
total is initialized with an integer literal. The two are not compatible in an assignment.
Choice 4
The code above fails to compile if there are no registers available for i.
Choice 5
The formal parameter d should be declared as double * d to allow dynamically allocated arrays as arguments.
Q106:
Code:
#include
void func()
{
int x = 0;
static int y = 0;
x++; y++;
printf( "%d -- %d\n", x, y );
}
int main()
{
func();
func();
return 0;
}
What will the code above print when it is executed?
Choice 1
1 -- 1
1 -- 1
Choice 2
1 -- 1
2 -- 1
Choice 3
1 -- 1
2 -- 2
Choice 4
1 -- 0
1 -- 0
Choice 5
1 -- 1
1 -- 2 [Ans]
Q107:
$$No other seems that sound$$
Code:
int fibonacci (int n)
{
switch (n)
{
default:
return (fibonacci(n - 1) + fibonacci(n - 2));
case 1:
case 2:
}
return 1;
}
The function above has a flaw that may result in a serious error during some invocations. Which one of the following describes the deficiency illustrated above?
Choice 1
For some values of n, the environment will almost certainly exhaust its stack space before the calculation completes.
[Ans]
Choice 2
An error in the algorithm causes unbounded recursion for all values of n.
Choice 3
A break statement should be inserted after each case. Fall-through is not desirable here.
Choice 4
The fibonacci() function includes calls to itself. This is not directly supported by Standard C due to its unreliability.
Choice 5
Since the default case is given first, it will be executed before any case matching n.
Q108:
When applied to a variable, what does the unary "&" operator yield?
Choice 1
The variable's address [Ans]
Choice 2
The variable's right value
Choice 3
The variable's binary form
Choice 4
The variable's value
Choice 5
The variable's format
Q109:
short int x; /* assume x is 16 bits in size */
What is the maximum number that can be printed using printf("%d\n", x), assuming that x is initialized as shown above?
Choice 1
127
Choice 2
128
Choice 3
255
Choice 4
32,767[Ans]
Choice 5
65,536
Q110:
int x = 011 | 0x10;
What value will x contain in the sample code above?
Choice 1
3
Choice 2
13
Choice 3
19
Choice 4
25
Choice 5
27
NGUYỄN THỊ BẢO TRANG
» Tin mới nhất:
» Các tin khác: