1. What is the correct value to return to the operating system upon the successful completion of a program?
A. 0
B. -1
C. 1
D. Do not return a value
Đáp án
Khi kết thúc chương trình C, giá trị nào được trả về cho hệ điều hành? A
2. What is the only function all C programs must contain?
A. start()
B. system()
C. main()
D. program()
C Bất cứ chương trình C nào đều phải có hàm main()
3. What punctuation is used to signal the beginning and end of code blocks?
A. { }
B.→ and ←
C. BEGIN and END
D. ( and )
A Dấu {} được dùng để đánh dấu điểm bắt đầu và kết thúc 1 block code (thân hàm, while, for, if/else,..)
4. What punctuation ends most lines of C code?
A. .
B. ;
C. :
D. ‘
B Dấu ; được dùng để đánh dấu điểm kết thúc 1 dòng code.
5. Which of the following is a correct comment?
A. */ Comments */
B. ** Comment **
C. /* Comment */
D. { Comment }
C Trong ngôn ngữ C, có 2 cách comment là: "// Comments" : 1 dòng code "/* Comment */" : 1 block code
6. Which of the following is not a correct variable type?
A. float
B. real
C. int
D. double
B "real" không phải là kiểu dữ liệu trong ngôn ngữ lập trình C/C++
7. Which of the following is the correct operator to compare two variables?
A. :=
B. =
C. equal
D. ==
D "==" là toán tử dùng để so sánh 2 biến với nhau.
8. Which of the following is true?
A. 1
B. 66
C. .1
D. -1
E. All of the above
E Kiểu dữ liệu boolean được định nghĩa như sau: true: giá trị khác không, false: giá trị bằng 0.
9. Which of the following is the boolean operator for logical-and?
A. &
B. &&
C. |
D. |&
B Toán tử logic AND được kí hiệu là: &&
10. Evaluate !(1 && !(0 || 1))
A. True
B. False
C. Unevaluatable
A
11. Which of the following shows the correct syntax for an if statement?
A. if expression
B. if { expression
C. if ( expression )
D. expression if
C xem lệnh if/else
12. What is the final value of x when the code is run?
int x; for(x = 0; x < 10; x++) { }
A. 10
B. 9
C. 0
D. 1
Đáp án
A
13. 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
A
14. Which is not a loop structure?
A. for
B. do while
C. while
D. repeat until
D
15. How many times is a do while loop guaranteed to loop?
A. 0
B. Infinitely
C. 1
D. Variable
C
16. Which is not a proper prototype?
A. int funct(char x, char y);
B. double funct(char x)
C. void funct();
D. char x();
B Câu lệnh khai báo hàm thiếu dấu ;
17. 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
B
18. 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
19. Which of the following is a complete function?
A. int funct();
B. int funct(int x) {return x=x+1;}
C. void funct(int) {printf( “Hello” );
D. void funct(x) {printf( “Hello” ); }
B
20. Which follows the case statement?
A. :
B. ;
C. –
D. A newline
A
21. What is required to avoid falling through from one case to the next?
A. end;
B. break;
C. stop;
D. continue;
B
22. What keyword covers unhandled possibilities?
A. all
B. continue
C. default
D. other
C
23. What is the result of the following code?
#include <stdio.h> 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
D Do không có lệnh break giữa các case. Khi x = 0, lệnh case 0 và case 2 được thực hiện.
24. Which of the following is the proper declaration of a pointer?
A. int x;
B. int &x;
C. ptr x;
D. int *x;
D
25. Which of the following gives the memory address of integer variable a?
A. *a;
B. a;
C. &a;
D. address(a);
C
26. 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);
A
27. Which of the following gives the value stored at the address pointed to by pointer a?
A. a;
B. val(a);
C. *a;
D. &a;
C
28. Which of the following is the proper keyword or function to allocate memory in C?
A. new
B. malloc
C. create
D. value
B
29. Which of the following is the proper keyword or function to deallocate memory in C language?
A. free
B. delete
C. clear
D. remove
B
30. Which of the following accesses a variable in structure b?
A. b→var;
B. b.var;
C. b-var;
D. b>var;
B
31. Which of the following accesses a variable in a pointer to a structure, *b?
A. b→var;
B. b.var;
C. b-var;
D. b>var;
A
32. Which of the following is a properly defined struct?
A. struct {int a;}
B. struct a_struct {int a;}
C. struct a_struct int a;
D. struct a_struct {int a;};
D
33. Which properly declares a variable of struct foo?
A. struct foo;
B. struct foo var;
C. foo;
D. int foo;
B
34. Which of the following correctly declares an array?
A. int arr[10];
B. int arr;
C. arr{10};
D. array arr[10];
A
35. What is the index number of the last element of an array with 29 elements?
A. 29
B. 28
C. 0
D. Programmer-defined
B
36. 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];
B
37. Which of the following correctly accesses the seventh element stored in foo, an array with 100 elements?
A. foo[6];
B. foo[7];
C. foo(7);
D. foo;
A
38. Which of the following gives the memory address of the first element in array arr, an array with 100 elements?
A. arr[0];
B. arr;
C. &arr;
D. arr[1];
B
39. Which of the following is a string literal?
A. Static String
B. “Static String”
C. ‘Static String’
D. char string[100];
B
40. What character ends all strings?
A. ‘.’
B. ‘ ‘
C. ‘\0’
D. ‘/0’
C
41. Which of the following reads in a string named x with one hundred characters?
A. fgets(x, 101, stdin);
B. fgets(x, 100, stdin);
C. readline(x, 100, ‘\n’);
D. read(x);
B
42. Which of the following functions compares two strings?
A. compare();
B. stringcompare();
C. cmp();
D. strcmp();
D
43. Which of the following adds one string to the end of another?
A. append();
B. stringadd();
C. strcat();
D. stradd();
C
A. stdio.h
B. conio.h
C. stdlib.h
D. ouput.h Đáp án
A
B
A. >
B. <
C. <=
D. None above
Đáp án
D
A. The first statement of main( )
B. The first statement of program
C. The first statement after the comment /**/
D. The first statement of end function
Đáp án
A
A. Because they tell the complier that a function is declared later
B. Because they make program readable
C. Because they allow the programmer to see a quick list of function in the program along with the argument for each function.
D. All of the above
Đáp án
A Function phototype chính là việc khai báo hàm. Nếu việc gọi hàm trước khi hàm được khai báo. Trình biên dịch thông báo lỗi.
B Toán tử % lấy phần dư của phép chia 2 số nguyên. Hàm fmod() lấy phần dư của phép chia 2 số thập phân. Hàm modf() tách phần nguyên và phần thập phân.
struct book { char name[10]; float price; int page; };
long int l = 2.3;
enum day{Monday, Tuesday, Wednesday};
B User define data type là kiểu dữ liệu (struct, class, enum,..) do người dùng tự định nghĩa từ các kiểu dữ liệu cơ bản
1: extern int x;
2: float func(float x) { … }
3: double pow(double, double);
A. 1
B. 2
C. 3
D. 1 and 3 Đáp án
D
52. Is the following statement a declaration or definition?
extern int i;
A
53. Is there any difference between following declarations?
1: extern int fun( ) ; 2: int fun( );
B Khi bạn cần gọi hàm từ file .c vào file .cpp, bạn cần phải extern function
54. In the following program where is the variable a getting defined and where it is getting declared?
#include <stdio.h> void main() { extern int a; printf("\n a = %d", a); } int a = 20;
A. Extern int a is declaration, int a = 20 is the definition
B. Int a = 20 is declaration, extern int a is the definition
C. Int a = 20 is definition, a is not defined
D. a is declared, a is not defined
A
55. What are the types of linkages?
B
56. Which of the following special symbol allowed in a variable name?
A. * (asterisk)
B. | (pipeline)
C. – (hyphen)
D. _ (underscore)
Đáp án
D
57. By default a real number is treated as a
B
58. How would you round off a value from 1.66 to 2.0?
A Hàm ceil(x) làm tròn số thập phân thành số nguyên nhỏ nhất, lớn hơn hoặc bằng x. Hàm floor(x) làm tròn số thập phân thành số nguyên lớn nhất, nhỏ hơn hoặc bằng x. Hàm roundup() và roundto() không tồn tại trong thư viện ngôn ngữ C/C++
59. Is there any difference in the following declaration?
int func(int arr[]); int func(int arr[20]);
A. Yes
B. No
Câu lệnh int func(int arr[]) chấp nhận đầu vào là mảng nguyên với kích thước bất kì.
Câu lệnh int func(int arr[20]) chấp nhận đầu vào là mảng nguyên với kích thước là 12.
60. A long double can be used if range of a double is not enough to accommodate a real number?
A. True
B. False
B
61. A float is 4 byte wide, whereas a double is 8 byte wide
A. True
B. False
62. Size of short integer and long integer can be verified using the sizeof( ) operator
A. True
B. False
63. If the definition of external variable occurs in the source file before its use in a particular function, then there is no need for an extern declaration in the function
A. True
B. False
64. Global variable are available to all functions. Does there exist a mechanism by way of which it available to some and not to others
A. Yes
B. No
65. Size of short integer and long integer would vary from one platform to another
A. True
B. False
66. 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.
67. 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
68. What will be the ouput of the program?
#include <stdio.h> #include <math.h> #include <conio.h> void main() { float n = 1.34; printf("%f %f",ceil(n), floor(n)); getch(); }
A. 1.000000 2.000000
B. 1.500000 1.000000
C. 2.000000 1.000000
D. 1.300000 2.000000
69. 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
70. 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
Hằng số 3.14 là kiểu double, 3.14L là kiểu long double
Bạn có thể test bằng câu lệnh: sizeof(3.14L) = sizeof(3.14) = 8 (byte) (Visual C++ 2008 x86)
71. What will you do to treat the constant 3.14 as a float?
A. use float(3.14f)
B. use 3.14f
C. use f(3.14)
D. use (f)(3.14)
Bạn có thể test bằng câu lệnh: sizeof(3.14f) = 4 (byte) (Visual C++ 2008 x86)
72. 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)
Round off ở đây có nghĩa là làm tròn số thập phân.
Ví dụ: 3.45 –> 3, 3.5 –> 4.
Do vậy, ở đây để làm tròn x ta cộng thêm 0.5.
Đáp án B cũng có thể đúng, nhưng đáp án A là chuẩn nhất, đảm bảo đúng trên mọi compiler.
73. What will be output of the program?
#include <stdio.h> #include <conio.h> void main() { float n = 1.67; printf("%e, ", n); printf("%f, ", n); printf("%g, ", n); printf("%lf, ", n); getch(); }
A. 1.670000e+000, 1.670000, 1.67, 1.670000,
B. Complier Error
C. 1.67e, 1.67000, 1.670, 1.67
D. 1.67e, 1.67, 1.67000, 1.67f
%e: in ra kiểu số mũ.
%f: in ra kiểu dấu phẩy động
%g: in ra dạng rút gọn của %f hoặc %e
%lf: in ra kiểu dấu phẩy động.
74. What will be output of program?
#include <stdio.h> #include <conio.h> void main() { float n = 0.7; if(n < 0.7f) printf("vncoding"); else printf("abc"); getch(); }
A. vncoding
B. abc
C. Complier error
D. None of these
0.7f là hằng số kiểu float. Biểu thức so sánh 0.7 < 0.7f trả về false.
75. What will be output of program?
#include <stdio.h> #include <conio.h> void main() { float n = 0.7; if(n < 0.7) printf("vncoding"); else printf("abc"); getch(); }
A. vncoding
B. abc
C. Complier error
D. None of these
76. If the file tobe included does not exist, the preprocessor flashes an error message
A. True
B. False
Complier sẽ thông báo lỗi nếu thiếu file #include
77. What is output of the program?
#include <stdio.h> #include <conio.h> void main() { int y = 100; const int x = y; printf("%d", x); getch(); }
A. 100
B. Garbage value
C. Error
D. 0
hằng số x được khởi tạo bằng 100.
78. What will happen if in the C program you assign a value to a array element whose subscript exceeds the size of array?
A. The element will be set to 0.
B. The complier would report an error.
C. The program may crash if some important data gets overwritten
D. The array size would appropriately grow
Khi bạn assign giá trị cho phần tử vượt quá kích thước của mảng. Xảy ra problem là buffer overrun. Có nghĩa là sử dụng vùng nhớ ko hợp lệ (ví dụ: đang lưu giá trị của một biến khác,…), làm cho chương trình bị crash.
79. What is output of the program?
#include <stdio.h> #include <math.h> #include <conio.h> void main() { printf("%f", sqrt(36.0)); getch(); }
A. 6.000000
B. 6
C. Error
80. In which stage the following code
#include <stdio.h>
Gets replaced by the contents of the file stdio.h
A. During editing
B. During linking
C. During execution
D. During preprocessing
81. What will be output of the program?
#include <stdio.h> #include <conio.h> void main() { printf("%d %d %d", sizeof(3.14), sizeof(3.14f), sizeof(3.14l)); getch(); }
A. 8 4 8
B. 4 4 8
C. 4 8 10
D. 4 8 12
3.14 là hằng số kiểu double
3.14f là hằng số kiểu float
3.14l là hằng số kiểu long double
82. A function cannot be defined inside another function
A. True
B. False
Không thể define 1 hàm trong 1 hàm khác, ta chỉ có thể gọi hàm trong 1 hàm khác.
83. What is the notation for following functions?
1. int func(int a, int b) { /*Some code*/ } 2. int func(a, b) int a; int b; { /*Some code*/ }
A. 1. KR Notation and 2. ANSI Notation
B. 1. Pre ANSI C Notation and 2. KR Notation
C. 1. ANSI Notation and 2. KR Notation
D. 1. ANSI Notation and 2. Pre ANSI Notation
84. Name of functions in two different files linked together must be unique.
A. True
B. False
85. If return type for a function is not specified, it defaults to int
A. True
B. False
86. A function may have ant number of return statements each returning different values.
A. True
B. False
Một hàm có thể sử dụng nhiều cầu lệnh return với các giá trị trả về khác nhau
87. Functions cannot return more than one value at a time
A. True
B. False
88. Function can be called either by value or reference
A. True
B. False
89. How many times the program will print “vncoding”?
#include<stdio.h> void main() { printf("vncoding"); main(); }
A. Infinite times
B. 65535 times
C. Till stack overflows
D. Cannot call main( ) in main( )
90. In C all function except main( ) can be called recursively
A. True
B. False
Tất cả các hàm bao gồm cả hàm main đều có thể đệ quy.
91. Is it true that too many recursive calls may result into stack overflow?
A. Yes
B. No
Vì khi hàm được gọi, địa chỉ hàm + giá trị trả về của hàm +… được lưu stack.
92. Maximum number of arguments that a function can take is 12
A. Yes
B. No
Không rõ là bao nhiêu :). Nhờ các bạn check giúp.
93. Usually recursion works slower than loops
A. Yes
B. No
94. In a function two return statements should never occur.
A. Yes
B. No
Trong ngôn ngữ C, có thể sử dụng nhiều câu lệnh return trong 1 hàm. Ngoại trừ, viết 2 câu lệnh return liên tiếp nhau.
95. There is a error in the below program. Which statement will you add to remove it
#include<stdio.h> void main() { int a; a = f(1, 3.14); } float f(int a, float b) { return ((float)a + b); }
A. Add prototype: float f(int, float);
B. Add prototype: float f(a, b);
C. Add prototype: float f(float a, int b)
96. Every function must return a value
A. Yes
B. No
Hàm có kiểu trả về là void thì trong thân hàm không cần gọi lệnh return.
97. Which of the following statements are correct about the program?
#include <stdio.h> #include <conio.h> void main() { printf("%p", main()); getch(); }
A. It prints garbage values infinitely
B. Runs infinitely without printing anything
C. Error: main( ) cannot be called inside printf( )
D. No Error and print nothing
98. Will the following functions work?
int f1(int a, int b) { return(f2(20)); } int f2(int a) { return a*a; }
A. Yes
B. No
Vì hàm f2 được gọi trước khi được define. Nên khai báo hàm f2()
99. If a function contains two return statements successively, the complier will generate warnings. Yes / No?
A. Yes
B. No
Vì gặp lệnh return thứ nhất, kết thúc hàm.
Nếu 1 hàm dùng nhiều câu lệnh return liên tiếp nhau, chỉ có câu lệnh return đầu tiên có ý nghĩa, các câu lệnh sau nó ko bao giờ được thực hiện.
100. Functions can not return a floating point number
A. Yes
B. No
101. What will be the output of the program?
#include <stdio.h> #include <conio.h> int reverse(int); void main() { int n = 5; reverse(n); getch(); } int reverse(int n) { if(n == 0) return 0; else printf("%d", n); reverse(n--); }
A. 543210
B. 54321
C. 12345
D. Infinite loop
Hàm reverse() là hàm đệ quy.
n = 5, câu lệnh gọi hàm reverse(n–) <=> reverse(5) vì biến n giảm sau khi gọi hàm.
Vì giá trị truyền vào cho hàm reverse ko thay đổi. Do vậy, chương trình đệ qui rơi vào vòng lặp vô hạn.
Để fix chương trình này, thay reverse(n–) bằng reverse(–n).
102. What will be the output of the program?
#include <stdio.h> #include <conio.h> void main() { int func(int); int i = func(5); printf("%d", --i); getch(); } int func(int n) { return(n++); }
A. 4
B. 5
C. 6
D. Another
Ngôn ngữ C, cho phép bạn khai báo hàm trong 1 hàm khác.
Hàm func(5) trả về là 5 không phải là 6, vì giá trị n được tăng sau khi thực hiện xong câu lệnh return.
103. 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
Hàm được định nghĩa chưa có kiểu trả về. Một số chương trình biên dịch sẽ không chấp nhận điều này.
104. Point out the error in the program
#include <stdio.h> #include <conio.h> int f(int a) { a > 20 ? return(1) : return(0); } void main() { int f(int); int b = f(20); printf("%d", b); getch(); }
A. Error: Prototype declaration
B. No error
C. Error: return statement cannot be used with conditional operators
D. None of above
Sau toán tử điều kiện (? phải là biểu thức toán học, không thể là câu lệnh (return).
Câu lệnh “a > 20 ? return(1) : return(0);” nên đổi thành “return (a > 20 ? 1 : 0);”
105. 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
k = i + j = 5
l = i*j = 6
Câu lệnh return(k, l) = return(5, 6) = return(6).
106. What will be output of the program?
#include<stdio.h> #include <conio.h> int f1(int); int f2(int); void main() { extern int i; int j = 3; f1(j); printf("%d,", j); f2(j); printf("%d", j); getch(); } int f1(int i) { printf("%d,",++i); return 0; } int f2(int j) { printf("%d,", ++j); return 0; }
A. 4, 3, 4, 3
B. 4, 4, 5, 5
C. 3, 4, 3, 4
D. None of above
107. 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
Hàm fun() tính giai thừa của n.
108. Point out the error in the following program
#include <stdio.h> #include <conio.h> void main() { int a = 10; void f(); a = f(); printf("%d", a); getch(); } void f() { printf("vncoding"); }
A. Error: cannot convert ‘void’ to ‘int’
B. Error:
5 Comments on Khái niệm cơ bản ngôn ngữ lập trình C
Leave a Reply
You must be logged in to post a comment.
Copyright © 2015-2024 | WordPress Theme by MH Themes
Cám ơn anh. Những bài viết rất hay và hữu ích
Thanks
Mong a viết tiếp mục 1000 câu trắc nghiệm C/C++ :))
Cám ơn anh bài viết hay lắm ạ ^^
Câu 12 trong thân vòng for phải có dấu chấm phẩy chứ nhỉ ?