WorksheetsPRf192
Total questions: 80
Worksheet time: 40mins
Name
Class
Date
1.
Which code line is incorrect?
a)
A. putchar('a');
b)
B. putchar(65);
c)
C. None of the others
2.
What will print when the sample code below is executed?
int main(){
int a = 3, b,c;
b = a = 10;
c = a < 10;
printf("a = %d, b = %d, c = %d", a,b,c);
return 0;
}
a)
A. a=10, b=10, c=0
b)
B. a=10, b=10, c=10
c)
C. a=3, b= 10, c=10
d)
D. a=10, b=0, c=0
3.
Which of the following statements is correct regarding the Von Neumann architecture?
a)
A. It refers to "fixed-program computers"
b)
B. It refers to "stored-program computers"
c)
C. It takes a lot of time and effort to reconfigure the computer to perform a new task
d)
D. It separates the storage and treatment of CPU instructions and data
4.
Which is the INCORRECT statement?
a)
A. Input to a program may be unbuffered or buffered.
b)
B. In the buffered input, the program can respond to each and every keystroke directly.
c)
C. Buffered input enables data editing before submission to a program.
d)
D. A buffer is a region of memory that collects and holds data temporarily.
5.
Which function is not used to read from a file?
a)
A. fprintf
b)
B. fgetc
c)
C. fgets
d)
D. fscanf
6.
What is the correct definition of an array?
a)
A. An array is a collection of different data types spread throughout the memory
b)
B. An array is a collection of the same data type spread throughout the memory
c)
C. An array is the collection of the same data type located next to each other in the memory
d)
D. An array is the collection of different data types located next to each other in the memory
7.
A string is a ... array of characters terminated by a null('\0').
a)
A. one-dimensional
b)
B. two-dimensional
c)
C. non-dimensional
d)
D. None of the others
8.
What is the output when the sample code below is executed?
int x = 1000;
while (x++ < 1003)
printf("%d ", x);
printf("%d\n",x);
a)
A. 1000 1001 1002 1003
b)
B. 1001 1002 1003
c)
C. 1000 1001 1002
d)
D. 1001 1002 1003 1004
9.
What is the correct statement about the following code?
int main(){
float *p;
*p=30;
return(0);
}
a)
A. Error at compiling time
b)
B. Run successful
c)
C. Error at run time, because pointer variable p has not be allocated memory yet.
10.
Can I use code like this?
((condition) ? a : b) = some_expression;
a)
A. Yes
b)
B. No
11.
The address operator is shown using the ____ symbol.
a)
A. *
b)
B. #
c)
C. &
d)
D. @
12.
What is the recommended format to define a magic value in C?
a)
A. #define PI = 3.14159;
b)
B. #define PI 3.14159
c)
C. #define PI = 3.14159
d)
D. const PI = 3.14159
13.
What is the output when the sample code below is executed?
void inc(int* a) {
for(int i = 0;i<5;i++)
(*a)++;
}
int main() {
int x = 1;
inc(&x);
printf("%d", x);
}
a)
A. 1
b)
B. 4
c)
C. 5
d)
D. 6
14.
What is the output when the sample code below is executed?
int inc(int i) { return (i++); }
int main(){
int i= inc(10);
printf("%d\n", --i);
return(0);
}
a)
A. 9
b)
B. 10
c)
C. 11
d)
D. Compile error
15.
What is the output when the sample code below is executed?
int a = 0, b = 0, c = 0;
if (a > 0)
if (b > 0) c = 1;
else c = 2;
a++;
b-=1;
printf("%d %d %d\n",a,b,c);
a)
A. 1 -1 0
b)
B. 0 -1 0
c)
C. 0 -1 2
d)
D. 1 0 2
16.
Which statement is correct?
a)
A. The higher the level of programming language, the closer to the human languages from native machine languages
b)
B. The higher the level of programming language, the closer to the native machine language
c)
C. The higher the level of programming language, the further to the human languages
d)
D. None of the others
17.
What is the output when the sample code below is executed?
char s[10] = "hi";
printf("%d", strcmp(strcat(s, " there"), "hello"));
a)
A. A positive number
b)
B. A negative number
c)
C. Zero
d)
D. None of the other choices
18.
What will be the output of the following code fragment?
#include
#include
int main()
{
char str1[] = "bca";
char str2[] = "bcd";
printf("%d", strcmp(str1, str2));
}
a)
A. 0
b)
B. A positive integer
c)
C. A negative integer
d)
D. Nothing (no output)
19.
What is the output when the sample code below is executed?
char f[]="morning";
int i=0;
while(f[i] != 'n') {
printf("%c%c", f[i], *(f + i+ 1));
i++;
}
a)
A. mmoorrnm
b)
B. mmoorrn
c)
C. moorrn
d)
D. mmoorr
e)
E. morning
20.
What is the output of the following code?
printf ("%d", strcmp("Hello", "hello"));
a)
A. 0
b)
B. 1
c)
C. -1
d)
D. Error, we can not compare like that.
21.
An array declared as:
int code[100];
The first element of the array is:
a)
A. code
b)
B. code[0]
c)
C. code[1]
d)
D. None of the others
22.
What is the correct statement?
a)
A. scan returns the number of addresses successfully filled or EOF
b)
B. scan returns the number of addresses successfully filled only.
c)
C. scan returns nothing, that is the void function.
23.
What is the correct statements?
a)
A. The operator * reads as 'the data at address'.
b)
B. The operator * reads the address of the variable.
c)
C. The * operator is a unary operator and it returns the memory address of the operand
24.
What is the output when the sample code below is executed?
main()
{
int x = 0;
while(x <= 10)
for(;1;)
if(++x%10 == 0) break;
printf("%d\n", x);
}
a)
A. 10
b)
B. 11
c)
C. 20
d)
D. 21
e)
E. Error
25.
The built-in functions printf & scanf are present within the ..... file.
a)
A. stdlib.h
b)
B. conio.h
c)
C. stdio.h
26.
What number is equivalent to - 4e^3 written in exponential notation?
a)
A. -4000
b)
B. -400
c)
C. -40
d)
D. .004
e)
E. .0004
27.
What is the output when the sample code below is executed?
int x=100;
for(int i=0;i<5;i++)
for(int j=0;j<10;j++)
{
x--;
}
printf("%d",x);
a)
A. 50
b)
B. 100
c)
C. 85
d)
D. 0
e)
E. A
28.
Is the following code legal?
int a, b = 0;
a-b=6;
a)
A. Yes
b)
B. No
29.
Double data type takes .... bits
a)
A. 16
b)
B. 32
c)
C. 128
d)
D. 64
30.
Which of the following header files contains function prototypes isdigit(int), isspace(int) ?
a)
A. stdio.h
b)
B. stdlib.h
c)
C. conio.h
d)
D. ctype.h
31.
What is the output of the following code?
void func1(int (*a)[10]){
printf("Good, It works");
}
void func2(int a[][10]){
printf("What will happen?");
}
int main(){
int a[10][10];
func1(a);
func2(a);
return 0;
}
a)
A. Good, It works
b)
B. What will happen?
c)
C. Good, It worksWhat will happen?
d)
D. None of the other choices
32.
What is the output when the sample code below is executed?
int sum = 0;
for(int i=1; i<=5; i++){
if(i==3)
continue;
sum += i;
}
printf("%d", sum);
a)
A. 15
b)
B. 12
c)
C. 6
d)
D. 3
33.
What will be the output of the following program?
#include
#include
#include
void main(){
char str[] = "abcd";
int len = strlen(str);
for(int i=0;i < len; i++){
if(i%2 == 0)
str[i] = toupper(str[i]);
}
printf("%s", str);
return 0;
}
a)
A. abcd
b)
B. AbCd
c)
C. aBcD
d)
D. ABCD
34.
What will happen with the following code?
char str[] = "You are right.";
str = "No, you are wrong.";
printf("%s",str);
a)
A. print out to the screen the line "No, you are wrong."
b)
B. print out to the screen the line "You are right."
c)
C. Error at compiling time. Strings are special arrays, that you cannot assign values to them
d)
D. Error at run time.
35.
We store data in a file in either of two formats: binary format or text
a)
A. True
b)
B. False
36.
What is the output when the sample code below is executed?
int i, a[10] = {1, 1, 2, 3}, sum = 0;
for (i = 2; i < 10; i++)
sum += a[i] a[i-2] a[i-1];
printf("%d", sum);
a)
A. 8
b)
B. An arbitrary value
c)
C. 17
d)
D. 14
37.
Which of the following statements prints % character?
a)
A. printf("%%");
b)
B. printf("\%%")
c)
C. printf("\\%");
d)
D. printf("\%")
38.
What is the output when the sample code below is executed?
int x=100, *p,y=0;
p=&x;
*р=200;
p=&y;
*p=x;
printf("%d %d %d ",x,*p,y);
a)
A. 200 200 200
b)
B. 200 200 100
c)
C. 100 100 100
d)
D. 100 200 200
e)
E. 100 100 200
39.
What is the output when the sample code below is executed?
int j= 11;
do {
j = j+1;
printf("%d ", j);
}
while(j<=10);
a)
A. No output
b)
B. 10
c)
C. 12
d)
D. 11
e)
E. 1 2 3 4 5 6 7 8 9 10
40.
Which one of the followings is not in the C standard library?
a)
A. time.h
b)
B. system.h
c)
C. math.h
d)
D. stdlib.h
41.
Which function is NOT Built-in functions in C?
a)
A. tolower()
b)
B. sqr()
c)
C. floor()
d)
D. exit()
42.
What is the output of the following code?
int a;
for(a = 1; a <= 1; a++) printf("%d",a++);
printf("%d",a);
a)
A. 11
b)
B. 22
c)
C. 13
d)
D. 12
43.
What is the output when the sample code below is executed?
#include
int add (int i, int j){
int sum;
sum = i + j;
return sum;
}
int main(){
int a = 5, b = 2, c;
c = add(a, b);
printf ("%d", c);
return 0;
}
a)
A. 2
b)
B. 5
c)
C. 7
d)
D. 1
44.
Which is file access mode that always writes data to the end of file?
a)
A. г
b)
B. a
c)
C. w+
d)
D. w
45.
The data type _____ is used to store single character.
a)
A. number
b)
B. char
c)
C. character
d)
D. int
e)
E. string
46.
What is the output when the sample code below is executed?
char a = '1';
switch(a){
case 0:printf("Orange ");
case 1:printf("Banana ");
case 2:printf("Apple ");
default:printf("Mango ");
}
a)
A. Apple
b)
B. Banana
c)
C. Mango
d)
D. Apple Mango
e)
E. Banana Apple Mango
47.
Output of the following code is correct or not?
for (slices = 4; slices >= 0; --slices){
printf ("Gulp! Slices left %d\n", slices - 1);
}
Output:
Gulp! Slices left 3
Gulp! Slices left 2
Gulp! Slices left 1
Gulp! Slices left 0
a)
A. Wrong
b)
B. Correct
48.
Which library you need to include into your program in order to use printf function?
a)
A. studio.c
b)
B. stdio.c
c)
C. stdio.h
d)
D. studio.h
49.
What will be the output of the following program?
#include
int main(void){
int ref[] = {1, 2, 4};
int *ptr;
int index;
for (index = 0, ptr = ref; index < 3; index++, ptr++)
printf("%d %d", ref[index], *ptr);
return 0;
}
a)
A. 1 2 4 1 2 4
b)
B. 1 4 2 2 4 1
c)
C. 1 4 4 2 2 1
d)
D. 1 1 2 2 4 4
50.
What is not valid in C?
a)
A. class aClass{public:intx;};
b)
B. / A comment /
c)
C. char x = 12;
d)
D. int d = 10;
51.
Referring to the sample code below, what value will the variable counter have when completed?
int x = 3, counter = 0;
while(x-1){
++counter;
x--;
}
a)
A. 0
b)
B. 1
c)
C. 2
d)
D. 3
e)
E. 4
52.
What will be the output of the following code fragment?
double x = -3.5, y = 3.5;
printf("%.0f : %.0f\n", ceil(x), ceil(y));
printf("%.0f : %.0f\n", floor(x), floor(y));
a)
A. -3 : 4 -4 : 3
b)
B. -4 : 4 -3 : 3
c)
C. -4 : 3 -4 : 3
d)
D. -4 : 3 -3 : 4
53.
How is the integer pointer var declared in C?
a)
A. pointer *var;
b)
B. int pointer var;
c)
C. int *var;
d)
D. int pointer *var;
54.
Declaring a variable means:
a)
A. Some memory is allocated.
b)
B. A value is stored in the allocated memory.
c)
C. Memory is not allocated.
d)
D. Memory is allocated and that portion of memory is referred by value.
55.
Why hexadecimal and octal representations are used for sets of bits?
a)
A. Because they are larger than bit unit.
b)
B. Because modern computers process and store information in hexadecimal and octal digits.
c)
C. Because these representations are considerably shorter and more convenient.
56.
What is the output when the sample code below is executed?
#include
int fn(int v){
if(v%2==0)
return(v/2);
else
return(v%2);
}
int main(){
printf("%d\n",fn(5));
return(0);
}
a)
A. 5
b)
B. 1
c)
C. 0
d)
D. 2
57.
Consider the code:
int x[] = {1, 2, 3, 4, 5};
int u;
int *ptr = x;
????
for(u = 0; u < 5; u++){
printf("%d-", x[u]);
}
printf("\n");
Which one of the following statements could replace the ???? in the code above to cause the string 1-2-3-10-5- to be printed when the code is executed?
a)
A. *ptr + 3 = 10;
b)
B. *ptr[3] = 10;
c)
C. *(ptr + 3) = 10;
d)
D. (*ptr)[3] = 10;
e)
E. *(ptr[3]) = 10;
58.
Consider the statement:
int a[8] = {0, 1, 2, 3, 5};
What is the value of a[4]?
a)
A. Arbitrary value
b)
B. 0
c)
C. NULL
d)
D. 5
59.
What is the output when the sample code below is executed?
main(){
int a[5] = {1, 2, 3, 4, 5};
int i, sum = 0;
for (i = 0; i < 5; i++) {
if (i==2)
break;
sum += a[i];
}
printf("%d", sum);
}
a)
A. 3
b)
B. 15
c)
C. 12
d)
D. 1
60.
What is the output when the sample code below is executed?
void foo(int *z){
return(m+2);
}
int main(){
int a=45, *b, m = 10;
b=foo(&a);
printf("\n%d %b", a, b);
return 0;
}
a)
A. 45 12
b)
B. 45 10
c)
C. 10 45
d)
D. compile error
e)
E. 12 12
61.
Which function is NOT used to write data to a file?
a)
A. fprintf
b)
B. fputc
c)
C. fputs
d)
D. fscanf
62.
Which statement of the following code result in an error if a and b are declared as integer variables and p as a pointer variable pointing to an integer and the value of a = 220.
a)
A. p = &a;
b)
B. b = *p;
c)
C. b = p + a++;
d)
D. a = b;
63.
Why the following code is wrong?
int choice = 0, a = 0, b = 1, c = 2;
switch(choice){
case a:
printf("case A happens!");
break;
case b:
printf("Wow, that is B!");
break;
case c:
printf("C please!");
break;
}
a)
A. Lack of default at the end of switch block
b)
B. Can not assign value of choice, a, b, and c at the declaration time
c)
C. The value after the "case" keyword must be the constant
d)
D. The above code is correct.
64.
Which function prototype is declared correctly to pass an array of string to function?
a)
A. void foo(char name[][31], int a);
b)
B. void foo(char name[][], int a);
c)
C. void foo(char name[5][], int a);
65.
What is not the primitive data types in C?
a)
A. int
b)
B. float
c)
C. double
d)
D. class
66.
What is the output when the sample code below is executed?
int count=10, *temp, sum=0;
temp=&count;
*temp=20;
temp=∑
*temp=count;
printf("%d %d %d ", count, *temp, sum);
a)
A. 10 20 20
b)
B. 20 20 20
c)
C. 10 10 10
d)
D. 20 20 10
67.
What is the role of the assembler?
a)
A. It converts assembly language instructions and data into equivalent machine language instructions and data
b)
B. It converts high level language instructions and data into equivalent machine language instructions and data
c)
C. It converts high level language instructions and data into equivalent assembly language instructions and data
d)
D. None of the above
68.
The output of the code below will be changed if we replace while(i++<10) with while(++i<10) ?
int i = 0;
while(i++<10) printf("%d",i);
a)
A. Yes, the initial loop (while(i++<10)) will be executed 10 times and the new loop (while(++i<10)) will be executed 9 times.
b)
B. Yes, the initial loop (while(i++<10)) will be executed 9 times and the new loop (while(++i<10)) will be executed 10 times.
c)
C. No
69.
The following code is an infinite loop?
int number=1;
while(1){
printf("%d ",number);
if(number == 3) break;
number += 2;
}
a)
A. True
b)
B. False
70.
For which value(s) of the integer x will the following code become a finite loop?
int number=1;
while (1){
printf("%d ",number);
if (number == 3) break;
number += x;
}
a)
A. 0
b)
B. 3
c)
C. 4
d)
D. 1 or 2
71.
What is the proper declaration for the variable c in the code below?
c = getchar();
a)
A. char *c;
b)
B. char c;
c)
C. char c[];
d)
D. float c;
72.
If int num[15] is an one-dimensional array of integers, which of the following refers to the value 12th element in the array?
a)
A. *(num + 11)
b)
B. *(num + 12)
c)
C. num + 12
d)
D. num + 11
73.
Given the program:
#include
#include
int myFunction(int);
int main(){
int i = 0;
i = myFunction(i);
printf("%d",i);
getch();
return 0;
}
int myFunction(int x){
return 2;
}
What is printed?
a)
A. Compile error
b)
B. 2
c)
C. 0
74.
Given the below code:
char ch;
scanf("%c", &ch);
printf("%c", ch);
A user enters "abcd" from the console
What is printed?
a)
A. Blank(nothing output)
b)
B. a
c)
C. abcd
d)
D. Compile error
75.
What will be the output of the following program?
#include
#include
int main(){
char ch = 'B';
if(islower(ch+ 1))
putchar(toupper(ch+ 1));
else
putchar(tolower(ch-1));
return 0;
a)
A. B
b)
B. c
c)
C. A
d)
D. a
76.
Given the code below:
int a=2;
printf("%d", ++a, a+5);
What is printed?
a)
A. 2
b)
B. 3
c)
C. undefined
d)
D. error
77.
What is the output when the sample code below is executed?
int i=0, j=0;
for(i=1; i<10, j<3; i *= 2) {
printf("%d ", j++);
}
printf(" %d %d", i, j);
a)
A. 0 1 2 3 8 4
b)
B. 0 1 2 3 9 4
c)
C. 0 1 2 8 3
d)
D. 0 1 2 3 18 4
78.
Consider the following code:
int z,x=5,y=-10,a=3,b=2;
z = ++x + y * b / a;
What number will z in the sample code above contain?
a)
A. 1
b)
B. -1
c)
C. 0
d)
D. 12
79.
Which is NOT a valid function for reading from a file?
a)
A. fgetchar()
b)
B. fscanf()
c)
C. fgetc()
d)
D. fgets()
80.
Which is NOT a valid data type in C language?
a)
A. float
b)
В. double
c)
C. string
d)
D. int
100 %
