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 special symbol allowed in a variable name?
A. * (asterisk)
B. | (pipeline)
C. – (hyphen)
D. _ (underscore)
-
Câu 2:
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 3:
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 4:
What is output?
#include <stdio.h> #include "conio.h" void main() { int i = 3; switch (i) { case 0+1: printf("A"); break; case 1+2: printf("B"); break; default: printf("ABC"); } getch(); }
A. A
B. B
C. ABC
-
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 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 7:
What is output?
#include<stdio.h> #include <conio.h> int main() { int a = 5; switch(a) { default: a = 4; case 6: a--; case 5: a = a + 1; case 1: a = a - 1; } printf("%d \n", a); getch(); }
A. 3
B. 4
C. 5
D. 6
-
Câu 8:
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 9:
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 10:
What will be output of program?
#include <stdio.h> #include <conio.h> void main() { float n = 0.7; if(n < 0.7f) printf("LaptrinhC++"); else printf("abc"); getch(); }
A. LaptrinhC++
B. abc
C. Complier error
D. None of these
-
Câu 11:
A constructor with default arguments for all its parameters is called a ___ constructor.
A. static
B. run-time
C. default
-
Câu 12:
It Is legal to return local variables from a function which returns by reference.
A. TRUE
B. FALSE
-
Câu 13:
Which of the following can be virtual?
A. constructors
B. destructors
C. static functions
D. None of the above
-
Câu 14:
What is output of the program?
#include <stdio.h> #include <conio.h> void main() { int i = 3, j = 2, k = -1, m; m = ++i&&++j&&++k; printf("%d %d %d %d", i, j, k, m); getch(); }
A. 4 3 0 0
B. 3 3 0 1
C. 4 2 0 0
D. None of these
-
Câu 15:
What is output?
#include <stdio.h> #include <conio.h> int main() { int array[2][2][3]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; printf("%d", array[1][0][2]); getch(); }
A. 6
B. 7
C. 8
D. 9
-
Câu 16:
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 17:
What is output of code?
void main() { if ((1 || 0) && (0 || 1)) { printf("ABC"); } else { printf("DEF"); } getch(); }
A. ABC
B. DEF
C. Syntax error
-
Câu 18:
What gets printed?
void main() { int array[2][2] = {0, 1, 2, 3}; int i; int sum = 0; for (i = 0; i < 4; ++i) { int x, y; x = i % 2; if (x) { y = 0; } else { y = 1; } sum += array[x][y]; } printf("%d\n", sum); getch(); }
A. 3
B. 4
C. 5
D. 6
-
Câu 19:
In which standard library file is the function printf( ) located?
A. stdio.h
B. conio.h
C. stdlib.h
D. ouput.h
-
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:
What is the only function all C programs must contain?
A. start()
B. system()
C. main()
D. program()
-
Câu 22:
There can be a null reference.
A. TRUE
B. FALSE
-
Câu 23:
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 24:
Which of the declaration is correct?
A. int length;
B. char int;
C. int long;
D. float double;
-
Câu 25:
A float occupies 4 bytes. If the hexadecimal equivalent of these 4 bytes A, B, C and D, then when this float is stored in memory in which of the following order do these bytes gets stored?
A. ABCD
B. DCBA
C. 0xABCD
D. Depend on big endian or little endian architecture.
-
Câu 26:
What is the output of the following code?
#include <iostream> int count = 0; class obj { public: obj() { count++; } ~obj() { count--; } }; int main() { obj A, B, C, D, E; obj F; { obj G; } std::cout << count; return 0; }
A. 0
B. 5
C. 6
D. 7
-
Câu 27:
A class member that is to be shared among all objects of a class is called
A. A const member
B. A reference parameter
C. A static member
D. A function member
-
Câu 28:
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 29:
Usually recursion works slower than loops
A. Yes
B. No
-
Câu 30:
What gets printed?
void main() { int i = 3; if (!i) i++; i++; if (i == 3) i += 2; i += 2; printf("%d\n", i); getch(); }
A. 5
B. 6
C. 7
D. Another
-
Câu 31:
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 32:
What character ends all strings?
A. ‘.’
B. ‘ ‘
C. ‘\0’
D. ‘/0’
-
Câu 33:
Trong cấu trúc chương trình C++ có bao nhiêu hàm main()?
A. 1
B. 2
C. 3
D. 4
-
Câu 34:
Friendship is commutative.
A. TRUE
B. FALSE
-
Câu 35:
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 36:
What is output of code?
#include <stdio.h> #include <conio.h> void main() { int i; i = 0; if(i = 15, 10, 5) printf("C/C++ %d", i); else printf("Java %d", i); getch(); }
A. C/C++ 15
B. Java 15
C. Java 5
D. Complier error
-
Câu 37:
Which of the following accesses a variable in structure b?
A. b→var;
B. b.var;
C. b-var;
D. b>var;
-
Câu 38:
If a class declares a variable static, this means:
A. Each instance of a class will have its own copy of the variable
B. Changing the variable in one instance will have no effect on other instances of the class
C. Changing the variable in one instance will have no effect on other instances of the class
D. Every instance of the class must consider the value of the static variable before initializing
-
Câu 39:
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 40:
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 41:
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 42:
What is output?
#include <stdio.h> #include <conio.h> void main() { int i, j; for(i = 0, j = 0; i < 5, j < 6; i++, j++) { printf("i = %d \t j = %d\n", i, j); } getch(); }
A. print i and j from 0 till 4
B. print i and j from 0 till 5
C. print i from 0 to 4, print j from 0 to 5
D. Complier Error
-
Câu 43:
Once an exception has been thrown, it is not possible for the program to jump back to the throw point.
A. TRUE
B. FALSE
-
Câu 44:
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 45:
Nguyên lý của cấu trúc while là:
A. Chương trình sẽ lặp đi lặp lại khối lệnh cho đến khi biểu thức điều kiện bằng 0.
B. Chương trình sẽ lặp đi lặp lại khối lệnh cho đến khi biểu thức điều kiện sai.
C. Chương trình sẽ lặp đi lặp lại khối lệnh cho đến khi biểu thức điều kiện đúng.
D. Không có đáp án đúng.
-
Câu 46:
What is a destructor?
A. A function called when an instance of a class is initialized
B. A function that is called when an instance of a class is deleted
C. A special function to change the value of dynamically allocated memory
D. A function that is called in order to change the value of a variable
-
Câu 47:
Which of the following adds one string to the end of another?
A. append();
B. stringadd();
C. strcat();
D. stradd();
-
Câu 48:
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 49:
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 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.