Ôn tập 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

Ôn tập 1

1) What is the size of an int data type?


A. 4 Bytes
B. 8 bytes
C. Depends on the system/compiler
D. Cannot be determined
2) Output of this program

A.The compiler will flag an error


B.Program will compile and print the output 5 for 5 times
C.Program will compile and print the ASCII value of 5
D.Program will compile and print FAIL for 5 times
3) Output of this program

A. Hello World! X
B. Hello World! followed by a junk value
C. Compile time error
D. Hello World! 1
4) Which function reads characters from the keyboard right after typing, without waiting to press
Enter.
A. scanf ();
B. getchar (); có hiện mh, có enter
C. getche (); có hiện mh, ko cần enter
D. getch (); ko , ko

5) Different between getchar() and getch()


a) getchar() read every key stroke and save it to buffer
b) getch() read every key stroke and display it on screen except enter
c) getchar() read a single character from the standard input stream stdin
d) getch() read a single character and display it on screen
anwser: C

6) Which of the following functions can be used to enter an integer in C program

a) getchar

b) getch

c) scanf

d) None of the others

7) Given S is a string variable. Choose a statement that will cause an error?

a. S = getchar(); báo error


b. gets(S); đúng
c. scanf(“%”,S); ko báo error
d. S[0] = getchar(); đúng

8) What guideline should be examined before working with a text file? Choose one answer.
(1): Data format in the file must be known or designed
(2): Number of values in the file must be known
(3): Last date modified of the file must be known
A. (3)
B. (1)
C. (2)
D. Both (1), (2), (3)
9) Which of the following is true for variable names in C? [a..z][A..Z][0..9]_
A. They can contain alphanumeric characters as well as special characters
B. It is not an error to declare a variable to be one of the keywords
C. Variable names cannot start with a digit
D. Variable can be of any length
10) (1): 1 byte consists of 4 nibbles. (2): One nibble consists of 2 consecutive.
1 byte consists of 2 nibbles. Each nibble represents 4 bits. So, in total, a byte contains 8 bits.
The statement (1) is ...., (2) is....
A. true, true
B. true, false
C. false, false
D. false, true
11) Output of this program

++a = 4
a++ = 5
--a = 4
A. Value of x is 12
B. Value of x is 13
C. Value of x is 10
D. Undefined behaviour

Answer: 13

12) Which of the following is not an arithmetic operation?


A. a *= 10;
B. a /= 10;
C. a != 10;
D. None of them

Answer: C
13) Output of this program

// == : ki hieu so sánh nên d = a = 1(true)


A. Syntax error
B. 1
C. 5
D. 10

Answer: B

14) Which of the following is an invalid assignment operator?


A. a %= 10;
B. a |= 10;
C. a /= 10;
D. None of the mentioned

Answer: B

15) Which of the following is NOT possible with any 2 operators in C?


A. Different precedence, same associativity (True) precedence : độ ưu tiên
B. Different precedence, different associativity (True) assciativity tính kết hợp
C. Same precedence, same associativity (True)
D. Same precedence, different associativity (False)

16) int arr[] ={5,2,0,6};


printf(“%d”, *arr);
*arr: chỉ tới giá trị đầu tiên trong mảng
A. 5
B. 1002032
C. NULL
D. Error
Answer: (A)

15. What is the output when the sample code below is executed?

char mess[] = "abc";


char* p;
p = mess + strlen(mess);
while(p > mess)
printf("%s", --p);

a) abcd
b) error
c) cbcabc
d) abcabc

16. What is the output when the sample code below is executed?

char mess[] = "hello";


char* p;
p = mess + 2;
while(p > mess)
printf("%s", --p);

return 0;

a. Hello
b. llo
c. lloellohello
d. ellohello

16.

#include <stdio.h>

int main() {
float x = 'a';
printf("%f", x);
return 0;
}

a) a

b) run time error

c) a.0000000

d) 97.000000

17. Hàm nào sau đây nhận giá trị từ bàn phím

a) getch(), getchar(), scanf()

b) getchar(), scanf()

c) kbhit(), getch(), scanf(), getchar() kbhit() xác định xem một phím đã được nhấn hay chưa

d) Tất cả đều sai

anwser: c

18. Why hexdecimal and octal representations are used for sets of bits?

a) Because these representations are considerably shorter and more convenient

b) Because they are larger than bit unit

c) Because modern computers process and store information in hexadecimal and octal digits

answer A

19. Which is NOT a valid data type in C language?

a) int

b) float

c) string

d) double

20. What is required to avoid falling through from one case to the next in the switch case?
a) end;

b) break;

c) ;

d) stop;

22. What is the error of this code

#include <stdio.h>

void num(int a, int b){


int sum;
sum = a + b;
sum = sum / 10;
return sum;
}

int main(){

int a, b, result;
a = 10;
b= 12;

result = num(a, b);


printf("%d", result);
return 0;
}

a) 2

b) Function should return a value

c) ld returned 1 exit status

d) 'function' cannot return a value

anwser: d

23. What is “w+" mode can do

a) read file (return null if file not exist)

b) read and write file (If the file does not exist, it will be created automatically)

c) write file

d) If the file already exists, the content will be overwritten. If not, return NULL and exit function.

anwser: b
17) a=1;
b=7;
if(a||b++)
b++;
printf(“%d”,b);

a = 1 tương đương với kết quả true => if(đúng hoặc b = 8)

A. 7
B. 1
C. 8
D. 9

25. What is the output of this function ?

#include <stdio.h>

int main(){

int a;

a = 2;

while (a)

printf("a = %d\n", a);

return 0;

a) a = 2

b) compile error

c) infinity loop

d) program exit

anwser: c

You might also like