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:
In case of a copy constructor, which of the following is true?
A. Used to instantiate an object from another existing object
B. To copy one object to another existing object
C. Can be a substitute for a ‘=’ operator
D. All of the above
-
Câu 2:
What will be output of the program?
#include <stdio.h> #include <conio.h> void main() { int x = 4, y, z; y = --x; z = x--; printf("%d %d %d", x, y, z); getch(); }
A. 4 3 2
B. 4 3 3
C. 2 3 2
D. 2 3 3
-
Câu 3:
Kết quả đoạn lệnh sau là bao nhiêu?
For (int i = 0; i < 3; i++) cout << i*i << “,”;
A. Lỗi biên dịch
B. 0,1,4,9,
C. Lặp vĩnh viễn
D. 0,1,4,
-
Câu 4:
Every function must return a value
A. Yes
B. No
-
Câu 5:
What is output?
#include <conio.h> #include <stdio.h> int main() { int i = 0, j = 0; while (i < 2) { l1: i++; while (j < 3) { printf("loop\n"); goto l1; } } getch(); }
A. loop loop loop
B. Infinite loop
C. Complie error
-
Câu 6:
What are the difference types of real data type in C?
A. float, double
B. short int, double, long int
C. float, double, long double
D. double, long int, float
-
Câu 7:
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 8:
A class object passed to a function template must overload any operators used on the class object by the template.
A. TRUE
B. FALSE
-
Câu 9:
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 10:
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 11:
The design of classes in a way that hides the details of implementation from the user is known as:
A. Encapsulation
B. Information Hiding
C. Data abstraction
D. All of the above
-
Câu 12:
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 13:
The Standard Template Library(STL) is a library of ___ templates.
A. container class
B. time class
C. none of above
-
Câu 14:
A class template may not be used as a base class.
A. TRUE
B. FALSE
-
Câu 15:
Output of following code?
void count() { static int page = 0; printf("%d", page); page++; } void main() { int i; for(i = 0; i < 10; i++) { count(); } getch(); }
A. 0123456789
B. 0000000000
C. 0101010101
-
Câu 16:
The two types of polymorphism is : ____ & ____ .
A. Run time and compile time
B. Preprocessor, compile time
C. Preprocessor, Linker
-
Câu 17:
Output of following code?
void main() { int x; { x++; } printf("%d", x); getch(); }
A. 1
B. 0
C. Error
-
Câu 18:
What is output?
void main() { int x = 5,y = 6; int* const p = &x; p = &y; printf("%d", (*p)); getch(); }
A. Complier error
B. 6
C. 5
D. Another
-
Câu 19:
Which of the following statements are correct about this function
long fun(int n) { int i; long f = 1; for(i = 1; i <= n; i++) f = f*i; return f; }
A. The function calculates the value of 1 raised to power n
B. The function calculates the factorial value of an integer
C. The function calculates the square root of an integer
D. None of above
-
Câu 20:
What is output of code?
#include <stdio.h> #include <conio.h> void main() { int i; i = 10; if(i == 20 || 30) printf("True"); else printf("False"); getch(); }
A. True
B. False
C. Complier error
-
Câu 21:
Static data members cannot be private.
A. TRUE
B. FALSE
-
Câu 22:
What does the following declaration mean?
int (*ptr)[10];
A. ptr is array of pointers to 10 integers
B. ptr is a pointer to an array of 10 integers
C. ptr is an array of 10 integers
D. ptr is an pointer to array
-
Câu 23:
What will be output of following program?
#include <stdio.h> #include <conio.h> int main() { int a = 5, b = 10, c; int *p = &a, *q = &b; c = p - q; printf("%d" , c); getch(); }
A. 3
B. 4
C. 5
D. 6
-
Câu 24:
What is output?
#include <stdio.h> #include <conio.h> int main() { int i = 3; while (i--) { int i = 100; i--; printf("%d ", i); } getch(); }
A. 99 99 99
B. Complier Error
C. 1
-
Câu 25:
What will be output of the program?
#include <stdio.h> #include <conio.h> void main() { int arr[3] = {3}; int i; for(i = 0; i <= 2; i++) printf("%d, ", arr[i]); getch(); }
A. 3, 0, 0,
B. 3, 3, 3,
C. 3, garbage, garbage
D. Another
-
Câu 26:
It is possible to overload a function template and an ordinary (non-template) function.
A. TRUE
B. FALSE
-
Câu 27:
std::cout is a standard input stream.
A. TRUE
B. FALSE
-
Câu 28:
We want to round off x, a float, to an int value, The correct way to do is:
A. y = (int)(x + 0.5)
B. y = int(x + 0.5)
C. y = (int)x + 0.5
D. y = (int)((int)x + 0.5)
-
Câu 29:
What is the output of the following code?
#include <iostream> using namespace std; class Parent { public: Parent() { Status(); } virtual ~Parent() { Status(); } virtual void Status() { cout << "Parent "; } }; class Child : public Parent { public: Child() { Status(); } virtual ~Child() { Status(); } virtual void Status() { cout << "Child "; } }; void main() { Child c; }
A. Parent Parent
B. Parent Child Child Parent
C. Child Parent Parent Child
D. Error
-
Câu 30:
Output of following code?
void main() { int x=0; { int x = 0, y = 0; y++; x++; } printf("%d", x); getch(); }
A. 1
B. Error
C. 0
-
Câu 31:
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 32:
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 33:
Data items in a class may be public.
A. TRUE
B. FALSE
-
Câu 34:
Kết quả đoạn lệnh sau là bao nhiêu?
For (;;) cout << i*i << “,”;”
A. Lỗi biên dịch
B. Lặp vĩnh viễn
C. 0,1,4,
D. 0,1,4,9,
-
Câu 35:
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 36:
What is output?
#include <stdio.h> #include <conio.h> #define call(x,y) x##y void main() { int x = 5, y = 10, xy = 20; printf("%d", xy + call(x, y)); getch(); }
A. 530
B. 70
C. 40
D. Complier Error
-
Câu 37:
A variable that is declared protected:
A. Is visible only in the subclasses (and not in the class it is declared in)
B. Is visible only in the class it is declared in
C. Is visible to all classes, but modifiable only in the class where it is declared
D. Is visible in the class it is declared in, and all of its sub-classes
-
Câu 38:
Which of the following functions compares two strings?
A. compare();
B. stringcompare();
C. cmp();
D. strcmp();
-
Câu 39:
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 40:
What is output?
#include <stdio.h> #include <conio.h> void main() { struct site { char name[] = "laptrinhc++"; int year = 2; }; struct site *ptr; printf("%s ", ptr->name); printf("%d", ptr->year); getch(); }
A. laptrinhc++ 2
B. Complier error
C. Runtime error
-
Câu 41:
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 42:
Member functions of a class are normally made ___ and data members of a class are normally
made ___ .
A. private, public
B. protected, public
C. public, private
D. public, protected
-
Câu 43:
What is output of code?
void main() { int x = 5; const int* p; p = &x; x++; *p = 4; printf("%d", *p); getch(); }
A. 4
B. 5
C. 6
D. Complier Error
-
Câu 44:
What is output of program?
#include <stdio.h> #include <conio.h> void main() { int x = 10, y = 20, z = 5, i; i = x < y < z; printf("i = %d", i); getch(); }
A. i = 0
B. i = 1
C. Error
D. None of these
-
Câu 45:
What is output?
void main() { int x = 0, y = 0; if(x == 0 || ++y) printf("x=%d", x); printf(" y=%d", y); getch(); }
A. x=0 y=1
B. x=0 y=0
C. Error syntax
-
Câu 46:
What will be the output of the program?
#include <stdio.h> #include <conio.h> void main() { int x = 12, y = 7, z = 2; z = x != 4 || y == 2; printf("z = %d", z); getch(); }
A. z = 0
B. z = 1
C. z = 4
D. z = 3
-
Câu 47:
What is output?
#include <stdio.h> int main() { char *url="c:\tc\bin\rw.c"; printf("%s", url); return 0; }
A. c:/tc/bin/rw.c
B. c: c inw.c
C. c:cinw.c
D. w.c in
-
Câu 48:
In C all function except main( ) can be called recursively
A. True
B. False
-
Câu 49:
I want a nonmember function to have access to the private members of a class. The class must declare that function:
A. friend
B. inline
C. static
D. virtual
-
Câu 50:
Which of the following correctly shows the hierarchy of arithmetic operator in C?
A. / + * –
B. * – / +
C. + – / *
D. / * + –