lOMoARcPSD| 58097008
Exercise 1
-
Students need to review all the theory content they have learned.
-
The following are just some sample exercises, which have similar question formats that may be encountered in the test.
-
These exercises do not cover all the knowledge learned.
lOMoARcPSD| 58097008
1. Which of the following variable declarations is correct?
a) int a, b; b) int* a, *b;
c) int a, *b; d) int a, *A;
2. What is the purpose of the following code segment? int
main(){
int i, a=0;
for(i=0; i<10; i++)
a+=i; return 0;
}
3. List at least 4 countable types?
4. List at least 3 uncountable types?
5. What are the values of the two variables x and y after executing
the following code segment:
int x, y;
x=20; y
= x--;
??
a) x= 19 y= 19 b) x =19 y= 20 c) x =20 y = 19 d) x =20 y = 19
6. What is the result of the following expression?
6>2|| !(10>12)&&5>=6
a) 1 b) 0
7. In a C program that uses the statement printf as follows:
printf(“%d %f %c %s %p”, x, y, z, t, w);
What types should the variables x, y, z, t, and w have?
a) x : int, y: float, z : char, t : char *, w : pointer
b) x : char, y: float, z : char, t : char *, w : pointer
c) x : int, y: long, z : char, t : char *, w : pointer
d) x : int, y: long, z : char, t : char, w : pointer
8. How many bytes is the size of the long double type in 64-bit
operating systems?
a) 8 b) 12 c) 16 d) Another answer
9. How many bytes is the size of a pointer type (in a 64-bit
operating system)?
a) 4 b) 8 c) 12 d) Another answer
10. How many types of passing parameters are there for functions?
a) 1 b) 2 c) 3 d) 4
11. What result does the following program display? #include
<stdio.h> int main(){
int d=25/7;
switch(d){
case 0: printf("0");
case 2: printf("2");
case 4: printf("4");
}
return 0;
}
a) 0 b) 2 c) 4 d) shows nothing
12. What result does the following program produce? #include
<stdio.h> int main(){
float x=3.4;
int *p;
p=&x;
printf("%f %d", x, *p);
}
a) 3.4 3.4 b) a) 3.40000 3.40000 c)3.40000 1073741824(address) d) error
13. What is the value displayed on the screen after running the
following program?
#include <stdio.h> int
main(){
int i,j, p=0;
int a[3][3] = {{1, 3, 5}, {7, 9, 11}, {13, 15, 17}};
for(i=0; i<2; i++)
for (j=0; j<3;j++)
p=p+a[i][j];
printf("%d", p);
}
a) 35 b) 36 c) 37 d) 38
14. What is the value range of types char, unsigned char, int?
15. What output does the following program produce, assuming the
user enters a=13?
#include <stdio.h> int
main(){
float a;
printf("a="); scanf("%f", &a);
if(a%2==0) printf("a la so chan");
else printf("a la so le");
return 0;
}
a) a la so chan b) a la so le c) shows nothing d) error
16. What result does the following program display? #include
<stdio.h> int main(){
int i, s=0;
int a[]={1, 2, 3, 4, 5, 6};
for(i=5; i>=0; i--)
s=s-a[i];
printf("%d", s);
return 0;
}
a) -20 b) -21 c) -22 d) -23
17. Which function is used to compare 2 character strings?
18. Which function is used to convert a string of numerical digits into
numbers?
19. Which function is used to move the cursor in a file?
20. What is the result of the following program?
#include <stdio.h>
#include <string.h>
int main(){
char* s, chuoi[255]="van su khoi dau nan" ;
s=strstr(chuoi, "khoi");
puts(s);
}
a) khoi b) khoi dau nan c) van su khoi dau nan d) error
21. What is the result of the following program?
#include <stdio.h>
#include <malloc.h> int
main(){
int s=0, i, j;
for( i=1;i<=3;i++)
for(j=1;j<=4; j++)
s=s+i;
printf("%d", s);
}
a) 21 b)22 c)23 d)24
lOMoARcPSD| 58097008
22. What is the result displayed on the screen of
the following program?
#include <stdio.h>
#include <malloc.h> int
main(){
char *p;
p=(char*)malloc(1);
*p=66;
printf("%c", *p);
}
a) A b) B c)C d) D
23. What is the result displayed on the screen of
the following program?
#include <stdio.h> int
main(){
int a=5, b=10, *pa, *pb;
pa=&a; pb=&b; *pa=a*2;
*pb=b*2; printf(“a=%d
b=%d”, a, b);
return 0;
}
a) a=10 b=10 b) a=20 b=20 c) a=10 b=20 d) a=20 b=10
24. What is the result of the following
program? #include <stdio.h> int tangtri(int
x, int *y){
x++ ;
*y=(*y)+1 ;
} int main(){
int z=2, t=2;
tangtri(z, &t) ;
printf("z=%d t=%d", z, t);
return 0 ;
}
a) z= 2 t= 2 b) z= 2 t= 3 b) z= 3 t= 3 d) tất cả ều sai
25. What is the result of the following
program? #include <stdio.h> int main(){
int i=1, s=0; while(i<5){
i++;
s++;
}
printf("%d", s);
return 0;
}
a) 3 b)4 c)5 d)6
26. What is the result of the following
program? #include <stdio.h> int main(){
int i, j;
for(i=5; i>=1; i--){
for(j=1; j<=i; j++)
printf("%d ", j);
printf("\n");
}
return 0;
}
a) b) c) d)
1 1 1 2 3 4 1 2 3 4 5
1 2 1 2 1 2 3 1 2 3 4
1 2 3 1 2 3 1 2 1 2 3
1 2 3 4 1 2 3 4 1 1 2
1 2 3 4 5 1
27. Given the following declarations:
typedef struct Node {
int data;
struct Node *next;
};
typedef struct Node *position;
position p1,p2; int *p3;
Suppose that the 2 commands below have been executed:
p1=(struct Node*)malloc(sizeof(struct Node)); p2=(struct
Node*)malloc(sizeof(struct Node));
What does the following code segments show? Explain why the error
occurred (if any):
a) p1->data=123; p2->data=456;
p1->next=p2; printf(“%5d%5d”, p1->data,
p1->next->data);
b) p1->data=12; p2->data=34;
p1=p2;
printf(“%5d%5d”, p1->data, p2->data);
c) p1->data=123; p2->data=456;
p1->next=p2; printf(“%5d%5d”, p2->data,
p1->next->data);
28. What is the result of the following
program? #include <stdio.h> int main(){
int a, b, d;
a=37; b=7; d=0;
while (a-b>0){
d++; a=a-
b;
}
printf("%d", d);
return 0;
}
a) 2 b) 3 c)4 d)5
29. What is the result of the following
program? #include <stdio.h> int main(){
int I, N, S;
N=11; I=1; S=0;
do{
S+=I; I++;
if(I==7) break;
}while(I<=N);
printf("%d; %d", N, S);
return 0;
}
a) 12; 22; b)11; 23 c)11; 21 d) 13; 25
30. What is the result of the following
program? #include <stdio.h> int main(){
float x=5.5, y=10; if(x==5.5);
if(x>5.5) x=2*x;
printf("x=%.1f y=%.1f", x, y);
return 0 ;
}
a) x=5.5 y=10.0 b) x=11.0 y= 10.0 c) error d) All are incorrect
lOMoARcPSD| 58097008
31. What is the result of the following program? #include <stdio.h>
int main(){ int i, a[]={2, 4, 6, 8, 10, 12, 14, 16, 18, 20}, N=8;
for(i=0;i<N;i++)
if(i%2==0)a[i]=a[i]*2;
for(i=0;i<N;i++) printf("%d ",
a[i]);
return 0 ;
}
a) 2, 4, 6, 8, 10, 12, 14, 16
b) 2, 8, 6, 16, 10, 24, 14, 32
c) 4, 8, 12, 16, 20, 24, 28, 32
d) 4 4 12 8 20 12 28 16
32. What is the result of the following program?
#include <stdio.h> #include
<string.h> int main(){
char s[20]= "ABCDEFGHIJ"; int i;
for(i=0;i<=strlen(s)/2;i++)
printf("%c", s[i]);
return 0 ;
}
a) ABCD b) ABCDE c) ABCDEF d) ABCDEFG
end

Preview text:

lOMoAR cPSD| 58097008 Exercise 1
- Students need to review all the theory content they have learned.
- The following are just some sample exercises, which have similar question formats that may be encountered in the test.
- These exercises do not cover all the knowledge learned. lOMoAR cPSD| 58097008
1. Which of the following variable declarations is correct? 13.
What is the value displayed on the screen after running the a) int a, b; b) int* a, *b; following program? c) int a, *b; d) int a, *A; #include int main(){ 2.
What is the purpose of the following code segment? int int i,j, p=0; main(){ int i, a=0;
int a[3][3] = {{1, 3, 5}, {7, 9, 11}, {13, 15, 17}}; for(i=0; i<10; i++) for(i=0; i<2; i++) a+=i; return 0; for (j=0; j<3;j++) } p=p+a[i][j]; printf("%d", p); 3.
List at least 4 countable types? } 4.
List at least 3 uncountable types? a) 35 b) 36 c) 37 d) 38 5.
What are the values of the two variables x and y after executing 14.
What is the value range of types char, unsigned char, int? the following code segment: 15.
What output does the following program produce, assuming the int x, y; user enters a=13? x=20; y #include int = x--; main(){ ?? float a;
a) x= 19 y= 19 b) x =19 y= 20 c) x =20 y = 19 d) x =20 y = 19
printf("a="); scanf("%f", &a); 6.
What is the result of the following expression?
if(a%2==0) printf("a la so chan");
6>2|| !(10>12)&&5>=6 else printf("a la so le"); a) 1 b) 0 return 0; } 7.
In a C program that uses the statement printf as follows:
a) a la so chan b) a la so le c) shows nothing d) error
printf(“%d %f %c %s %p”, x, y, z, t, w);
What types should the variables x, y, z, t, and w have? 16.
What result does the following program display? #include
a) x : int, y: float, z : char, t : char *, w : pointer int main(){
b) x : char, y: float, z : char, t : char *, w : pointer int i, s=0; int a[]={1, 2, 3, 4, 5, 6};
c) x : int, y: long, z : char, t : char *, w : pointer for(i=5; i>=0; i--)
d) x : int, y: long, z : char, t : char, w : pointer s=s-a[i]; 8.
How many bytes is the size of the long double type in 64-bit printf("%d", s); operating systems? return 0;
a) 8 b) 12 c) 16 d) Another answer } 9.
How many bytes is the size of a pointer type (in a 64-bit a) -20 b) -21 c) -22 d) -23 operating system)? 17.
Which function is used to compare 2 character strings?
a) 4 b) 8 c) 12 d) Another answer 18.
Which function is used to convert a string of numerical digits into 10.
How many types of passing parameters are there for functions? n u mbers? a) 1 b) 2 c) 3 d) 4 19.
Which function is used to move the cursor in a file? 11.
What result does the following program display? #include int main(){ 20.
What is the result of the following program? int d=25/7; #include switch(d){ #include case 0: printf("0"); int main(){ case 2: printf("2");
char* s, chuoi[255]="van su khoi dau nan" ; case 4: printf("4"); s=strstr(chuoi, "khoi"); } puts(s); return 0; } }
a) khoi b) khoi dau nan c) van su khoi dau nan d) error
a) 0 b) 2 c) 4 d) shows nothing
21. What is the result of the following program? 12.
What result does the following program produce? #include #include int main(){ #include int float x=3.4; main(){ int s=0, i, j; int *p; for( i=1;i<=3;i++) p=&x; for(j=1;j<=4; j++) printf("%f %d", x, *p); s=s+i; } printf("%d", s);
a) 3.4 3.4 b) a) 3.40000 3.40000 c)3.40000 1073741824(address) d) error } a) 21 b)22 c)23 d)24 lOMoAR cPSD| 58097008
27. Given the following declarations: typedef struct Node { int data;
22. What is the result displayed on the screen of struct Node *next; the following program? }; #include
typedef struct Node *position; #include int position p1,p2; int *p3; main(){ char *p;
Suppose that the 2 commands below have been executed: p=(char*)malloc(1);
p1=(struct Node*)malloc(sizeof(struct Node)); p2=(struct *p=66;
Node*)malloc(sizeof(struct Node)); printf("%c", *p); }
What does the following code segments show? Explain why the error a) A b) B c)C d) D occurred (if any):
23. What is the result displayed on the screen of a)
p1->data=123; p2->data=456; the following program?
p1->next=p2; printf(“%5d%5d”, p1->data, #include int p1->next->data); main(){ int a=5, b=10, *pa, *pb; b)
p1->data=12; p2->data=34;
pa=&a; pb=&b; *pa=a*2; p1=p2; *pb=b*2; printf(“a=%d
printf(“%5d%5d”, p1->data, p2->data); b=%d”, a, b); c)
p1->data=123; p2->data=456; return 0;
p1->next=p2; printf(“%5d%5d”, p2->data, } p1->next->data);
a) a=10 b=10 b) a=20 b=20 c) a=10 b=20 d) a=20 b=10
24. What is the result of the following
28. What is the result of the following
program? #include int tangtri(int program? #include int main(){ x, int *y){ int a, b, d; x++ ; a=37; b=7; d=0; *y=(*y)+1 ; while (a-b>0){ } int main(){ d++; a=a- int z=2, t=2; b; tangtri(z, &t) ; } printf("z=%d t=%d", z, t); printf("%d", d); return 0 ; return 0; } }
a) z= 2 t= 2 b) z= 2 t= 3 b) z= 3 t= 3 d) tất cả ều sai a) 2 b) 3 c)4 d)5
25. What is the result of the following
29. What is the result of the following program? #include int main(){ program? #include int main(){ int i=1, s=0; while(i<5){ int I, N, S; i++; N=11; I=1; S=0; s++; do{ } S+=I; I++; printf("%d", s); if(I==7) break; return 0; }while(I<=N); } printf("%d; %d", N, S); a) 3 b)4 c)5 d)6 return 0; }
26. What is the result of the following
a) 12; 22; b)11; 23 c)11; 21 d) 13; 25 program? #include int main(){ int i, j;
30. What is the result of the following for(i=5; i>=1; i--){ program? #include int main(){ for(j=1; j<=i; j++)
float x=5.5, y=10; if(x==5.5); if(x>5.5) x=2*x; printf("%d ", j);
printf("x=%.1f y=%.1f", x, y); printf("\n"); return 0 ; } } return 0; }
a) x=5.5 y=10.0 b) x=11.0 y= 10.0 c) error d) All are incorrect a) b) c) d) 1 1 1 2 3 4 1 2 3 4 5 1 2 1 2 1 2 3 1 2 3 4 1 2 3 1 2 3 1 2 1 2 3 1 2 3 4 1 2 3 4 1 1 2 1 2 3 4 5 1 lOMoAR cPSD| 58097008
31. What is the result of the following program? #include
int main(){ int i, a[]={2, 4, 6, 8, 10, 12, 14, 16, 18, 20}, N=8;
for(i=0;i if(i%2==0)a[i]=a[i]*2; for(i=0;ia[i]); return 0 ; } a) 2, 4, 6, 8, 10, 12, 14, 16
b) 2, 8, 6, 16, 10, 24, 14, 32
c) 4, 8, 12, 16, 20, 24, 28, 32 d) 4 4 12 8 20 12 28 16
32. What is the result of the following program? #include #include int main(){
char s[20]= "ABCDEFGHIJ"; int i;
for(i=0;i<=strlen(s)/2;i++) printf("%c", s[i]); return 0 ; }
a) ABCD b) ABCDE c) ABCDEF d) ABCDEFG end