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:
The constructor and destructor of a class in C++ are called ___
A. automatically
B. manually
C. none of above
-
Câu 2:
Which of the following functions compares two strings?
A. compare();
B. stringcompare();
C. cmp();
D. strcmp();
-
Câu 3:
Identify which of the following are declarations
extern int x; float func(float x) { … } double pow(double, double);
A. 1
B. 2
C. 3
D. 1 and 3
-
Câu 4:
What is output?
void main() { char str[] = {"pvpit"}; char *s1 = str; s1++; printf("%c", *s1); getch(); }
A. pvpit
B. vpit
C. v
D. Another
-
Câu 5:
What will be the output of the program?
#include <stdio.h> #include <conio.h> void main() { static int a[20]; int i = 0; a[i] = i; printf("%d %d %d", a[0], a[1], i); getch(); }
A. 1 0 1
B. 1 1 1
C. 0 0 0
D. 0 1 0
-
Câu 6:
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 7:
Point out a error of the following program
f(int a, int b) { int a; a = 20; return a; }
A. Missing parenthesis in return statement
B. The function should be defined as int f(int a, int b)
C. Re-declaration of a
D. None of above
-
Câu 8:
What is output ?
#include <conio.h> #include <stdio.h> int main() { int i = 0, j = 0; while (i < 5, j < 10) { i++; j++; } printf("%d, %d\n", i, j); getch(); }
A. 5, 5
B. 10, 10
C. Syntax error
-
Câu 9:
Which of the following gives the memory address of a variable pointed to by pointer a?
A. a;
B. *a;
C. &a;
D. address(a);
-
Câu 10:
What value gets printed by the program below?
#include <stdio.h> int main() { int w = 3; int x = 31; int y = 10; double z = x / y % w; printf("%f\n", z); return 0; }
A. 1
B. 0
C. 0.1
-
Câu 11:
Which of the following is a valid function call (assuming the function exists)?
A. funct;
B. funct x, y;
C. funct();
D. int funct();
-
Câu 12:
Lệnh cin trong C++ có tác dụng gì?
A. Là lệnh chú thích trong C++
B. Là lệnh khai báo một biến.
C. Là stream đầu ra chuẩn trong C++.
D. Là stream đầu vào chuẩn của C++.
-
Câu 13:
What is the result of the following code?
void main() { int x = 0; switch(x) { case 1: printf( "One" ); case 0: printf( "Zero" ); case 2: printf( "Hello World" ); } }
A. One
B. Zero
C. Hello World
D. ZeroHello World
-
Câu 14:
A pure virtual function is specified by placing ___ at the end of its prototype in the class
definition.
A. =0
B. =1
C. =-1
-
Câu 15:
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 16:
What is required to avoid falling through from one case to the next?
A. end;
B. break;
C. stop;
D. continue;
-
Câu 17:
What is output of code?
#include <stdio.h> int main() { int a = 320; char *ptr; ptr = (char*)&a; printf("%d ", *ptr); return 0; }
A. 320
B. 64
C. Complier Error
-
Câu 18:
What will be the output of the program?
#include<stdio.h> #include <conio.h> int func(int i, int j) { int k, l; k = i + j; l = i * j; return (k, l); } void main() { int i = 2, j = 3, k, l; k = func(i, j); l = func(i, j); printf("%d %d", k, l); getch(); }
A. 6 6
B. 5 6
C. Complier error
D. None of above
-
Câu 19:
Kết quả đoạn lệnh sau là bao nhiêu?
For (int i = 0; i <= 3; i++) cout << i*i << “,”;
A. 0,1,4,
B. Lặp vĩnh viễn
C. Lỗi biên dịch
D. 0,1,4,9,
-
Câu 20:
A program can use the address of any variable in an expression, except variables declared with the ___ storage class.
A. static
B. register
C. auto
-
Câu 21:
What punctuation ends most lines of C code?
A. .
B. ;
C. '
-
Câu 22:
What is output?
#include <stdio.h> #include <conio.h> void main() { int i = 2, j = 2; while(i+1? --i : j++) printf("%d", i); getch(); }
A. 1
B. 2
C. Complier Error
-
Câu 23:
What will be the output of the program?
#include<stdio.h> #include<conio.h> int main() { int i = 4, j = -1, k = 0, w, x, y, z; w = i||j||k; x = i&&j&&k; y = i||j&&k; z = i&&j||k; printf("%d %d %d %d", w, x, y, z); getch(); }
A. 1 1 1 1
B. 1 0 0 1
C. 1 0 1 1
D. Other
-
Câu 24:
What is output?
void main() { int a = 15, b = 10, c = 5; if(a > b > c) printf("True"); else printf("False"); getch(); }
A. True
B. False
C. Complier Error
D. Run time error
-
Câu 25:
What is output?
#include <stdio.h> #include <conio.h> #define A 0 #define B 1 int main() { int i = 3; switch (i & 1) { case A: printf("FALSE"); break; case B: printf("TRUE"); break; default: printf("Default"); } getch(); }
A. FALSE
B. TRUE
C. Default
-
Câu 26:
Which of the following is a two-dimensional array?
A. array arr[20][20];
B. int arr[20][20];
C. int arr[20, 20];
D. char arr[20];
-
Câu 27:
What is output?
#include <stdio.h> #include <conio.h> void main() { int i = 6; while(i) { if (i > 5) { i--; } i = i + 5; if (i > 34) { break; } } printf("%d", i); getch(); }
A. Infinite loop
B. 35
C. 38
D. 39
-
Câu 28:
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; }
A. 1
B. 2
C. 3
D. None of the lines
-
Câu 29:
The expression of the right hand side of || operators does not get evaluated if the left hand side determines the outcome.
A. True
B. False
-
Câu 30:
Khai báo biến nào sau đây là SAI?
A. double d = 3.14;
B. int num = 10;
C. long lint = 8;
D. short int = 5;
-
Câu 31:
Constructors can be virtual like virtual destructors
A. TRUE
B. FALSE
-
Câu 32:
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 33:
Lệnh nào sau đây định nghĩa một hằng giá trị?
A. const PI = 3.1415;
B. #define PI 3.1415
C. #define PI = 3.1415
D. const float PI;
-
Câu 34:
What will you do to treat the constant 3.14 as a long double?
A. use 3.14LD
B. use 3.14L
C. use 3.14DL
D. use 3.14LF
-
Câu 35:
What is output of code?
#include <stdio.h> #include <conio.h> #include <string.h> void main() { char str1[] = "vncoding"; char str2[] = "vncoding"; if (strcmp(str1, str2)) printf("Equal"); else printf("Unequal"); getch(); }
A. Equal
B. Unequal
C. nothing is printed
-
Câu 36:
What will be output of following program?
#include <stdio.h> #include <conio.h> int main() { int i = 5, j; int *p , *q; p = &i; q = &j; j = 5; printf("%d %d", *p, *q); getch(); }
A. 5 5
B. Complier Error
C. 5 Garbage value
-
Câu 37:
Thế nào là truyền tham trị? Chọn câu trả lời đúng nhất
A. Truyền bản sao của tham số vào biến. Tất cả các thay đổi của biến được thực hiện bởi hàm không ảnh hưởng đến giá trị của biến bên ngoài hàm.
B. Truyền địa chỉ của biến vào hàm.
C. Truyền giá trị của tham số vào biến.
D. Truyền bản sao của biến vào hàm chứ không phải là bản thân biến.
-
Câu 38:
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 39:
What is output ?
#include <stdio.h> int main() { const int i = 5; i++; printf("%d", i); return 0; }
A. 5
B. 6
C. 0
D. Complier error
-
Câu 40:
The heap storage is used for local objects.
A. TRUE
B. FALSE
-
Câu 41:
Which of the following statements should be used to obtain a remainder after dividing 3.14 by 2.1?
A. rem = 3.14%2.1;
B. rem = fmod(3.14, 2.1);
C. rem = modf(3.14, 2.1);
D. Remainder cannot be obtain in floating point division.
-
Câu 42:
What will be output when you will execute following c code?
void main() { int i = 0; char ch = 'A'; do { putchar(ch); } while(i++ < 5 || ++ch <= 'F'); getch(); }
A. AAAAAABCDEF
B. AAAAAABCDE
C. ABCDEF
D. Another
-
Câu 43:
What is output of program?
#include <stdio.h> #include <conio.h> void main() { int a[5] = {1, 2}; printf("%d %d %d", a[2], a[3], a[4]); getch(); }
A. 0 0 0
B. 1 2 2
C. 1 1 1
D. Error
-
Câu 44:
One can apply pointer arithmetic with reference variables.
A. TRUE
B. FALSE
-
Câu 45:
The size of a class with no data members and member functions is ___ bytes
A. 0
B. 1
C. 4
-
Câu 46:
The ___ block contains code that directly or indirectly might cause an exception to be thrown.
A. catch
B. try
C. none of above
-
Câu 47:
Is there any difference between following declarations?
extern int fun( ) ; int fun( );
A. Both are identical
B. No difference, except extern int fun( ); is probably in another file
C. int fun( ); is overrided with extern int fun( );
D. None of these
-
Câu 48:
A function cannot be defined inside another function
A. True
B. False
-
Câu 49:
What do you think is the outcome of calling a redefined non-virtual function using a base-class pointer?
A. The appropriate redefined version of the function will be used
B. The base-class version of the function will always be used
C. The outcome is unpredictable
D. A run-time error will occur
-
Câu 50:
Which of the following special symbol allowed in a variable name?
A. * (asterisk)
B. | (pipeline)
C. – (hyphen)
D. _ (underscore)