Câu hỏi trắc nghiệm ngôn ngữ lập trình C (tiếp theo)
What is a proper method of opening a file for writing as binary file?
Choice 1
FILE *f = fwrite( "test.bin", "b" );
Choice 2
FILE *f = fopenb( "test.bin", "w" );
Choice 3
FILE *f = fopen( "test.bin", "wb" );
Choice 4
FILE *f = fwriteb( "test.bin" );
Choice 5
FILE *f = fopen( "test.bin", "bw" );
Q32:Which one of the following functions is the correct choice for moving blocks of binary data that are of arbitrary size and position in memory?
Choice 1
memcpy()
Choice 2
memset()
Choice 3
strncpy()
Choice 4
strcpy()
Choice 5
memmove()
Q33:
int x = 2 * 3 + 4 * 5;
What value will x contain in the sample code above?
Choice 1
22
Choice 2
26[Ans]
Choice 3
46
Choice 4
50
Choice 5
70
Q34:
Code:
void * array_dup (a, number, size)
const void * a;
size_t number;
size_t size;
{
void * clone;
size_t bytes;
assert(a != NULL);
bytes = number * size;
clone = alloca(bytes);
if (!clone)
return clone;
memcpy(clone, a, bytes);
return clone;
}
The function array_dup(), defined above, contains an error. Which one of the following correctly analyzes it?
Choice 1
If the arguments to memcpy() refer to overlapping regions, the destination buffer will be subject to memory corruption.
Choice 2
array_dup() declares its first parameter to be a pointer, when the actual argument will be an array.
Choice 3
The memory obtained from alloca() is not valid in the context of the caller. Moreover, alloca() is nonstandard.
Choice 4
size_t is not a Standard C defined type, and may not be known to the compiler.
Choice 5
The definition of array_dup() is unusual. Functions cannot be defined using this syntax.
Q35:
int var1;
If a variable has been declared with file scope, as above, can it safely be accessed globally from another file?
Choice 1
Yes; it can be referenced through the register specifier.
Choice 2
No; it would have to have been initially declared as a static variable.
Choice 3
No; it would need to have been initially declared using the global keyword.
Choice 4
Yes; it can be referenced through the publish specifier.
Choice 5
Yes; it can be referenced through the extern specifier.
Q36:
time_t t;
Which one of the following statements will properly initialize the variable t with the current time from the sample above?
Choice 1
t = clock();
Choice 2
time( &t );
Choice 3
t = ctime();
Choice 4
t = localtime();
Choice 5
None of the above
Q37:
Which one of the following provides conceptual support for function calls?
Choice 1
The system stack
Choice 2
The data segment
Choice 3
The processor's registers
Choice 4
The text segment
Choice 5
The heap
Q38:
C is which kind of language?
Choice 1
Machine
Choice 2
Procedural
Choice 3
Assembly
Choice 4
Object-oriented
Choice 5
Strictly-typed
Q39:
Code:
int i,j;
int ctr = 0;
int myArray[2][3];
for (i=0; i<3; i++)
for (j=0; j<2; j++)
{
myArray[j][i] = ctr;
++ctr;
}
What is the value of myArray[1][2]; in the sample code above?
Choice 1
1
Choice 2
2
Choice 3
3
Choice 4
4
Choice 5
5
Q40:
Code:
int x = 0;
for (x=1; x<4; x++);
printf("x=%d\n", x);
What will be printed when the sample code above is executed?
Choice 1
x=0
Choice 2
x=1
Choice 3
x=3
Choice 4
x=4
Choice 5
x=5
NGUYỄN THỊ BẢO TRANG
» Tin mới nhất:
» Các tin khác: