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:
Which of the following is the proper declaration of a pointer?
A. int x;
B. int &x;
C. ptr x;
D. int *x;
-
Câu 2:
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 3:
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 4:
Lệnh cout trong C++ đi kèm với cặp dấu nào?
A. >>
B. \\
C. ||
D. <<
-
Câu 5:
What is output?
void main() { int x = 5, y = 8; const int* p; p = &x; p = &y; x++; printf("%d", *p); getch(); }
A. 5
B. 6
C. 8
D. Complier Error
-
Câu 6:
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 7:
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 8:
C++ is a pure object oriented programming language.
A. TRUE
B. FALSE
-
Câu 9:
Output of following code?
const int x = 5; void main() { int x[x]; int y = sizeof(x) / sizeof(int); printf("%d", y); getch(); }
A. 1
B. 5
C. 20
D. ‘x’ isn’t defined
-
Câu 10:
Cách khai báo hàm nào sau đây là đúng?
A. <Tên hàm> { Khối lệnh }
B. <Kiểu dữ liệu trả về> <Tên hàm> (Tham số 1, Tham số 2,..) { Khối lệnh }
C. <Tên hàm> (Tham số 1, Tham số 2,..) { Khối lệnh }
D. <Kiểu dữ liệu trả về> :<Tên hàm> (Tham số 1, Tham số 2,..) { Khối lệnh }
-
Câu 11:
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 12:
The default access for members of a class is ___ .
A. private
B. public
C. protected
D. protect
-
Câu 13:
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 14:
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 15:
Which is not a loop structure?
A. for
B. do while
C. while
D. repeat until
-
Câu 16:
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 17:
What is output?
#include <stdio.h> #include <conio.h> #if X == 3 #define Y 3 #else #define Y 5 #endif void main() { printf("Y = %d", Y); getch(); }
A. Y = 3
B. Y = 5
C. Garbage value
-
Câu 18:
A function may have ant number of return statements each returning different values.
A. True
B. False
-
Câu 19:
How would you round off a value from 1.66 to 2.0?
A. ceil(1.66)
B. floor(1.66)
C. roundup(1.66)
D. roundto(1.66)
-
Câu 20:
It is possible to overload a function template and an ordinary (non-template) function.
A. TRUE
B. FALSE
-
Câu 21:
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 22:
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 23:
Quy tắc đặt tên biến nào sau đây là đúng?
A. Là một chuỗi gồm một hoặc nhiều ký tự chữ, số hoặc ký tự gạch dưới, bắt đầu bằng một ký tự hoặc dấu gạch dưới.
B. Không chứa các ký hiệu Đểc biệt hoặc dấu cách.
C. Không trùng với các từ khoá.
D. Tất cả các quy tắc đầu đúng.
-
Câu 24:
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 25:
New operator allocates memory blocks from the ___.
A. Stack
B. Heap
C. Register
-
Câu 26:
What is output?
#include <stdio.h> #include <conio.h> struct { short s[5]; union { float y; long z; }u; } t; void main() { printf("sizeof(st) = %d", sizeof(t)); getch(); }
A. 16
B. 22
C. 32
D. 18
-
Câu 27:
What is output?
#include <stdio.h> #include <conio.h> int main() { float a = 0.7; if(0.7 > a) printf("Hi\n"); else printf("Hello\n"); getch(); }
A. Hi
B. Hello
C. None of above
-
Câu 28:
What is output?
#include <stdio.h> #include <conio.h> #define SQUARE(x) x*x void main() { int x; x = 36 / SQUARE(6); printf("%d", x); getch(); }
A. 1
B. 36
C. 6
D. 30
-
Câu 29:
Is the following statement a declaration or definition?
extern int i;
A. Declaration
B. Definition
C. A & B
-
Câu 30:
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 31:
In the function template definition it is not necessary to use each type parameter declared in the template prefix.
A. TRUE
B. FALSE
-
Câu 32:
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 33:
C++ programming language was designed and developed by ___ at ___.
A. Steven Job, AT&T Bell Labs
B. Bjarne Stroustrup, AT&T Bell Labs
C. Guido van Rossum, M&D Lab
-
Câu 34:
What will be output of program?
#include <stdio.h> #include <conio.h> void main() { float n = 0.7; if(n < 0.7) printf("LaptrinhC++"); else printf("abc"); getch(); }
A. LaptrinhC++
B. abc
C. Complier error
D. None of these
-
Câu 35:
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 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:
Function can be called either by value or reference
A. True
B. False
-
Câu 38:
What will be output of the program?
#include <stdio.h> #include <conio.h> void main() { int k, num = 20; k = (num>5 ? (num <= 10 ? 10 : 30): 40); printf("%d", k); getch(); }
A. 20
B. 30
C. 40
D. 10
-
Câu 39:
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 40:
What is output?
#include <stdio.h> #include <conio.h> void main() { char c = 125; c = c + 10; printf("%d", c); getch(); }
A. 135
B. 8
C. -121
D. 121
-
Câu 41:
What is output ?
#include <stdio.h> #include <conio.h> #include <string.h> #include <stdlib.h> void myfunc(char** param) { ++param; } void main() { char* string = (char*)malloc(64); strcpy(string, "hello_World"); myfunc(&string); myfunc(&string); printf("%s\n", string); getch(); }
A. hello_World
B. ello_World
C. llo_World
D. lo_World
-
Câu 42:
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 43:
The constructor and destructor of a class in C++ are called ___
A. automatically
B. manually
C. none of above
-
Câu 44:
Name of functions in two different files linked together must be unique.
A. True
B. False
-
Câu 45:
Which of the declaration is correct?
A. int length;
B. char int;
C. int long;
D. float double;
-
Câu 46:
Which library will you add in the following program to work it correctly?
#include <stdio.h> #include <conio.h> void main() { printf("%f", log(1.9)); getch(); }
A. math.h
B. stdlib.h
C. log.h
D. dos.h
-
Câu 47:
What is output of code?
#include <stdio.h> #include <conio.h> void main() { int a = 80; if(a++ > 80) printf("C/C++ %d", a); else printf("Java %d", a); getch(); }
A. C/C++ 80
B. C/C++ 81
C. Java 80
D. Java 81
-
Câu 48:
What is the return type of the function with prototype: “int func(char x, float v, double t);”
A. char
B. int
C. float
D. double
-
Câu 49:
The three member access specifiers are ___, ___ and ___ .
A. public, private, protected
B. public, private, protect
C. public, private, static
-
Câu 50:
What is a base class?
A. An abstract class that is at the top of the inheritance hierarchy.
B. A class with a pure virtual function in it.
C. A class that inherits from another class
D. A class that is inherited by another class, and thus is included in that class.