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)
Chọn phần
-
Câu 1:
What is output?
#include <stdio.h> #include <conio.h> 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; }
A. LAPTRINHC++.NET
B. .NETLAPTRINHC++
C. Address of pstr[0] Address of pstr[1]
-
Câu 2:
What is output? Giả sử dùng VC++ 2008 trên hệ điều hành 32 bit
#include <stdio.h> #include <conio.h> typedef struct { char c; // 1 byte float b; // 4 byte int a; // 4 byte }A; void main() { printf("\n Size of struct: %d", sizeof(A)); getch(); }
A. 9
B. 12
C. 16
D. 24
-
Câu 3:
What is output?
#include <stdio.h> #include <conio.h> typedef struct { int a[2]; // 8 byte char b[5]; // 5 byte char c[5]; // 5 byte }A; void main() { printf("\n Size of struct: %d",sizeof(A)); getch(); }
A. 20
B. 18
C. 32
D. 24
-
Câu 4:
What is output?
#include <stdio.h> #include <conio.h> struct birthday { int d; // day int m; // month int y; // year }; struct info { int ID; // code of staff birthday b; }; void main() { info a = {1009, 16, 9, 1989}; printf("\nID=%d, dd/mm/yyyy = %d/%d/%d", a.ID, a.b.d, a.b.m, a.b.y); getch(); }
A. ID=1009, dd/mm/yyyy = 16/09/1989
B. ID = 1009, dd/mm/yyyy = garbage value/garbage value/garbage value (garbage value: giá trị rác)
C. Error sytax (Lỗi cú pháp)
-
Câu 5:
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 6:
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 7:
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 8:
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 9:
What is output?
#include <stdio.h> #include <conio.h> #define x 5+2 void main() { int i; i = x*x*x; printf("%d", i); getch(); }
A. 21
B. 27
C. Complier Error
D. Another
-
Câu 10:
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 11:
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 12:
What is output?
#include <stdio.h> #include <conio.h> #define X 3 #if !X printf("C/C++"); #else printf("Java"); #endif void main() { getch(); }
A. C/C++
B. Java
C. Complier error
-
Câu 13:
What is output?
#include <stdio.h> #include <conio.h> #define ISEQUAL(X, Y) X == Y void main() { #if ISEQUAL(X, 0) printf("C/C++"); #else printf("Java"); #endif getch(); }
A. C/C++
B. Java
C. Complier error
-
Câu 14:
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 15:
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 16:
What is output?
#include <stdio.h> #include <conio.h> #define MAX 1000 void main() { int MAX = 100; printf("%d ", MAX); getch(); }
A. 1000
B. 100
C. Complier error
-
Câu 17:
What is output?
#include <stdio.h> #include <conio.h> #define PRINT(i, limit) do \ { \ if (i++ < limit) \ { \ printf("laptrinhc++"); \ continue; \ } \ }while(1) void main() { PRINT(0, 3); getch(); }
A. ‘laptrinhc++’ is printed 3 times
B. ‘laptrinhc++’ is printed 2 times
C. Complier error
-
Câu 18:
A ____ is a special member function used to initialize the data members of a class.
A. constructor
B. destructor
C. static method
-
Câu 19:
The default access for members of a class is ___ .
A. private
B. public
C. protected
D. protect
-
Câu 20:
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 21:
Inheritance enables ___ which saves time in development , and encourages using previously
proven and high quality software.
A. reusability
B. encapsulation
C. development
-
Câu 22:
The three member access specifiers are ___, ___ and ___ .
A. public, private, protected
B. public, private, protect
C. public, private, static
-
Câu 23:
A “has a” relationship between classes represents ___ and an “is a” relationship between
classes represent ___ .
A. containment, inheritance
B. hiding, inheritance
C. encapsulation, inheritance
-
Câu 24:
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 25:
A operator ___ is called as de-referencing operator.
A. &
B. *
C. &&
-
Câu 26:
The size of a class with no data members and member functions is ___ bytes
A. 0
B. 1
C. 4
-
Câu 27:
A class is called as abstract base class if it has a ___ function
A. pure virtual
B. static
C. private
-
Câu 28:
Run-time or dynamic allocation of memory may be done using the C++ operator ___ .
A. new
B. alloc
C. malloc
-
Câu 29:
Operator overloading permits to extend the applicability of existing C++ operators so that they work with new ___ or ___.
A. data types, objects
B. data types, constant
C. data types, pointer
-
Câu 30:
A ___ is a set of instance or values.
A. class
B. object
C. function
-
Câu 31:
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 32:
C++ is a ___ programming language with ___ extensions.
A. procedural, object oriented
B. object, procedural
C. procedural, STL
-
Câu 33:
Pointers are ___ that contain the addresses of other variables and ____ .
A. value, object
B. object, class
C. variables, functions
-
Câu 34:
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 35:
New operator allocates memory blocks from the ___.
A. Stack
B. Heap
C. Register
-
Câu 36:
The new operator throws a ___ when heap is exhausted.
A. runtime exception
B. syntax error
C. logic error
-
Câu 37:
The (assert.h) header is used for ___ .
A. debugging
B. checking memory leak
C. library for time
-
Câu 38:
The constructor and destructor of a class in C++ are called ___
A. automatically
B. manually
C. none of above
-
Câu 39:
Two or more functions may have the same name, as long as their ___ are different.
A. return type
B. parameter lists
C. none of above
-
Câu 40:
A constructor with default arguments for all its parameters is called a ___ constructor.
A. static
B. run-time
C. default
-
Câu 41:
Static member functions can access only the ___ data members of a class.
A. dynamic
B. static
C. public
-
Câu 42:
The two types of polymorphism is : ____ & ____ .
A. Run time and compile time
B. Preprocessor, compile time
C. Preprocessor, Linker
-
Câu 43:
A file stream is an extension of a ___ stream.
A. console
B. windows
C. none of above
-
Câu 44:
The Standard Template Library(STL) is a library of ___ templates.
A. container class
B. time class
C. none of above
-
Câu 45:
Run time polymorphism is ___ than the compile time polymorphism.
A. less flexible
B. more flexible
C. none of above
-
Câu 46:
With private inheritance, public and protected members of the base class become ___ members of
the derived class.
A. private
B. public
C. protected
-
Câu 47:
The STL Container adapters contains the ___ , ___ and ___ STL containers.
A. Stack, Queue, Priority_queue
B. Set, Multiset, Map
C. vectors, lists, deques
-
Câu 48:
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 49:
When writing function or class template, one use a ___ to specify a generic data type.
A. template parameters
B. keyword
C. none of above
-
Câu 50:
Data items in a class may be public.
A. TRUE
B. FALSE