0% found this document useful (0 votes)
22 views

PRF192

The document consists of a series of multiple-choice questions related to the C programming language, covering topics such as variable definitions, functions, loops, pointers, and data types. Each question presents options to choose from, testing knowledge on syntax, functionality, and programming concepts in C. The questions range from basic to more advanced topics, making it a comprehensive quiz for assessing understanding of C programming.

Uploaded by

23122349
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

PRF192

The document consists of a series of multiple-choice questions related to the C programming language, covering topics such as variable definitions, functions, loops, pointers, and data types. Each question presents options to choose from, testing knowledge on syntax, functionality, and programming concepts in C. The questions range from basic to more advanced topics, making it a comprehensive quiz for assessing understanding of C programming.

Uploaded by

23122349
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 41

1.Which of the following is a valid variable definition?

A. int 1student_ID;
B. int _Student_ID1;
C. int Age$;
D. int long;

2.Which is a function in C language?


A. is_ prime()
B #include()
C. int()
D. if()
E return()
F. 2ndElement()

3.Which of the following statements is invalid?


A. printf('\\\');
B. printf("abc");
C. printf("%%");
D. printf("\n");

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

5.Which of the following is the correct syntax of the for statement?


A. for (Init1, Init2; Condition; Task1, Task2);
B. for (Init1, Condition, Task1);
C. for (Condition; Init1, Init2; Task1);
D. for (Init1; Init2; Condition; Task2)

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.

10.What is the main() function in C?


A. It is the function where the program's execution starts.
B. Every program has exactly one main function.
C. The main function always returns an integer value or void.
D. All answers are correct.

11.How to declare a variable in C language?


A. All variables must be declared before we use them in C program.
B. To declare a variable you specify its name and data type it can store.
C. All variable are always stored on the stack.
D. Reading a value from keyboard or other device with a OUT statement
E. The scope of a variable is the range of program statements that can't access that
variable

12.The ^ operator in the C programming language is used to_


A. XOR two bit sequences.
B. OR two bit sequences.
C. AND two bit sequences.
D. SHIFT UP a bit sequences.
E. NOT a bit sequences.
F. Calculate the exponential value, for example 2^3 = 8.

13.What is the scope of a global variable in C?


A. Throughout the entire program
B. Only within the function where it's declared
C. Only within the block where it's declared
D. Within the structure where it's defined

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.

15.What is the purpose of the sizeof operator in C?


A. It returns the size of a variable in bytes
B. It returns the value of a variable
C. It declares the size of an array
D. It calculates the sum of two numbers

16.How does a "for" loop differ from a "while" loop in C programming?


A. A "for" loop is used for iterating over a sequence of elements, while a "while" loop is
used to execute a block of code repeatedly as long as a condition is true.
B. A "for" loop is primarily used for conditional statements, while a "while" loop is
designed for sequential processing.
C. The use of "for" and "while" loops is interchangeable, there is no substantial
difference between them.
D. A "for" loop is exclusively used with arrays, while a "while" loop is used with numerical
calculations.

17.What is a pointer in C programming?


A. A variable stores anything
B. A variable stores address of another variable or a variable stores address of the
dynamically allocated memory
C. An address in the memory
D. A variable stores any number

18.What is the purpose of the continue statement in a loop?


A. To skip the rest of the code inside the loop and move to the next iteration.
B. To jump to the beginning of the loop.
C. To exit the entire program.
D. The way increment/decrement variable in the loop

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

20.What is the purpose of the calloc function in C?


A. Allocate memory and initialize it to zero
B. Free memory allocated
C. Deallocate memory
D. Copy memory from one location to another

21.What will happen if the loop's condition is always true?


A. Loop infinitely
B. No Output will be printed
C. Compile time error
D. The loop will not work

22.What is the difference between a while loop and a do-while loop?


A. The way the condition is checked.
B. They are essentially the same.
C. The type of tasks they can perform.
D. The variable in loop construct.

23.What is the incorrect definition?


A. Algorithm: a way to find out a solution
B. Data: Values are used to describe information. So, information can be called as the
mean of data
C. Solution: A situation in which something is hidden
D. Information: Knowledge about something

24.What is the function of "fflush(stdin);" command?


A. Print string out to screen
B. Receive a string entered from the keyboard
C. Remove characters are entered from keyboard
D. Remove characters are remained in the keyboard buffer

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

26.What is the incorrect definition?


A. Algorithm: a way to find out a solution
B. Data: Values are used to describe information. So, information can be called as the
mean of data
C. Solution: A situation in which something is hidden
D. Information: Knowledge about something
27.What does the statement rewind(fp) do?
A. Bring the pointer fp back to the beginning of the file
B. Assign to the pointer fp the address 0x00 (NULL)
C. Bring the pointer fp to the end of the file
D. Bring the pointer fp back to the beginning of the current line

28.During the compilation process, what will be done with comments?


A. The comment mark will be removed. The content of the comments will be compiled
line by line.
B. The comment is treated as an array of characters.
C. Comments are removed in the pre-processing step.
D. Each comment is compiled as a statement that does nothing.

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

31.How to declare a variable in C language?


A. All variables must be declared before we use them in C program.
B. To declare a variable you specify its name and data type it can store.
C. All variable are always stored on the stack.
D. Reading a value from keyboard or other device with a OUT statement
E. The scope of a variable is the range of program statements that can't access that
variable.

32.Which of the following statements about the strstr() function in C is true?


A. Compare two strings
B. Returns the pointer to the first occurrence of the given substring in the main string
C. Concatenate source string to the end of destination string
D. Copy source string to destination string

33.What is a pointer in C programming?


A. A variable stores anything
B. A variable stores address of another variable or a variable stores address of the
dynamically allocated memory
C. An address in the memory
D. A variable stores any number

34.What is the purpose of the sizeof operator in C?


A. It returns the size of a variable in bytes
B. It returns the value of a variable
C. It declares the size of an array
D. It calculates the sum of two numbers

35.Which is incorrect statement in C programming?


A. #define is a preprocessor command often used to introduce named constants
B. double and goto are keyword for declaring data type.
C. return 0; is normally the last statement in main()
D. The file stdio.h is the library where the compiler finds scanf().

36.Real-world example of a switch statement in C is:


A. Check the day of the week.
B. Sort an array ascending.
C. Sort an array descending.
D. Find the average value of a sequence.

37.Choose the correct definition for "Simple data types" in C programming.


A. Changing from one form of representation to another
B. A category of data that represents individual, non-complex elements such as integers,
floating-point numbers, and characters
C. Performing operations and expressions on data
D. Storing a collection of elements accessible by an index or a key

38.What is the correct order of the main components in the function?


A. Return type, function name, parameters, and function body.
B. Return type, function name, return value, and function body
C. Return type, function name, parameters, and return value
D. Return value, function name, parameters, and function body

39.In C programming language, what is the function fprintf() used for?


A. Writing formatted data to a file.
B. Reading formatted data from a file.
C. Appending formatted data to a file.
D. Closing a file.

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.

42.Choose the correct statement related to the array.


A. Arrays provide constant-time access to elements.
B. Arrays allow for dynamic resizing during runtime.
C. Arrays can store elements of different data types.
D. Arrays automatically adjust their size based on the number of elements.

43.Which of the following statements is incorrect?


A. To make our programs longer, we use higher-level languages.
B. Program code in a high level language can not run, it must be translated to binary
code (machine code) before running.
C. C is based on a view of structured programming.
D. Programs that perform relatively simple tasks and are written in assembly language
contain a large number of statements.

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

45.What is the & operator?


A. Bitwise AND
B. Bitwise OR
C. Logical AND
D. Logical OR

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

48.What is incorrect when input a string?


A. scanf("%s", s);
B. scanf("%[^\n]", s);
C. getc(s);
D. gets(s)
E. scanf(s);

49.The strcpy() function in C programming is used to


A. copy strings
B. contcatenate (joins) two strings
C. compare two strings

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()

51.Which function is used to write a string to a file in C?


A. fputs()
B. fscanf()
C. fgets()
D. fopen()

52.The function islower() returns a non-zero value if a character is:


A. A lowercase letter
B. An uppercase letter
C. A digit
D. A punctuation character

53.Which of these is NOT a relational or logical operator?


A. =
B. ||
C. ==
D. !=

54.Which function is used to read a single character from the standard input in C?
A. getchar()
B. fscanf()
C. fgets()
D. getc()

55.What is the return type of the putchar function?


A. int
B. char
C. void
D. string

56.In C programming, a variable is frequently used to store the address of another


variable. What is the name of this variable?
A. Pointer
B. Address
C. Integer
D. Byte

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

62.What is incorrect when output a string?


A. putc(s)
B. puts(s)
C. printf(s)
D. printf("%s",s)
E. printf("%s", &s)

63.Which format specifier is used to print the value of a double variable?


A. %lf
B. %d
C. %c
D. %f

64.What is the result of floor(-5.9) and floor(5.9)?


A. -6 and 5.
B. -5 and 5.
C. -6 and 6.
D. -5 and 6.

65.Who is the inventor of the C programming language?


A. Dennis Richie
B. Bjarne Stroustrup
C. Brian Kernighan
D. Niklaus Wirth

66.Which character is commonly used to mark the end of a string in C?


A. '\0'
B. '\n'
C. '\t'
D. '\'

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

68.Which keyword is used to define a named constant in C?


A. const
B. define
C. constant
D. named

69.Which of the following operators has the lowest priority?


A. +=
B. +
C. ++
D. -

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

71.Which keyword is used to define a named constant in C?


A. const
B. define
C. constant
D. named

72.Which of the following operators can be applied to the pointer variable(s)?


A. Increments
B. Square root
C. Division
D. Multiplication

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

76.Which mode is only used to append data to a file?


A. "a"
B. "append+"
C. "r+"
D. "w+"

77.What is the main() function in C?


A. It is the function where the program's execution starts.
B. Every program has exactly one main function.
C. The main function always returns an integer value or void.
D. All answers are correct.

78.What technique in programming to solve this complex problem is to break the


program into a series of smaller programs?
A. Modularity
B. Repeat
C. Select
D. Sequentially

79.Values used to describe information in programming are typically referred to as "


A. Data
B. Information
C. Algorithm
D. Computer program

80.Which is not a type of bus in a computer?


A. Address bus
B. Signal bus
C. Control bus
D. Data bus

81.Which function is used to concatenate two strings in C?


A. strcat()
B. strcomb()
C. strmerge()
D. strconnect()

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

84.Given the following code snippet: int a[10] = {1, 2, 3};


What is the value of a[3]?
A. 0
B. 1
C. 2
D. 3

85.In C, what is the purpose of | operator?


A. It is a bitwise operator OR
B. It is a logical operator AND
C. It is a bitwise operator AND
D. It is a logical operator OR

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

88.How are strings typically represented in C?


A. As an array of characters
B. As an array of strings
C. As individual characters
D. As integers referencing ASCII values

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

93.What is the result of the "printf("%d", 0x11 | 010);" command?


A. 5
B. 22
C. 18
D. 25
Ε. 28

94.What represents dynamic allocation in C?

A. int* a = (int*)malloc(5*sizeof(int));
B. int a[5];
C. int a[5][5];
D. free(a);

95.Which of the following declaration is not supported by C?


A. string a;
B. float a = 3e2;
C. int* a;
D. float *a;
E. char * 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. 400 bytes and 400 bytes


B. 400 bytes and 100 bytes
C. 100 bytes and 800 bytes
D. 100 bytes and 400 bytes

99.Assume we have the following code:


int i=4;
int *p = &i;
What is the result of the following expression: ++*p?

A. 5
B. 4
C. 9
D. 12

100.What is the result of the "printf("%d %d", 12&5,12|5);" command?


A. 4 13
B. 5 12
C. 4 12
D. 5 13
E. 11

101.What is the value of ceil(2.55) from the math.h library?

A. 3
B. 2
C. 2.5
D. 2.6

102.Consider an array a with n elements. The code snippet above is executed to


calculate the value s. Which of the following options correctly describes the value of s
after executing the code snippet?

int a[MAX_SIZE];
int s = 0;
for (int i = 0; i < n; i++)
s=s+a[i]a[i];

A. The sum of squares of all elements in the array a


B. The sum of all even elements in the array a.
C. The sum of all odd elements in the array a.
D. The sum of all elements in the array a.

103.What is the output of the following code snippet?


#include <stdio.h>
int main() {
char char_array[] = {'a', 'b', 'c', 'd', 'e'};
int array_size = sizeof(char_array) / sizeof(char);
for (int i = 0; i < array_size; i++) {
char_array[i] = char_array[i] + 1;
}
for (int i = 0; i < array_size; i++) {
printf("%c", char_array[i]);
}
return 0;
}

A. b c d e f
B. a b c d e
C. 98 99 100 101 102
D. c d e f g

104.Consider the following program and answer the following questions.


##include<stdio.h>
void updatePosition(int "time, float" position, float v)
{
if ((*position <5) && ((^ * pos(bon > - 5))
*position+=v;
else
* position+=-0.1*(*póition);
time+ 1;
}
main()
{
float p = 4.0 , v= 1;
int t=0;
printf("t = %d,p= %f\n”,t,p);
updatePosition(&t,&p,v);
updatePosition(&t,&p,v);
printf(“t=%d,p=%f\n”,t,p);
}
What is the result displayed to the screen?

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

106.What is the issue with the following code?


char str[1];
gets(str);
printf("%s", str);

A. Runtime error
B. Logical error.
C. Compilation error.
D. No issue.

107.Given the following code snippet:


#include <stdio.h>
int main() {
int a = 5;
{
int b = 10;
printf("%d", a);
}
// Uncommenting the line of code below will be a compilation error.
// printf("%d", b);
return 0;
}
Which of the following best describes the scope of a variable declared inside a block in
C?

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.

108.What is the output of the following code snippet?


#include<studio.h>
int main(){
const int *p;
int a=100;
p=&a;
printf("%d",*p);
return 0;
}

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

110.Assume we have the following codes:


double d=9;
double *p = &d:
Suppose that a double occupies the memory block of 8 bytes, and the address of d is
1200. What is the result of the following expression: p + 8?

A. 1264
B. 1200
C. 1208
D. 1209

111.What is the output of the following code snippet?


#include <stdio.h>
int num(int a, int b){
int sum;
sum = a + b;
return sum;
}
int main()
{
int a, b, result;
a = 10;
b= 12;
printf("%d", result);
printf("%d", result);
return 0;
}

A 22
B. 10
C. 12
D. 21

112.What will be the output of the following code? printf("%c", tolower('c'));

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

114.Consider the following code:


int func(int* a, int n){
int S = 0;
for(int i = 0; i < n; i++) {
S = S + (a[i] % 2)*a[i];
}
return S;
}
What does the above code snippet do?

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.

115.What is the output of the following code snippet?


char words[4][11];
strcpy(words[0], "apple");
strcat(words[0], "juice");
printf("%s\n", words[0]);

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

118.What will be the output of the following program?


int main()
{
int i = 100;
int *p = &i;
*p +=2;
printf("%d, %d", i, *p);
getchar();
return 0;
}

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. a and b do not change values.


B. cannot execute the swap(a,b) function.
C. a has the old value of b, and b has the new value of t.
D. a and b change values for each other;

123.What will be the output of the following program?


int main()
{
int i = 1;
int *p = &i;
int **k = &p;
i+=2;
printf("%d%d%d", *p, **k, *(*k));
getchar();
return 0;
}

A. 333
B. 111
C. 222
D. Compile error

124.What does the following code print?


int i = 0;
while (i < 5) {
printf("%d ", i);
i--;
}

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

126.Consider the following array of integers: (8, 1, 2, 7, 9}


What will be the state of the array after one pass of selection sort?

A. {1, 8, 2, 7, 9}
B. {8, 1, 2, 7, 9}
C. {1, 2, 8, 7, 9}
D. {1, 2, 7, 8, 9}

127.what is the size of a float variable in byte?


A. 2 bytes
B. 1 byte
C. 8 bytes
D. 4 bytes
128.what is the output of the following code snippet?
char str10 = "Hello";
char str2[10];
strcpy(str2, str1);

A. Copies content of str1 into str2


B. Compares str1 with str2
C. Retrieves the length of str1
D. Assign str2 to an empty string

129.What is the result of the expression 10 % 3?


A. 1
B. 3
C. 2
D. 0

130.What is the size of the char data type in bytes?


A. 1 byte
B. 2 bytes
C. 4 bytes
D. It depends on the syýtem

131.What will be the maximum size of a double variable?

A. 8 bytes
B. 4 bytes
C. 2 bytes
D. 16 bytes

132.What will be the output of the following program?


void func(int *p){
int j=11;
*p = j;
}
int main() {
int i=1;
int*p = &i;
func(p);
printf(“%d,%d”,i,*p);
getchar();
return 0;
}

A.11,11
B.1,1
C.0,0
D.0,1

133.Consider the following program. What will be printed to the screen?


#include<stdio.h>
int main()
{
char i,j;
for (i= 'A'; i < 'E'; i++)
{
for (j=’A’;j<=i; j++)
{
printf("%c", i);
}
printf(“\n”);
}
return 0;
}

A. A
BB
CCC
DDDD
EEEEE

B. AAAAA
BBBB
CCC
DD
E

C. A
AB
ABC
ABCD
ABCDE

D.A
AA
AAA
AAAA
AAAAA

134.What does the following code print?


#include <stdio.h>
void swap(int a, int *b) {
int temp = a;
a = *b;
*b = temp;
}
int main() {
int x = 5;
int y = 10;
swap(x, y);
printf("x=%d, y = %d\n", x, y);
return 0;

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

135.What is the result of the expression !1?


A. 0
B. 1
C. 10
D. 11

136.Given the following code snippet:


#include <stdio.h>
#define MONTHS_IN_YEAR 12
int main() {
const int WORKING_DAYS = 22;
printf("%d ", MONTHS_IN_YEAR);
printf("%d", WORKING_DAYS);
return 0;
}

Choose the correct statement:


A. The output will be: 12 22
B. No output
C. Compile error
D. Runtime error

137.What is the return value of the strcmp("abc", "Abcdef") function?


A. 1
B. 0
C. -1
D. 2

138.What does the following code print?


float a = 3.0;
float b = 2.0;
int r = a % b;
printf("%d", r);

A. Compiler error
B. 1.000000
C. 1.500000
D. 1.0
Ε. 1.5
F. 1

139.What will be the output of the following code snippet:


#include <stdlib.h>
#include <stdio.h>
int main() {
int a = 5;
{
int a = 10;
printf("%d ", a);
}
printf("%d", a);
return 0;
}

A. 10 5

B. 5 10

C. 5 5

D. 10 10

140.What is the result displayed on the screen of the following program?


#include <stdio.h>
int main(void)
{
int a[] = {1, 2, 3, 5, 6, 7);
for (int i = 0; i < 6; ++i)
printf("%3d", a[i]/2);
return 0;
}

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

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


#include <stdio.h>
int main()
{
int x=7;
for(;x>3;)
printf("Yes");
x–;
return 0;
}

A. Infinite loop
B. Compile time error
C. Yes Yes Yes Yes
D. Yes

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


#include<stdio.h>
int main()
{
int x=10,i;
for(i=0;i<x;i+=3){
printf("One");
continue;
printf("Two");
}
return 0;
}

A. OneOneOneOne
B. OneTwoOneOne
C. OneTwoTwoTwo
D. TwoTwoTwoOne

143.Which is the correct function definition that will run without errors?

A. int minus(int a, int b) {return (a - b);}


B. int minus (int a, b) {return (a - b);};
C. int minus (int a, int b) {return (a - b);}
D. int minus (int a, b) {return (a - b);}

144.Which of the following is not a valid variable name declaration?


A. int_a3;
B. int a_3;
C. int 3_a;
D. int_3a

145.What will be the output of the following C code?


#include <stdio.h>
void main()
{
int i= 10, j = 3, k = 3;
printf("%d %d ", i, j, k);
}
A. Compile time error
B. 10 3 3
C. 10 3
D. 10 3 somegarbage value

146.Assume we have a snippet code in C:


int main() {
int *p = NULL:
printf("%d",p);
getchar();
return 0;
}
The output will be:

A. 0
B. 1
C. 10
D. 100

147.int *ptr = malloc(sizeof(int));


To reallocate ptr to be an array of 5 elements, which of the following statements
generates an error?

A. ptr = realloc(ptr, 5* sizeof(int));


B. realloc(ptr, 5* sizeof(int));
C. ptr += malloc(5* sizeof(int));
D. realloc(ptr, 20);
E. ptr = realloc(ptr, 20);

148.What is the syntax of the conditional operator in C?


A. condition? expression1: expression2
B. condition? expression1, expression2
C. condition: expression1? expression2
D. expression1: condition? expression2

149.Which of the following is a valid code to use to declare and initialize a two-
dimensional array?

A. int a[2, 3] = [[1, 2, 3], [4, 5, 6]]


B. int a[][]= {{1, 2, 3}, {4, 5, 6}} ;
C. int a[2][3] = [[1, 2, 3], [4, 5, 6]];
D. int a[] [3] = {{1, 2, 3}, {4, 5, 6}}

150.Which of the following is an incorrect iteration construct?


A. (condition)? True_Value: False_Value
B. for (InitBlock; Condition; Task2) Task1;
C. do{ statements;} while (condition)
D. while (condition) { statements; }

151. What is incorrect about function prototype?


A. void printSum(int* a, int b);
B. int printSum(int* a, int b);
C. int printSum(int a, b);
D. int* printSum(int* a, int b);

152.Which of the following is the correct syntax of the while statement?


A. while (condition) { statements; }
B. (condition) { statements ;}
C. while (condition) { statements };
D. { statements } while (condition);

153.Which is a function in C language?


A. is _ prime()
B. #include()
C. int()
D. if()
E return()
F. 2ndElement()

154.How can you initialize a character array in C?


A. char arr[] = "Hello";
B. char arr[] = ['H', 'e', 'l', 'l', 'o','/e'];
C. Char[] arr = "Hello";
D. Char[] arr = ('H', 'e', 'I', 'l', 'o','/0');

155.Which implicit type casting is used in the following codes in C programming?


A. int i = (double) 123.5;
B. double t = double(2);
C. double t = (double) 2;
D. double t = (int) 2.7;
156.The function which will compute the average of two real numbers should be
prototyped as:
A. int average(double, double);
B. double average(double, double);
C. char average(double, double);
D. void average(double, double);
157.What will be the output of the C program?
int default 5, a = 3;
if(a > 2)
printf("%d", default);

A. 2
B. 5
C. Compilation error.
D. 3

158.What will be the output of the following C code?


#include <stdio.h>
void main()
{
int k = 5;
int *p = &k;
int **m = &p;
**m = 6;
printf("%d\n", k);
}

A. 5
B. Run time error
C. 6
D. Junk

159.What will be the output of the following C code?


#include <stdio.h>
void main()
{
int x = 0:
if (x == 0)
printf("Hi"),
else
printf("How are you");
printf("Hello");
}
A. Hi
B. How are you
C. Hello
D. HiHello

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

162.What will be the output of the following C code?


#include <stdio.h>
void main()
{
int total=0;
for(int s=1; s<15; s++)
total=total+s;
printf("%d", total);
}

A. 105
B. 150
C. 120
D. 210

163.What will be the output of the following C code?


#include <stdio.h>
void main()
{
int k = 5;
int *p = &k;
int **m = &p;
**m = 6;
printf("%d\n", k);}

A. 5
B. Run time error
C. 6
D. Junk

164.What will be the output of the C program?


int a = 4, b = 2;
printf("a^b = %d", a^b);

A. 2
B. 8
C. 16
D. 6

165.What will be the output of the following C code?


#include <stdio.h>
void main()
{
int *ptr, a = 10;
ptr = &a;
*ptr += 1;
printf("%d,%d\n", "ptr, a);
}

A. 10,10
B. 10,11
C. 11,10
D. 11,11

166.What will be the output of the C program?


#include<stdio.h>
void myFunction(int i)
{
printf("%d", i);
}
int main()
{
myFunction();
return 0;
}

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. No error, output is 1111


B. No error, output is 1
C. Compile time error, no break statements
D. Compile time error, case label outside switch statement

168.What will be the output of the C program?


char temp;
char arr[10] = {1, 2, 3, 4, 5, 6, 7, 8);
temp = (arr + 1)[2];
printf("%d\n", temp);

A. 1
B. 2
C. 3
D. 4

169.What will be the output of the C program?


int a = 5;
printf("%dha"+2,a);

A. 5ha
B. ha
C. dha
D. 7

170.Suppose there is a function in C as follows:


double g (double x, double y){
return (x-2)*(x - 2) + y*y;
}
What is the value of z after executing the statement z=g(2,0)?

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.

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


#include<stdio.h>
int main()
{
int a=70,b=90,c=80;
if(a!=b){
a-=b; c/=10;
}
else
a+=c;
printf("%d,%d,%d",a,b,c);
return 0;
}

A. -20;90;8
B. 70;90;80
C. 150;80;8
D. 150;90;80

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


#include<stdio.h>
int main()
{
int x=10,i;
for(i=9;i<x;i+=3){
printf("%d",i++);
break;
printf("%d",-1);
}
return 0;
}

A. 9
B. 8
C. 12
D. 10

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


#include<stdio.h>
int main()
{
const int a=5;
if(a>3)
a++;
break;
else
a-- ;
printf("%d",a);
return 0;
}

A. Compile time error


B. 6
C. 4
D. 5

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


#include <stdio.h>
int main() {
int i = 10;
do {
printf("%d ", i);
i-= 2;
} while (i >= 1);
return 0;
}

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

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


#include <stdio.h>
int main()
{
20 > 30? return 1: return 2;
}

A. Compile time error


B. 1
C. 2
D. return 1:return2

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


#include<stdio.h>
int main()
{
int a=10,b=20,c=30,
while(a>1)
{
if(b%2!=0)
a/=10;
b--;
c*=2:
}
printf("%d %d %d",a,b,c);
return 0;
}

A. 1; 18; 120

B. 10;19;60

C. 1;20;60

D. 10;19; 120

You might also like