Câu hỏi trắc nghiệm ngôn ngữ lập trình C (tiếp theo)
Which one of the following is a true statement about pointers?
Choice 1
Pointer arithmetic is permitted on pointers of any type.
Choice 2
A pointer of type void * can be used to directly examine or modify an object of any type.
Choice 3
Standard C mandates a minimum of four levels of indirection accessible through a pointer.
Choice 4
A C program knows the types of its pointers and indirectly referenced data items at runtime.
Choice 5
Pointers may be used to simulate call-by-reference.
Q52:
Which one of the following functions returns the string representation from a pointer to a time_t value?
Choice 1
localtime
Choice 2
gmtime
Choice 3
strtime
Choice 4
asctime
Choice 5
ctime
Q53:
Code:
short testarray[4][3] = { {1}, {2, 3}, {4, 5, 6} };
printf( "%d\n", sizeof( testarray ) );
Assuming a short is two bytes long, what will be printed by the above code?
Choice 1
It will not compile because not enough initializers are given.
Choice 2
6
Choice 3
7
Choice 4
12
Choice 5
24
Q54:
char buf [] = "Hello world!";
char * buf = "Hello world!";
In terms of code generation, how do the two definitions of buf, both presented above, differ?
Choice 1
The first definition certainly allows the contents of buf to be safely modified at runtime; the second definition does not.
Choice 2
The first definition is not suitable for usage as an argument to a function call; the second definition is.
Choice 3
The first definition is not legal because it does not indicate the size of the array to be allocated; the second definition is legal.
Choice 4
They do not differ -- they are functionally equivalent. [Ans]
Choice 5
The first definition does not allocate enough space for a terminating NUL-character, nor does it append one; the second definition does.
Q55:
In a C expression, how is a logical AND represented?
Choice 1
@@
Choice 2
||
Choice 3
.AND.
Choice 4
&&
Choice 5
.AND
Q56:
How do printf()'s format specifiers %e and %f differ in their treatment of floating-point numbers?
Choice 1
%e always displays an argument of type double in engineering notation; %f always displays an argument of type double in decimal notation. [Ans]
Choice 2
%e expects a corresponding argument of type double; %f expects a corresponding argument of type float.
Choice 3
%e displays a double in engineering notation if the number is very small or very large. Otherwise, it behaves like %f and displays the number in decimal notation.
Choice 4
%e displays an argument of type double with trailing zeros; %f never displays trailing zeros.
Choice 5
%e and %f both expect a corresponding argument of type double and format it identically. %e is left over from K&R C; Standard C prefers %f for new code.
Q57:
Which one of the following Standard C functions can be used to reset end-of-file and error conditions on an open stream?
Choice 1
clearerr()
Choice 2
fseek()
Choice 3
ferror()
Choice 4
feof()
Choice 5
setvbuf()
Q58:
Which one of the following will read a character from the keyboard and will store it in the variable c?
Choice 1
c = getc();
Choice 2
getc( &c );
Choice 3
c = getchar( stdin );
Choice 4
getchar( &c )
Choice 5
c = getchar();
Q59:
Code:
#include
int i;
void increment( int i )
{
i++;
}
int main()
{
for( i = 0; i < 10; increment( i ) )
{
}
printf("i=%d\n", i);
return 0;
}
What will happen when the program above is compiled and executed?
Choice 1
It will not compile.
Choice 2
It will print out: i=9.
Choice 3
It will print out: i=10.
Choice 4
It will print out: i=11.
Choice 5
It will loop indefinitely.
Q60:
Code:
char ptr1[] = "Hello World";
char *ptr2 = malloc( 5 );
ptr2 = ptr1;
What is wrong with the above code (assuming the call to malloc does not fail)?
Choice 1
There will be a memory overwrite.
Choice 2
There will be a memory leak.
Choice 3
There will be a segmentation fault.
Choice 4
Not enough space is allocated by the malloc.
Choice 5
It will not compile.
NGUYỄN THỊ BẢO TRANG
» Tin mới nhất:
» Các tin khác: