Câu hỏi trắc nghiệm ngôn ngữ lập trình C (tiếp theo)
Code:
int x = 3;
if( x == 2 );
x = 0;
if( x == 3 )
x++;
else x += 2;
What value will x contain when the sample code above is executed?
Choice 1
1
Choice 2
2
Choice 3
3
Choice 4
4
Choice 5
5
Q42:
Code:
char *ptr;
char myString[] = "abcdefg";
ptr = myString;
ptr += 5;
What string does ptr point to in the sample code above?
Choice 1
fg
Choice 2
efg
Choice 3
defg
Choice 4
cdefg
Choice 5
None of the above
Q43:
Code:
double x = -3.5, y = 3.5;
printf( "%.0f : %.0f\n", ceil( x ), ceil( y ) );
printf( "%.0f : %.0f\n", floor( x ), floor( y ) );
What will the code above print when executed?
ceil =>rounds up 3.2=4 floor =>rounds down 3.2=3
Choice 1
-3 : 4
-4 : 3
Choice 2
-4 : 4
-3 : 3
Choice 3
-4 : 3
-4 : 3
Choice 4
-4 : 3
-3 : 4
Choice 5
-3 : 3
-4 : 4
Q44:
Which one of the following will declare a pointer to an integer at address 0x200 in memory?
Choice 1
int *x;
*x = 0x200
Choice 2
int *x = &0x200;
Choice 3
int *x = *0x200;
Choice 4
int *x = 0x200;
Choice 5
int *x( &0x200 );
Q45:
Code:
int x = 5;
int y = 2;
char op = '*';
switch (op)
{
default : x += 1;
case '+' : x += y; /*It will go to all the cases*/
case '-' : x -= y;
}
After the sample code above has been executed, what value will the variable x contain?
Choice 1
4
Choice 2
5
Choice 3
6
Choice 4
7
Choice 5
8
Q46:
Code:
x = 3, counter = 0;
while ((x-1))
{
++counter;
x--;
}
Referring to the sample code above, what value will the variable counter have when completed?
Choice 1
0
Choice 2
1
Choice 3
2
Choice 4
3
Choice 5
4
Q47:
char ** array [12][12][12];
Consider array, defined above. Which one of the following definitions and initializations of p is valid?
Choice 1
char ** (* p) [12][12] = array;
Choice 2
char ***** p = array;
Choice 3
char * (* p) [12][12][12] = array;
Choice 4
const char ** p [12][12][12] = array;
Choice 5
char (** p) [12][12] = array;
Q48:
void (*signal(int sig, void (*handler) (int))) (int);
Which one of the following definitions of sighandler_t allows the above declaration to be rewritten as follows:
sighandler_t signal (int sig, sighandler_t handler);
Choice 1
typedef void (*sighandler_t) (int)
Choice 2
typedef sighandler_t void (*) (int);
Choice 3
typedef void *sighandler_t (int);
Choice 4
#define sighandler_t(x) void (*x) (int)
Choice 5
#define sighandler_t void (*) (int)
Q49:
All of the following choices represent syntactically correct function definitions. Which one of the following represents a semantically legal function definition in Standard C?
Choice 1
Code:
int count_digits (const char * buf) {
assert(buf != NULL);
int cnt = 0, i;
for (i = 0; buf[i] != '\0'; i++)
if (isdigit(buf[i]))
cnt++;
return cnt;
}
Choice 2
Code:
int count_digits (const char * buf) {
int cnt = 0;
assert(buf != NULL);
for (int i = 0; buf[i] != '\0'; i++)
if (isdigit(buf[i]))
cnt++;
return cnt;
}
Choice 3
Code:
int count_digits (const char * buf) {
int cnt = 0, i;
assert(buf != NULL);
for (i = 0; buf[i] != '\0'; i++)
if (isdigit(buf[i]))
cnt++;
return cnt;
}
Choice 4
Code:
int count_digits (const char * buf) {
assert(buf != NULL);
for (i = 0; buf[i] != '\0'; i++)
if (isdigit(buf[i]))
cnt++;
return cnt;
}
Choice 5
Code:
int count_digits (const char * buf) {
assert(buf != NULL);
int cnt = 0;
for (int i = 0; buf[i] != '\0'; i++)
if (isdigit(buf[i]))
cnt++;
return cnt;
}
Q50:
struct customer *ptr = malloc( sizeof( struct customer ) );
Given the sample allocation for the pointer "ptr" found above, which one of the following statements is used to reallocate ptr to be an array of 10 elements?
Choice 1
ptr = realloc( ptr, 10 * sizeof( struct customer));
Choice 2
realloc( ptr, 9 * sizeof( struct customer ) );
Choice 3
ptr += malloc( 9 * sizeof( struct customer ) );
Choice 4
ptr = realloc( ptr, 9 * sizeof( struct customer ) );
Choice 5
realloc( ptr, 10 * sizeof( struct customer ) );
NGUYỄN THỊ BẢO TRANG
» Tin mới nhất:
» Các tin khác: