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:
Which of the following functions compares two strings?
A. compare();
B. stringcompare();
C. cmp();
D. strcmp();
-
Câu 2:
Which of the following adds one string to the end of another?
A. append();
B. stringadd();
C. strcat();
D. stradd();
-
Câu 3:
In which standard library file is the function printf( ) located?
A. stdio.h
B. conio.h
C. stdlib.h
D. ouput.h
-
Câu 4:
Which function is used to read the input from console?
A. scanf( )
B. printf( )
C. getch( )
-
Câu 5:
Which of the following are NOT relational operator?
A. >
B. >
C. <=
D. None above
-
Câu 6:
In the C program, the first statement that will be executed?
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
-
Câu 7:
Why are a function phototypes useful?
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
-
Câu 8:
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 9:
Which of the following is not user define data type?
1.
struct book { char name[10]; float price; int page; };
2.
long int l = 2.3;
3.
enum day{Monday, Tuesday, Wednesday};
A. 1
B. 2
C. 3
D. 1 & 2 & 3
-
Câu 10:
Identify which of the following are declarations
extern int x; float func(float x) { … } double pow(double, double);
A. 1
B. 2
C. 3
D. 1 and 3
-
Câu 11:
Is the following statement a declaration or definition?
extern int i;
A. Declaration
B. Definition
C. A & B
-
Câu 12:
Is there any difference between following declarations?
extern int fun( ) ; int fun( );
A. Both are identical
B. No difference, except extern int fun( ); is probably in another file
C. int fun( ); is overrided with extern int fun( );
D. None of these
-
Câu 13:
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
-
Câu 14:
What are the types of linkages?
A. Internal and External
B. External, Internal and None
C. External and None
D. Internal
-
Câu 15:
Which of the following special symbol allowed in a variable name?
A. * (asterisk)
B. | (pipeline)
C. – (hyphen)
D. _ (underscore)
-
Câu 16:
By default a real number is treated as a
A. float
B. double
C. long double
D. far double
-
Câu 17:
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 18:
Is there any difference in the following declaration?
int func(int arr[]); int func(int arr[20]);
A. Yes
B. No
-
Câu 19:
A long double can be used if range of a double is not enough to accommodate a real number?
A. True
B. False
-
Câu 20:
A float is 4 byte wide, whereas a double is 8 byte wide
A. True
B. False
-
Câu 21:
Size of short integer and long integer can be verified using the sizeof( ) operator
A. True
B. False
-
Câu 22:
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
-
Câu 23:
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
-
Câu 24:
Size of short integer and long integer would vary from one platform to another
A. True
B. False
-
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 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 27:
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
-
Câu 28:
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 29:
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 30:
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)
-
Câu 31:
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 32:
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
-
Câu 33:
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 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:
If the file tobe included does not exist, the preprocessor flashes an error message
A. True
B. False
-
Câu 36:
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
-
Câu 37:
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
-
Câu 38:
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
-
Câu 39:
In which stage the following code. Gets replaced by the contents of the file stdio.h
#include <stdio.h>
A. During editing
B. During linking
C. During execution
D. During preprocessing
-
Câu 40:
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
-
Câu 41:
A function cannot be defined inside another function
A. True
B. False
-
Câu 42:
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
-
Câu 43:
Name of functions in two different files linked together must be unique.
A. True
B. False
-
Câu 44:
If return type for a function is not specified, it defaults to int
A. True
B. False
-
Câu 45:
A function may have ant number of return statements each returning different values.
A. True
B. False
-
Câu 46:
Functions cannot return more than one value at a time
A. True
B. False
-
Câu 47:
Function can be called either by value or reference
A. True
B. False
-
Câu 48:
How many times the program will print “laptrinhc++”?
#include<stdio.h> void main() { printf("laptrinhc++"); main(); }
A. Infinite times
B. 65535 times
C. Till stack overflows
D. Cannot call main( ) in main( )
-
Câu 49:
In C all function except main( ) can be called recursively
A. True
B. False
-
Câu 50:
Is it true that too many recursive calls may result into stack overflow?
A. Yes
B. No