400 Câu hỏi trắc nghiệm lập trình C/C++ có đáp án và lời giải chi tiết
Tổng hợp câu hỏi trắc nghiệm lập trình C/C++ có đáp án và lời giải đầy đủ nhằm giúp các bạn dễ dàng ôn tập lại toàn bộ các kiến thức. Để ôn tập hiệu quả các bạn có thể ôn theo từng phần trong bộ câu hỏi này bằng cách trả lời các câu hỏi và xem lại đáp án và lời giải chi tiết. Sau đó các bạn hãy chọn tạo ra đề ngẫu nhiên để kiểm tra lại kiến thức đã ôn.
Chọn hình thức trắc nghiệm (50 câu/60 phút)
-
Câu 1:
What is output?
#include <stdio.h> #include <conio.h> int main() { int x = 011, i; for(i = 0; i < x; i += 3) { printf("Start "); continue; printf("End"); } getch(); }
A. Start End Start End
B. Start Start Start
C. Start Start Start Start
-
Câu 2:
Which of the following is the boolean operator for logical-and?
A. &
B. &&
C. |
D. |&
-
Câu 3:
Which of the following special symbol allowed in a variable name?
A. * (asterisk)
B. | (pipeline)
C. – (hyphen)
D. _ (underscore)
-
Câu 4:
What is output?
#include <stdio.h> #include <conio.h> int main() { int i = 11; int const * p = &i; p++; printf("%d", *p); getch(); }
A. 11
B. 12
C. Garbage value
D. Complier error
-
Câu 5:
Is it true that too many recursive calls may result into stack overflow?
A. Yes
B. No
-
Câu 6:
What will be output when you will execute following c code? Biết kích thước kiểu char : 1 byte, float : 4 byte, int : 4 byte, double : 8 byte, long : 4 byte.
#include <stdio.h> #include <conio.h> int main() { printf("%d\t", sizeof(6.5)); printf("%d\t", sizeof(90000)); printf("%d", sizeof('A')); getch(); }
A. 8 4 1
B. 8 2 1
C. 4 4 1
D. Depend on complier
-
Câu 7:
Hàm overloaded là những hàm như thế nào?
A. Các hàm trùng tên nhưng khác về cách khai báo tham số
B. Các hàm có cùng kiểu dữ liệu trả về
C. Không có đáp án đúng
D. Các hàm trùng tham số những khác nhau về tên
-
Câu 8:
What is the correct value to return to the operating system upon the successful completion of a program?
A. 0
B. -1
C. 1
D. Do not return a value
-
Câu 9:
In C++ one can get the memory addresses of variables and functions.
A. TRUE
B. FALSE
-
Câu 10:
What is output?
#include <conio.h> #include <stdio.h> int main() { int i = 0; while (i = 0) printf("True\n"); printf("False\n"); getch(); }
A. True
B. False
C. Complie Error
D. Another
-
Câu 11:
There can be a null reference.
A. TRUE
B. FALSE
-
Câu 12:
In the expression a = b = 5 the order of Assignment is NOT decided by Associativity of operators.
A. True
B. False
-
Câu 13:
Which of the following operators can be applied on structure variables?
A. Equality comparison ( == )
B. Assignment ( = )
C. Both of the above
D. None of the above
-
Câu 14:
Which of the following gives the memory address of the first element in array arr, an array with 100 elements?
A. arr[0];
B. arr;
C. &arr;
D. arr[1];
-
Câu 15:
Every operators has an Associativity
A. Yes
B. No
-
Câu 16:
What will be output of following program?
#include <stdio.h> #include <conio.h> int main() { int a = 10; void *p = &a; int *ptr = p; printf("%u\n", *ptr); getch(); }
A. int a = 10;
B. void *p = &a;
C. int *ptr = p;
D. printf("%u\n", *ptr);
-
Câu 17:
What is output ?
#include <stdio.h> #include <conio.h> void main() { int i = 5,j = 6; printf("%d", i | j); getch(); }
A. 7
B. 6
C. 5
D. 1
-
Câu 18:
What is the final value of x when the code is run?
int x; for(x = 0; x < 10; x++) { }
A. 10
B. 9
C. 0
D. 1
-
Câu 19:
What is output?
void main() { int ints[] = { 0, 1, 2, 3 }; int* i1 = ints + 1; int a = ++*i1; int b = a + *i1; printf("%d\n", b); getch(); }
A. 3
B. 4
C. 5
D. 6
-
Câu 20:
Which of the following gives the memory address of integer variable a?
A. *a;
B. a;
C. &a;
D. address(a);
-
Câu 21:
What is output?
void main() { int ints[] = { 0, 5, 10, 15 }; int* i2 = ints + 2; int a = *i2++; // a = *(i2++); printf("%d#%d\n", a, *i2); getch(); }
A. 10#15
B. 10#10
C. 15#15
D. 11#15
-
Câu 22:
Để chú thích trên nhiều dòng lệnh trong chương trình C++, ta dùng cặp dấu nào?
A. \\
B. >>
C. /* và */
D. <<
-
Câu 23:
What is output of code?
#include <stdio.h> #include <conio.h> void main() { if(1,0) printf("True"); else printf("False"); getch(); }
A. True
B. False
C. Complier error
-
Câu 24:
What gets printed?
void main() { int x; if(x = 0) printf ("Value of x is 0"); else printf ("Value of x is not 0"); getch(); }
A. Value of x is 0
B. Value of x is not 0
C. Error
-
Câu 25:
What is output?
#include <stdio.h> #include <conio.h> #define a 10 void main() { printf("%d ", a); #define a 50 printf("%d ", a); getch(); }
A. 10 50
B. 10 10
C. 50 50
-
Câu 26:
Kết quả đoạn lệnh sau là bao nhiêu?
For (int i = 0,n = 4; n != i; i++,n--) cout << i << “,”;
A. Lặp vĩnh viễn
B. 0,1,2,
C. Lỗi biên dịch
D. 0,1,
-
Câu 27:
What is output?
#include <conio.h> #include <stdio.h> void foo(); int main() { printf("%d ", 1); goto l1; printf("%d ", 2); } void foo() { l1: printf("3 "); }
A. Complie error
B. 3
C. 1
D. 1 3
-
Câu 28:
What is output of program?
#include <stdio.h> #include <conio.h> void main() { extern int func(float); int a; a = func(3.14); printf("%d", a); getch(); } int func(float a) { return (int)++a; }
A. 3
B. 4
C. Complier Error
D. 3.14
-
Câu 29:
What will be output when you will execute following c code?
#include <stdio.h> int main() { double num = 5.2; int var = 5; printf("%d\t", sizeof(!num)); printf("%d\t", sizeof(var=15/2)); printf("%d", var); return 0; }
A. 1 4 5
B. 1 4 7
C. 8 4 7
D. Another
-
Câu 30:
What is output?
#include <stdio.h> #include <conio.h> int main() { int x = 3; if (x == 2); x = 0; if (x == 3) x++; else x += 2; printf("x = %d", x); getch(); }
A. x = 2
B. x = 6
C. x = 0
-
Câu 31:
What gets printed ?
void main() { static int i; while(i <= 10&&i >= 0) (i > 2 ? i++ : i--); printf("%d", i); getch(); }
A. -1
B. 0
C. 1
D. Complier error
-
Câu 32:
Kết thúc một dòng lệnh trong chương trình C++, ta sử dụng ký hiệu gì?
A. Dấu ,
B. Dấu .
C. Dấu :
D. Dấu ;
-
Câu 33:
What is output of the program?
#include <stdio.h> #include <math.h> #include <conio.h> void main() { printf("%f", sqrt(36.0)); getch(); }
A. 6.000000
B. 6
C. Error
-
Câu 34:
Trong cấu trúc chương trình C++, lệnh #include dùng để làm gì?
A. Thông báo trong chương trình sử dụng các lệnh tính toán, thông báo các biến sử dụng trong thân chương trình.
B. Khai báo các câu lệnh được sử dụng trong chương trình. Phải tạo các câu lệnh trước thì mới sử dụng được trong chương trình C++.
C. Thông báo cho bộ tiền biên dịch thêm các thư viện chuẩn trong C++. Các lệnh được sử dụng trong thân chương trình phải có prototype nằm trong các thư viện chuẩn này.
D. Không có đáp án đúng.
-
Câu 35:
In C++ one can define a function within another function.
A. TRUE
B. FALSE
-
Câu 36:
When does the code block following while(x<100) execute?
A. When x is less than one hundred
B. When x is greater than one hundred
C. When x is equal to one hundred
D. While it wishes
-
Câu 37:
A class that builds a linked list should destroy the list in the class destructor.
A. TRUE
B. FALSE
-
Câu 38:
Static member functions ___
A. can be used without an instantiation of an object
B. can only access static data
C. Both 1 and 2 are correct
D. Neither 1 nor 2 are correct
-
Câu 39:
The library function used to find the last occurrence of a character in a string is
A. strnstr()
B. strrchr()
C. laststr()
D. strstr()
-
Câu 40:
What will be output when you will execute following c code?
#include <stdio.h> int main() { char a = 250; int expr; expr= a + !a + ~a + ++a; printf("%d", expr); return 0; }
A. -6
B. 5
C. 4
D. Another
-
Câu 41:
The two types of polymorphism is : ____ & ____ .
A. Run time and compile time
B. Preprocessor, compile time
C. Preprocessor, Linker
-
Câu 42:
What is output?
void main() { int i = 5, k; if (i == 0) goto label; label: printf("%d", i); printf("Hey"); getch(); }
A. Hey
B. 5
C. 5Hey
D. Complie error
-
Câu 43:
We can implement generic classes using templates
A. TRUE
B. FALSE
-
Câu 44:
What is output?
#include <stdio.h> #include <conio.h> void main() { int i, j; i = j = 2; while(--i&&j++) printf("%d %d", i, j); getch(); }
A. 1 3
B. 1 2
C. Không in ra kí tự nào
-
Câu 45:
A long double can be used if range of a double is not enough to accommodate a real number?
A. True
B. False
-
Câu 46:
In the following program how long will the for loop get executed?
#include <stdio.h> #include <conio.h> void main() { int i = 5; for(;scanf("%d", &i); printf("%d", i)); getch(); }
A. The for loop would not get executed at all
B. The for loop would get executed only once
C. The for loop would get executed 5 times
D. The for loop would get executed infinite times
-
Câu 47:
What is output? (assuming that the array begins at the location 1002 and size of an integer is 4 bytes)
#include <stdio.h> #include <conio.h> 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(); }
A. 1006, 2, 2
B. 1006, 4, 4
C. 1002, 5, 5
D. Error
-
Câu 48:
What is output of the program?
#include <stdio.h> #include <conio.h> void main() { int i = 3; i = i++; printf("%d", i); getch(); }
A. 4
B. 3
C. Complier error
D. None of above
-
Câu 49:
What is output?
#include <stdio.h> #include <conio.h> typedef struct { int x; static int y; }st; void main() { printf("sizeof(st) = %d", sizeof(st)); getch(); }
A. 4
B. Complier error
C. 8
-
Câu 50:
Which of the following is the correct usage of condition operators used in C?
A. a>b? c = 20 : c = 21;
B. a>b? c = 20;
C. max = a>b? a>c?a:c:b>c?b:c;
D. return (a>b)?(a:b);