Câu 1
What is output of following code? void main() { int ints[] = { 0, 1, 2, 3 }; int* i1 = ints + 1; int* i2 = ints + 2; int a = ++*i1 + *i2++; int b = *++i1 + *i2--; printf("%d#%d", a, b); getch(); }
Đáp án và lời giải
Đáp án: B
Đề gồm 25 câu trắc nghiệm một lựa chọn môn Ngôn ngữ lập trình C; cả 25 câu đều có đáp án. Chọn Luyện tập để biết đúng sai từng câu, hoặc Thi thử có đồng hồ để lấy điểm thang 10.
What is output of following code? void main() { int ints[] = { 0, 1, 2, 3 }; int* i1 = ints + 1; int* i2 = ints + 2; int a = ++*i1 + *i2++; int b = *++i1 + *i2--; printf("%d#%d", a, b); getch(); }
Đáp án: B
What is output of following code? void main() { int i = 400; int *ptr = &i; *++ptr = 2; printf("%d %d", i, *ptr); getch(); }
Đáp án: A
What is output? void main() { char str[] = {"pvpit"}; char *s1 = str; s1++; printf("%c", *s1); getch(); }
Đáp án: C
What is output? void main() { char *s = "\12345s\n"; printf("%d", strlen(s)); printf("\n%s", s); getch(); }
Đáp án: A
For the code below which lines should be reported as errors by a compiler? int main(int argc, char** argv) { const char* foo = "wow"; // line 1 foo = "top"; // line 2 foo[0] = 1; // line 3 return 0; }
Đáp án: C
What is output? void main() { int x = 5,y = 6; int* const p = &x; p = &y; printf("%d", (*p)); getch(); }
Đáp án: A
What is output? void main() { int x = 5, y = 8; const int* p; p = &x; p = &y; x++; printf("%d", *p); getch(); }
Đáp án: C
What is output of code? void main() { int x = 5; const int* p; p = &x; x++; *p = 4; printf("%d", *p); getch(); }
Đáp án: D
What is output of code? #include int main() { int a = 320; char *ptr; ptr = (char*)&a; printf("%d ", *ptr); return 0; }
Đáp án: B
What will be output of following program? #include int main() { int i = 3; int *j; int **k; j = &i; k = &j; printf("%u , %u , %d ", k, *k, **k); return 0; }
Đáp án: A
What will be output of following program? #include #include #include int main() { char *ptr1 = NULL; char *ptr2 = 0; printf("\n%d", ptr2); strcpy(ptr1, "c"); strcpy(ptr2, "questions"); printf("\n%s %s", ptr1, ptr2); getch(); }
Đáp án: B
What will be output of following program? #include #include int main() { int a = 10; void *p = &a; int *ptr = p; printf("%u\n", *ptr); getch(); }
Đáp án: C
What will be output of following program? #include #include int main() { int a = 5, b = 10, c; int *p = &a, *q = &b; c = p - q; printf("%d" , c); getch(); }
Đáp án: A
What will be output of following program? #include #include int main() { int i = 5, j; int *p , *q; p = &i; q = &j; j = 5; printf("%d %d", *p, *q); getch(); }
Đáp án: A
What will be output of following program? #include #include void main() { int i = 5; int *p; p = &i; printf(" %u %u", *&p , &*p); getch(); }
Đáp án: A
What is output? #include #include int main() { int array[2][2][3]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; printf("%d", array[1][0][2]); getch(); }
Đáp án: C
What is output? #include #include void main() { char arr[8]={'V','I','E','T','N','A','M'}; char *p; p=(char *)(arr+2)[2]; printf("%c", p); getch(); }
Đáp án: D
What will be output of following program? #include #include void main() { char ch[]={'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; int *p = (int*)ch; p++; printf("%x", *p); getch(); }
Đáp án: A
What is output? #include #include int main() { int i = 11; int const * p = &i; p++; printf("%d", *p); getch(); }
Đáp án: C
Which of the following statements are correct about an array? 1. The array int num[26]; can store 26 elements 2. The expression num[1] designates the very first element in the array 3. It is necessary to initialize the array at the time of declaration. 4. The declaration num[SIZE] is allowed if SIZE is a macro.
Đáp án: A
Đáp án: B
What is output? (assuming that the array begins at the location 1002 and size of an integer is 4 bytes) #include #include int main() { int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; printf("%u, %u, %u\n", a[0]+1, *(a[0]+1), *(*(a+0)+1)); getch(); }
Đáp án: A
What does the following declaration mean? int (*ptr)[10];
Đáp án: A
What is output? #include #include int main() { char str[] = "LAPTRINHC++\0\.NET\0"; printf("%s\n", str); getch(); }
Đáp án: A
What is output? #include #include void swap(char *, char *); int main() { char *pstr[2] = {"LAPTRINHC++", ".NET"}; swap(pstr[0], pstr[1]); printf("%s%s", pstr[0], pstr[1]); getch(); } void swap(char *t1, char *t2) { char *t; t=t1; t1=t2; t2=t; }
Đáp án: A