Basic C MCQ - Final
Basic C MCQ - Final
Basic C MCQ - Final
Degree : M.Sc
Branch : SS / TCS / DS / CS / AM
Course Code : 20XW15/XT14/XD14/XC15/SA16
Course Name : PROBLEM SOLVING AND C PROGRAMMING
Use the question paper format which is available from the next page:
Field Instructions
Question 1
number
Question Consider the following C code. Which of the following is
true?
char *f="%d\n";
printf(f, 10);
Option No Option Correct(Y)
Option 1 is valid and prints the number 10, followed by a Y
newline character
Option 2 Is NOT valid and compile time error will be thrown
Option 3 Is valid and nothing will be printed
Option 4 Runtime error will be thrown
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 2
number
Question If s1 and s2 are two string variables, and i is an integer
variable; which of the following lines is NOT a valid use of
string functions?
Option No Option Correct(Y)
Option 1 strcmp(i, s1); Y
Option 2 strcpy(s2, s1);
Option 3 strcat(s1, s2+i);
Option 4 i = strlen(s1);
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 3
number
Question If p and q are pointers to int, pointing to elements of an array,
which of the following statements is not valid:
Option No Option Correct(Y)
Option 1 p = q + 2;
Option 2 *p = p - q;
Option 3 *p = p + q; Y
Option 4 *p = *p + *q;
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 4
number
Question Suppose that we would like to write a C program to read from
a text file named hello.txt and print its content to the screen.
To do this, we use a file pointer fp. Which of the following
four statements should we use to open this file?
Option No Option Correct(Y)
Option 1 fp = fopen("hello.txt", "w");
Option 2 fp = fopen("hello.txt", "a");
Option 3 fopen(fp, "hello.txt");
Option 4 fp = fopen("hello.txt", "r"); Y
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 5
number
Question Suppose that the following declarations are in effect:
int a[] = {17, 14, 10, -5, 14, 19};
int *p = &a[1];
int *q = &a[4];
Which of the following four logical expressions evaluates to
false?
Option No Option Correct(Y)
Option 1 p<q
Option 2 *p == *q
Option 3 a<p
Option 4 p == q Y
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 6
number
Question What will be the output of the following C program?
#include <stdio.h>
int main(void) {
char s[] = "Happy Programming";
printf("%c\n", s[1]);
printf("%s\n", s+6);
*(s+5) = '\0';
printf("%s\n", s);
return 0;
}
Option No Option Correct(Y)
Option 1 Illegal Operation
Option 2 a Y
Programming
Happy
Option 3 Happy Programming
Option 4 appy
gramming
Pro
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 7
number
Question What will be the output of the following C Program?
#include <stdio.h>
int main(void) {
int i = 4, j = 8;
int *p = &i;
int *q;
int *r = &j;
*r = *p;
q = p;
(*q)--;
printf("%d %d %d", *p, *q, *r);
}
Question 8
number
Question The following user defined function is supposed to create an
identical copy of a string and returns a pointer that points to it.
Which of the following statements correctly describes it?
char *duplicate(char *p) {
char *q;
strcpy(q, p);
return q;
}
Option No Option Correct(Y)
Option 1 Correct code and it will perform the task.
Option 2 Syntax Error function cannot return pointer
Option 3 Runtime Error: Segmentation fault as q is pointing Y
to unknown location.
Option 4 No error. But it will not do the expected operation.
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 9
number
Question Which of the following statements regarding streams and files
in the C programming language is INCORRECT?
Option No Option Correct(Y)
Option 1 In C, a stream is any source of input or any
destination of output;
Option 2 The following statement will output “out of Y
memory” followed by a newline character to
the standard error channel:
fprintf(stdout, "out of memory\n");
Option 3 The fopen function returns NULL when it fails
to open a file;
Option 4 The notion of lines does NOT apply to binary
files.
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 10
number
Question If c is a variable of type char, which one of the following
statements is illegal?
Option No Option Correct(Y)
Option 1 i += c; /* i has type int */
Option 2 c = 2 * c - 1;
Option 3 printf(c); Y
Option 4 putchar(c);
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 11
number
Question Suppose that the following declarations are in effect:
int a[] = {17, 211, 10, -5, 14, 19};
int *p = &a[3];
What is the value of *(p+2)?
Option No Option Correct(Y)
Option 1 10
Option 2 -5
Option 3 14
Option 4 19 Y
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 12
number
Question What is the output of the following program?
#include <stdio.h>
#include <string.h>
int main() {
char s[90] = "test";
char *p = "program";
printf("%d %d\n", strlen(s), strlen(p+2));
puts(strcat(s, p));
printf("%d\n", strlen(s));
return 0;
}
Question 13
number
Question In the following piece of C code, what will be the value of x?
int a = 3, b;
int x = 2 * (b = a) + (a = 1);
Option No Option Correct(Y)
Option 1 7 or 3 depends on the compiler execution order of Y
()
Option 2 Always 7
Option 3 Sometimes 7 and sometimes 3
Option 4 Always 3
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 14
number
Question What does the following piece of code compute?
int num;
for (num = 100; 1; ++num) {
for (int div = 2; div < num; ++div) {
if (!(num % div)) {
goto label;
}
}
break;
label: ;
}
printf("num = %d\n", num);
Option No Option Correct(Y)
Option 1 Computes a prime number no less than 100
Option 2 Computes the largest prime number no less
than 100
Option 3 Computes the smallest prime number no less Y
than 100
Option 4 Computes the smallest prime number greater
than 100
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 15
number
Question For the following statement, state what the output is when
they are executed.
int a = 0;
int b = 3;
if (a != 0 && b % a == 0) {
printf("%d divides %d\n", a, b);
}
else {
printf("%d does not divide %d\n", a, b);
}
Option No Option Correct(Y)
Option 1 0 divides 3
Option 2 0 does not divide 3 Y
Option 3 Runtime Error a % b is illegal
Option 4 No Error. No output.
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 16
number
Question What does the following expression print? Assume a is of int
type.
if (a = 0) {
printf("a is zero");
}
else {
printf("a is non-zero");
}
Option No Option Correct(Y)
Option 1 a is zero
Option 2 Error in if condition
Option 3 a is non-zero Y
Option 4 Runtime Error
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 17
number
Question If a is a number between 0 and 99, what does the following
code print?
char a1 = '0' + (a / 10);
char a0 = '0' + (a % 10);
printf("%c%c", a1, a0);
Option No Option Correct(Y)
Option 1 This will print two junk characters
Option 2 This prints the value of a as a two-digit number. Y
Option 3 This prints the value of a
Option 4 This prints the char equivalent of the value of a
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 18
number
Question Consider the following code segment. What will be printed?
int i = 1; int j = 2;
if (i) {
int i;
i = j;
j = 0;
}
printf("%d %d", i, j);
Question 19
number
Question #include <stdio.h>
int mystery(int n);
int main() {
int n = 3;
printf("%d %d\n", n <= 1, mystery(n));
return 0;
}
int mystery(int n) {
if (n <= 1)
return 1;
else
return (mystery(n-1) + n);
}
What will be the output of the above program?
Option No Option Correct(Y)
Option 1 0 6 Y
Option 2 0 Garbage Value
Option 3 1 6
Option 4 1 Garbage Value
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 20
number
Question Compilation is the step in the software development cycle
where this type of errors are detected.
Option No Option Correct(Y)
Option 1 Logic Errors
Option 2 Syntax Errors Y
Option 3 Semantic Errors
Option 4 Specification Errors
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 21
number
Question Comments / documentation are meant for _____ rather than
the computer and provide explanation of the actual code.
Option No Option Correct(Y)
Option 1 Barcode readers
Option 2 Compiler to understand the logic
Option 3 Human readers Y
Option 4 To select the compiler
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 22
number
Question The actual arguments in a function call have to match the
_____ of parameters that appear in the function definition
Option No Option Correct(Y)
Option 1 number
Option 2 type
Option 3 number and type Y
Option 4 number, type and name
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 23
number
Question Suppose the following code segment is executed, what will be
the value of z?
int x,y,z;
x=3;
y=7;
z=9;
if (x>y)
if (x-y == 4)
z = 33;
else
z=77;
Question 24
number
Question Suppose the following code segment is executed, what will be
the value of z?
int a,b,z;
a = 1;
b = 4;
while (a<b) {
a = 2 * a;
b = b +1;
}
z = b;
Question 25
number
Question Pick the best statement for the following program.
#include <stdio.h>
int foo(int a) {
printf("%d",a);
return 0;
}
int main( ) {
foo;
return 0;
}
Option No Option Correct(Y)
Option 1 It’ll result in compile error because foo is used
without parentheses
Option 2 No compile error and some garbage value
would be passed to foo function. This would
make foo to be executed with output “garbage
integer”.
Option 3 No compile error but foo function wouldn’t be Y
executed. The program wouldn't print anything.
Option 4 No compile error and ZERO (i.e. 0) would be
passed to foo function. This would make foo to
be executed with output 0
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 26
number
Question "C is strongly typed" means...
Question 27
number
Question Which of the following could NOT be a variable name in
C?
Option No Option Correct(Y)
Option 1 1st_value Y
Option 2 v300000
Option 3 integer
Option 4 Double
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 28
number
Question What is the value of the following expression (given the
following declarations)?
int a = 8;
int b = 2;
int c = 4;
a+b/c*a-c/b
Option No Option Correct(Y)
Option 1 10.0
Option 2 4
Option 3 6 Y
Option 4 10
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 29
number
Question Which of the following was NOT given as a motivation for
using functions in programming?
Option No Option Correct(Y)
Option 1 Functions raise the level of discourse
Option 2 Functions are more efficient (run faster) than Y
the same solution without functions
Option 3 That's how modern programming is done
Option 4 Functions permit code to be shared between
programs.
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 30
number
Question Suppose x is a double. After the statements
x = 5.9;
a = (int) x;
have executed, what is the value of x?
Option No Option Correct(Y)
Option 1 5.9 Y
Option 2 5
Option 3 5.0
Option 4 6
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 31
number
Question Choose the best conclusion to the statement.
In C, the word double…
Option No Option Correct(Y)
Option 1 is a special, floating point value
Option 2 must be part of the declaration of every variable
which will hold numeric values.
Option 3 is available for use as a variable name.
Option 4 is a reserved word. Y
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 32
number
Question Suppose # is a left-associative binary operator which has
lower precedence than +. Given the following expression,
which expression is equivalent to it?
3+5#6#7
Option No Option Correct(Y)
Option 1 3 + (5 # (6 # 7))
Option 2 (3 + 5) # (6 # 7)
Option 3 3 + ((5 # 6) # 7)
Option 4 ((3 + 5) # 6) # 7 Y
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 33
number
Question For the operators *, +, /, %, -, which of the following
statements about precedence in C is true:
Option No Option Correct(Y)
Option 1 Highest +, /, *
Lowest %, -
Option 2 Highest *, /, % Y
Lowest +, -
Option 3 Highest *, %, -
Lowest /, +
Option 4 Highest *, +, %
Lowest -, /
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 34
number
Question If you see the following line in an error-free C program:
y = combine (a / b + c);
Question 35
number
Question Suppose a valid C program contains the statement
TREE = TRUNK;
Question 36
number
Question In C, the value of a condition can be thought of informally as
"yes" or "no" but is actually represented by the values
Option No Option Correct(Y)
Option 1 true or false
Option 2 TRUE or FALSE
Option 3 1 or 1
Option 4 non-zero (usually 1) or 0 Y
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 37
number
Question #include <stdio.h>
int F1 (int a) {
a = 2;
return 3;
}
Question 38
number
Question The following function is supposed to find the smallest
among four characters. Choose the best answer.
char smallest_of_4 (char c1, char c2, char c3, char c4) {
char smallest_of_1and2, smallest_of_3and4;
char smallest_of_all;
return smallest_of_all;
}
Option No Option Correct(Y)
Option 1 This function always gives the right answer. Y
Option 2 This function never gives the right answer.
Option 3 If c1 happens to be the smallest character, this
function gives the right answer (regardless of
the values of c2, c3, c4). If c1 is not the
smallest character, some values of c2, c3, or c4
will cause it to give a wrong answer.
Option 4 If c3 is less than either c1 or c2, this function
always gives the right answers. If c3 is not less
than c1 or c2, it gives some incorrect answers.
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 39
number
Question What is printed by main when this program fragment runs?
Question 40
number
Question For which values of x is the following condition true? You
may assume that x is a positive integer.
(2 % (x + 1)) > 0
Option No Option Correct(Y)
Option 1 true for all even values of x
Option 2 true for all odd values of x
Option 3 true for all positive values of x
Option 4 true when x is greater than 1 Y
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 41
number
Question Saying "A invokes B" is the same as saying
Question 42
number
Question Assume the following.
sizeof(int) = 4 bytes
sizeof(char *) = 4 bytes
sizeof(char) = 1 byte
What is the output of the code below on a 32bit machine?
Question 43
number
Question What is the output of the code below?
#include <stdio.h>
int main() {
char string[] = "BADGERS";
char *ptr = string;
*ptr = *ptr + 2;
ptr = ptr + 2;
printf("%c", *ptr);
ptr--;
printf("%c", *ptr);
ptr = string;
printf("%c", *ptr);
return 0;
}
Option No Option Correct(Y)
Option 1 DAB
Option 2 BAD
Option 3 BAB
Option 4 DAD Y
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 44
number
Question What is the size (in bytes) for the following structures on a
32bit machine installed with the Linux Operating System?
sizeof(int) = 4 bytes
sizeof(short) = 2 bytes
sizeof(char) = 1 byte
struct foo {
int d1;
int d2;
char c1;
char *c2;
short s;
};
Question 45
number
Question Suppose that x and y have byte values 0x93 and 0x3F,
respectively. Find the byte value of the following C
expression.
!x || !y
Option No Option Correct(Y)
Option 1 0 Y
Option 2 1
Option 3 Illegal Operation
Option 4 Compiler dependent
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 46
number
Question Output of the following program?
#include <stdio.h>
int main()
{
static int i=5;
if(--i){
main();
printf("%d ",i);
}
return 0;
}
Question 47
number
Question What will be the output of the following C program segment?
switch ( inChar ) {
case ‘A’ : printf (“Choice A”) ;
case ‘B’ :
case ‘D’ :
case ‘E’ :
default : printf ( “ No Choice” ) ;
}
Question 48
number
Question Consider the following program,
main( )
{
int x = 49;
for(;x;)
x--;
printf(“%d\n”, x);
}
What will be the output of the program?
Question 49
number
Question What will be the output of the following C code?
#include <stdio.h>
int main()
{
short i;
for (i = 1; i >= 0; i++)
printf("%d\n", i);
}
Option No Option Correct(Y)
Option 1 The control won’t fall into the for loop
Option 2 Numbers will be displayed until the signed limit of
short and throw a runtime error
Option 3 Numbers will be displayed until the signed limit of Y
short and program will successfully terminate
Option 4 This program will get into an infinite loop and keep
printing numbers with no errors
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply
Question Type Basic MCQ
Question 50
number
Question What will be the output of the following C code?
void main()
{
int i=5;
while(i<=10) {
(i>2)?i++:i--;
printf(“%3d”, i);
}
}
Option No Option Correct(Y)
Option 1 6 7 8 9 10 11 Y
Option 2 6 7 8 9 10
Option 3 Infinite Loop
Option 4 5 6 7 8 9 10
Option 5
Question Difficulty Level Bloom’s
Metadata Taxonomy
Easy Apply