PRF192
PRF192
A. int 1student_ID;
B. int _Student_ID1;
C. int Age$;
D. int long;
4.Choose the correct statement for declaring a pointer variable to an integer variable.
A. int *p;
B. int p
C. int +p.
D. int Sp
6.What commands are used to write data appended to the end of the file?
A. FILE *f fwrite("output.txt", "a");
B. FILE *f = fopen("output.txt", "a");
C. FILE *f= fopen("output.txt", "a+");
D. FILE *f = fopen("output.txt", "w+");
E. FILE *f = fopen("output.txt", "w");
7.Which of the following statements has a different result from the other statements?
A. char c1 = 'B', printf("%c",c1);
B. char c2=066; printf("%c",c2),
C. char c3=0x42; printf("%c", c3);
D. char c4 = 0102, printf("%c",c4);
8.What is the purpose of the fscanf() function in the C programming language?
A. Read data from the file.
B. Print to the screen.
C. Read data from the keyboard.
D. Open a file.
E. se a file.
F. Print to file.
9.How does compilation differ from interpretation in the context of C programming language?
A. Compilation involves converting source code to machine code, while interpretation
involves executing code line by line.
B. Compilation and interpretation are two terms that are used interchangeably.
C. Algorithm is another term for interpretation in programming languages.
D. IDE tools are responsible for both compilation and interpretation processes.
14.What is the primary difference between global variables and local variables in C?
A. Global variables have a wider scope and can be accessed from any function, while
local variables are limited to their function's scope.
B. Global variables are initialized automatically to zero, while local variables require
explicit initialization.
C. Local variables cannot be modified after initialization, while global variables allow
modification at any time.
D. Global variables can only be used within the main function, while local variables can
be used throughout the program.
19.What will happen if the while loop does NOT the loop's condition?
A. Compile time error
B. Loop infinitely
C. No Output will be printed
D. The loop will not work
25.What benefit does #define offer when dealing with magic values in code?
A. It improves code portability
B. It makes the code shorter
C. It prevents the use of symbolic names
D. It increases code complexity
28.What benefit does #define offer when dealing with magic values in code?
A. It improves code portability
B. It makes the code shorter
C. It prevents the use of symbolic names
D. It increases code complexity
29.What does the return value of the scanf function indicate when it is used to read
items from the argument list?
A. The function returns the number of items of the argument list successfully filled.
B. The function returns the total number of items in the argument list.
C. The function returns the number of items that were not successfully filled.
D. The function does not return any value.
30.What happens when the return statement has a double expression and the function
return type is int?
A. There is error
B. This causes a run-time error
C. This is system dependent
D. There is a conversion from double to int
40.In computers, what are the basic number systems and their corresponding bases
used?
A. Decimal number system (Base-10).
B. Binary number system (Base-2).
C. Octal number system (Base-8).
D. Hexadecimal number system (Base-16).
E. All answers are correct.
41.What does the expression sizeof(arr)/ sizeof(arr[0]) evaluate to, where arr is an
array?
A. The number of elements in arr
B. The size of arr in bytes
C. The number of bytes occupied by each element in arr
D. The total size of arr in bytes.
44.What function is used to read a line from the specified stream and store it in the string
pointed from a file?
A. fgets
B. fgetc
C. fputs
D. fpusc
46.Binary search can be applied to which type of the below data structure in C?
A. One-dimensional array
B. Two-dimensional array
C. Every kind of array
D. All of the others
47.Errors that occur due to syntax errors belong to which of the following?
A. Compile time error
B. Run time error
C. Input error
D. Linking error
50.Which of the following functions provide buffered input facilities on the standard input
stream?
A. getchar(), scanf()
B. getchar(), fgets()
C. scanf(), fgetc()
D. fgets(), fgetc()
54.Which function is used to read a single character from the standard input in C?
A. getchar()
B. fscanf()
C. fgets()
D. getc()
57.Which of the following statements is used to stop the select or loop statement?
A. break
B. goto
C. continue
D. while
58.What translates a C source file into machine language so that the computer can
execute it?
A. A compiler
B. A text editor
C. A file
D. A program
59.To read an entire line from a file in C, which function is commonly used?
A. fgets()
B. gets()
C. readLine()
D. scanLine()
60.What term is commonly used to specify both the type and name of a variable or
constant in a C programming language?
A. Identification
B. Name
C. Declaration
D. Definition
61.Which of the following statements is used to move to the next loop without executing
the remaining part of the loop?
A. continue
B. goto
C. return
D. break
67.What is the returned type of the sqrt() function from the math.h library in C?
A. double
B. float
C. int
D. long
70.Which of the following symbols is used to force the cursor to change its position to
the beginning of the nex line on the screen?
A. \n
B.\t
C. \f
D. \b
73.The correct function to remove characters that remain in the keyboard buffer in C
programming is
A. clearbuffer()
B. cleanbuffer()
C. flushall(in)
D. fflush(stdin)
74.What is a variable storing the address of another variable or a variable storing the
address of the dynamically allocated memory called?
A. String
B. Pointer
C. Function
D. Array
75.In C programming, when declaring a variable of a type integer, the computer stores it
in a numbered storage location. What is this numbered location called?
A. Address
B. Pointer
C. Integer
D. Byte
82.What is the primary use of the const keyword when used with function parameters in
C?
A. It prevents the function from modifying the parameter's value
B. It ensures the parameter is passed by reference
C. It restricts the parameter's scope to the function
D. It specifies that the parameter should be initialized
83.The statement for(;;) does indeed represent an infinite loop, as it lacks the conditions
that would cause the loop to terminate naturally. However, an infinite loop can still be
terminated by using
A. exit(0)
B. abort()
C. break
D. terminate
86.To avoid the generated random number sequence being identical after the program is
run again and again, we need to use the _library and the_ function before using the
rand() function.
A. stdlib.h, randomize()
B. stdlib.h, reset()
C. time.h, randomize()
D. time.h, srand()
87.Which sorting algorithm repeatedly steps through the list, compares adjacent
elements, and swaps them if they are in the wrong order?
A. Bubble sort
B. Selection sort
C. Binary sort
D. None of the others
89.When a C program compiles without any errors or warnings, it means that the syntax
of the program is correct, and the compiler successfully translates the code into
machine-readable instructions. However, a program can still produce incorrect results if
there are in the code.
A. compilation errors
B. runtime errors
C. logic or semantic errors
D. interpreter errors
90.The pow() function in the math.h library is used to calculate the value of a number
raised to a specified power. What is the return value type of the pow() function?
A. double
B. int
C. long double
D.float
91.In the sample code int a = 0x10 | 011; the variable a will contain the value (in decimal
number system):_
A. 3
B. 13
C. 19
D. 25
Ε. 27
92.The strcmp() compares two strings character by character. If the strings are equal,
the function returns....
A. 1
B. 0
C. -1
A. int* a = (int*)malloc(5*sizeof(int));
B. int a[5];
C. int a[5][5];
D. free(a);
96.What is the maximum index of the last character in a character array initialized with a
size is 10?
A. 9
B. 10
C. 8
D. It depends on the contents of the array
97.Given a matrix named mat with dimensions 6x6, what is the correct way to access
the element in the last row and last column?
A. mat[5][5]
B. mat[5][6]
C. mat[6][5]
D. mat[-1][-1]
98.What are the sizes of the memory blocks allocated for d and e?
int size = 100;
float *d = malloc(size);
float *e = calloc(size, sizeof(float));
A. 5
B. 4
C. 9
D. 12
A. 3
B. 2
C. 2.5
D. 2.6
int a[MAX_SIZE];
int s = 0;
for (int i = 0; i < n; i++)
s=s+a[i]a[i];
A. b c d e f
B. a b c d e
C. 98 99 100 101 102
D. c d e f g
A.t=0,p=4.000000
t=2,p=6.000000
B.t=0,p=4.000000
t=2,p=5.000000
C..t=0,p=4.000000
t=2,p=4.500000
D.t=0,p=4.000000
t=2,p=4.000000
105.If the two strings have the same value, then strcmp() function returns_
A. True
B. 1
C. 0
D. -1
A. Runtime error
B. Logical error.
C. Compilation error.
D. No issue.
A. The variable b can be accessed only inside the inner block where it's declared.
B. The variable b can be accessed anywhere within main() after its declaration.
C. Both variables a and b can be accessed inside the inner block.
D. The variable b can be accessed globally throughout the program.
A. 100
B. 0
C. 101
D. Compile error
109.What is the results will be displayed on the screen after executing the following
code:
int a[] = {1,2,3,4);
int i=0, s=0;
for (; a[i]; ++i)
s += a[i];
printf("%d", s);
A. 10
B. Compiler error
C. Runtime error
D. Garbage value
A. 1264
B. 1200
C. 1208
D. 1209
A 22
B. 10
C. 12
D. 21
A. 'c'
B. 'C'
C. 'c' or 'C' (depending on IDE)
D. Compilation error
113.What is the result when converting 01001010 in binary system to decimal system?
A. 78
B. 76
C. 74
D. 72
A. Calculates the sum of the absolute value of all odd elements in the array a of size n.
B. Calculates the sum of all odd elements in the array a of size n.
C. Calculates the sum of all even elements in the array a of size n.
D. Calculates the sum of squares of all elements in the array a of size n.
A. applejuice
B. apple
C. juice
D. juiceapple
116.What is the results will be displayed on the screen after executing the following
code:
char a[] = "AbCdEf";
char *s=a;
for (; *s; s+=3)
printf("%s", s);
A. Runtime error
B. Ad
C. Compiler error
D. AbCdEfdEf
E. AbC
F. dEf
117.What is the output of the following code snippet?
#include <stdio.h>
int change(int a)
{
a = 10;
return a;
}
void main()
{
int i=5;
i = change(i);
printf("%d", i);
}
A. 10
B. 5
C. 15
D. Compiler error
A. 102, 102
B 100, 102
C. 100, 100
D. 102, 100
119.Which of the following correctly represents the updated array after the execution of
the below code?
int a[] = {1, 2, 3, 4, 5);
for (i=2; i < 4; i++){
a[i] = a[i + 1];
}
A. {1, 2, 4, 5, 5)
B. {1, 2, 4, 5}
C. (1, 3, 4, 5)
D. {1, 2, 3, 4}
120.What is the output of the following code if the user enters the value "20"?
int n;
char c;
scanf("%d", &n);
c = getchar();
printf("%d",c);
A. 10
B. 20
C. "
D. Undefined
121.Consider the following code snippet that reads and prints the contents of a text file
named "data.txt"
#include <stdio.h>
int main() {
FILE *file_ ptr;
char ch:
file_ptr = fopen("data.txt", "r");
if (file ptr == NULL) {
printf("Unable to open the file. \n");
return 1;
}
while ((ch = fgetc(file_ptr)) != EOF) {
printf("%c", ch);
}
fclose(file_ptr);
return 0;
}
What will be the output of this code when executed, assuming "data.bxt" contains the
following text: Hello
This is a sample text file.
A. Hello
This is a sample text file.
B. Hello
C. This is a sample text file.
D. This is a sample text file.
Hello
122.Assume we have a function such as:
void swap(int a, int b){
int t = a;
a=b;
b=t;
}
What is the problem with a and b after executing the swap (a, b) function?
A. 333
B. 111
C. 222
D. Compile error
A. infinite loop
Β. 01234
C. 543210
D. No output
E. Compiler error
F. 0
125.What is the value of variable a after executing the following lines of codes:
int a = 0;
char line1[] = "Hi";
char line2[] = "Hello";
a = strcmp(line1, line2);
A.0
B. A positive value
C. A negative value
D. NAN
A. {1, 8, 2, 7, 9}
B. {8, 1, 2, 7, 9}
C. {1, 2, 8, 7, 9}
D. {1, 2, 7, 8, 9}
A. 8 bytes
B. 4 bytes
C. 2 bytes
D. 16 bytes
A.11,11
B.1,1
C.0,0
D.0,1
A. A
BB
CCC
DDDD
EEEEE
B. AAAAA
BBBB
CCC
DD
E
C. A
AB
ABC
ABCD
ABCDE
D.A
AA
AAA
AAAA
AAAAA
A. Runtime error.
B. Compiler error.
C. x = 5 y = 10
D. x = 10 y = 5
E. x = 10 y = 10
F. x = 5 y = 5
A. Compiler error
B. 1.000000
C. 1.500000
D. 1.0
Ε. 1.5
F. 1
A. 10 5
B. 5 10
C. 5 5
D. 10 10
A. 0 1 1 2 3 3
Β. 0.5 1.0 1.5 2.5 3.0 3.5
C. 1 1 2 3 3 4
D. 0 1 1 2 2 3
A. Infinite loop
B. Compile time error
C. Yes Yes Yes Yes
D. Yes
A. OneOneOneOne
B. OneTwoOneOne
C. OneTwoTwoTwo
D. TwoTwoTwoOne
143.Which is the correct function definition that will run without errors?
A. 0
B. 1
C. 10
D. 100
149.Which of the following is a valid code to use to declare and initialize a two-
dimensional array?
A. 2
B. 5
C. Compilation error.
D. 3
A. 5
B. Run time error
C. 6
D. Junk
160.Choose the best comment about the output of the following C code:
#include <stdio.h>
void main()
{
int i=0
while (i < 5)
{
i++;
printf("Hi-");
while (i < 4)
{
i++;
printf("Hello-");
}
}
}
A. Hi-Hi-Hi-Hi-Hello-Hello-Hello-Hi-
B. Hi-Hi-Hi-Hi-Hi-Hello-Hello-Hello-
C. Hi-Hello-Hello-Hello-Hello-Hi-
D. Hi-Hello-Hello-Hello-Hi-
161.What will be the output of the following C code?
#include <stdio.h>
void main()
{
char result = 125;
result result 125;
printf("%d", result);
}
A. 130
B. -130
C. 126
D. -126
A. 105
B. 150
C. 120
D. 210
A. 5
B. Run time error
C. 6
D. Junk
A. 2
B. 8
C. 16
D. 6
A. 10,10
B. 10,11
C. 11,10
D. 11,11
A. 0
B. 2
C. Compiler error.
D. 4
167.Choose the best comment about the output of the following C code:
#include <stdio.h>
int main()
{
int a = 1;
switch (a)
case 1:
printf("%d", a);
case 2:
printf("%d", a);
case 3:
printf("%d", a);
return 0;
}
A. 1
B. 2
C. 3
D. 4
A. 5ha
B. ha
C. dha
D. 7
A. 0
B. 4
C. 2
D. 8
171.What will be the output of the C program?
int 2_var = 15;
printf("%d", 2_var);
A. 0
B. 15
C. Compilation error.
D. Runtime error.
A. -20;90;8
B. 70;90;80
C. 150;80;8
D. 150;90;80
A. 9
B. 8
C. 12
D. 10
A 10 8 6 4 2
B. 10 8 6 4 2 0
C. 10 8 6 4 2 0 -2 -4
D. 10 9 8 7 6 5 4 3 2
A. 1; 18; 120
B. 10;19;60
C. 1;20;60
D. 10;19; 120