0% found this document useful (0 votes)
8 views122 pages

TCS - D4-S2

The document contains a series of multiple-choice questions (MCQs) related to programming concepts, data types, and C language syntax. Each question is followed by four answer options, with the correct answer indicated. The content covers topics such as variable scope, recursion, data types, and code output predictions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views122 pages

TCS - D4-S2

The document contains a series of multiple-choice questions (MCQs) related to programming concepts, data types, and C language syntax. Each question is followed by four answer options, with the correct answer indicated. The content covers topics such as variable scope, recursion, data types, and code output predictions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 122

TCSTopic/Course

- Ninja
Sub-Topic (Example: name of college)

MCQs
Question 1
Neelam wants to share her code with a colleague, who may modify
it. Thus she wants to include the date of the program creation, the
author and other she wants to include the date of the program
creation, the author and other information with the program. What
component should she use?
A Header Files
)

B Iteration
)

C Comments
)

D Preprocessor Directive
)
A Header Files
)

B Iteration
)

C Comments
)

D Preprocessor Directive
)

Ans: C
Question 2
What is the output of the following code statements? The compiler
saves the first integer at the memory location 4165 and the rest at
consecutive memory spaces in order of declaration. Integer is one
byte long.
integer a
pointer c, d
a = 30c = &a
c = &a
d = c
a = a + 10
print *c
A 30
)

B 4165
)

C 40
)

D 4166
)
A 30
)

B 4165
)

C 40
)

D 4166
)

Ans: C
Question 3
A data type is stored as an 6 bit signed integer. Which of the
following cannot be represented by this data type?

A 0
)
B 32
)
C 18
)
D 64
)
Question 3
A data type is stored as an 6 bit signed integer. Which of the
following cannot be represented by this data type?

A 0
)
B 32
)
C 18
)
D 64
)
Ans: B
Question 4
A language has 28 different letters in total. Each word in the
language is composed of maximum 7 letters. You want to create a
data-type to store a word of this language. You decide to store the
word as an array of letters. How many bits will you assign to the
data-type to be able to store all kinds of words of the language
A 7
)

B 35
)

C 28
)

D 196
)
A 7
)

B 35
)

C 28
)

D 196
)

Ans: B
Question 5
A 10-bit unsigned integer has the following range

A 0 to 1000
)
B 0 to 1024
)
C 0 to 1025
)
D 0 to 1023
)
Question 5
A 10-bit unsigned integer has the following range

A 0 to 1000
)
B 0 to 1024
)
C 0 to 1025
)
D 0 to 1023
)
Ans: D
Question 6
Parul takes as input two numbers: a and b. a and b can take integer
values between 0 and 255. She stores a, b and c as 1-byte data
type. She writes the following code statement to process a and b
and put the result in c.

c = a + 2*b
To her surprise her program gives the right output with some input
values of a and b, while gives an erroneous answer for others. For
which of the following inputs will it give a wrong answer?
Question 6
Parul takes as input two numbers: a and b. a and b can take integer
values between 0 and 255. She stores a, b and c as 1-byte data
type. She writes the following code statement to process a and b
and put the result in c.

c = a + 2*b
To her surprise her program gives the right output with some input
values of a and b, while gives an erroneous answer for others. For
which of the following inputs will it give a wrong answer?
A a=10 b=200
)

B a=200 b=10
)

C a=50 b=100
)

D a=100 b=50
)
A a=10 b=200
)

B a=200 b=10
)

C a=50 b=100
)

D a=100 b=50
)

Ans: A
Question 7
Which is used to convert source code to target language?

A Linker
)
B Compiler
)
C Executer
)
D Loader
)
Question 7
Which is used to convert source code to target language?

A Linker
)
B Compiler
)
C Executer
)
D Loader
)
Ans: B
Question 8
Tricha wants to store a list of binary data. Which of following data
types should she use?

A Integer
)
B Float
)
C Character
)
D Boolean
)
Question 8
Tricha wants to store a list of binary data. Which of following data
types should she use?

A Integer
)
B Float
)
C Character
)
D Boolean
)

Ans: D
Question 9
Which of the following options is an exception to being a part of
composite data types?

A Union
)
B Array
)
C Structure
)
D Stack
)
Question 9
Which of the following options is an exception to being a part of
composite data types?

A Union
)
B Array
)
C Structure
)
D Stack
)

Ans: D
Question 10
The data type is store as 6 but unsigned integer. Which of the
following can't be represented by the this data type:

A -12
)
B 0
)
C 32
)
D 18
)
Question 10
The data type is store as 6 but unsigned integer. Which of the
following can't be represented by the this data type:

A -12
)
B 0
)
C 32
)
D 18
)

Ans: A
Question 11
What is the difference between a function and a method?

A Function is a named code unlike method which is a part of an


) object
B Function contained in an object is called a method
)
C Function cannot change variables outside its scope unlike
) method
D There is no difference between the two
)
Question 11
What is the difference between a function and a method?

A Function is a named code unlike method which is a part of an


) object
B Function contained in an object is called a method
)
C Function cannot change variables outside its scope unlike
) method
D There is no difference between the two
)

Ans: A
Question 12
getc() returns EOF when

A) End of files is reached


B) When getc() fails to read a character
C) Both of the above
D) None of the above
Question 12
getc() returns EOF when

A) End of files is reached


B) When getc() fails to read a character
C) Both of the above
D) None of the above

Ans: C
Question 13
What is the term given to the variable whose scope is beyond all
the scopes i.e., it can be accessed by all the scopes?

A Universal Variable
)
B Global Variable
)
C External Variable
)
D Auto Variable
)
Question 13
What is the term given to the variable whose scope is beyond all
the scopes i.e., it can be accessed by all the scopes?

A Universal Variable
)
B Global Variable
)
C External Variable
)
D Auto Variable
)
Ans: B
Question 14
Consider the following code:

#include<stdio.h> int modify(int a,int b)


int modify(int,int); {
int main() int c,d=2;
{ c=a*d+b;
int a=5,b=20,c; return c;
int d=10; }
c=modify(a,b);
c=c+d;
printf("%d",c);
return 0;
}
A 80
)

B 40
)

C 32
)

D 72
)
A 80
)

B 40
)

C 32
)

D 72
)

Ans: B
Question 15
Choose the correct answer.
Tanuj writes the code for a function that takes as input n and
calculates the sum of first n natural numbers

Function sum( n )
{
if(??)
return 1
else
return (n + sum(n-1))
end
}
Fill in ?? in the code:-

A N equal 1
)

B N equal 2
)

C N>=1
)

D N>1
)
Question 16
Choose the correct answer.
Shrishti writes the code for a function that computes the factorial
of the inputted number n.

function factorial(n)
{
if(n equals 1)
return 1
else
— MISSING STATEMENT —
end
}
Fill in the missing statement:-

A return factorial(n-1)
)

B return n*factorial(n)
)

C return n*(n-1)
)

D return n*factorial(n-1)
)
Fill in the missing statement:-

A return factorial(n-1)
)

B return n*factorial(n)
)

C return n*(n-1)
)

D return n*factorial(n-1)
)
Ans: D
Question 17
Choose the correct answer. Saumya writes a code which has a
function which calls itself. Which programming concept is Saumya
using?
A This is bad programming practice and should not be done
)
B Recursion
)
C Decision Making
)
D Overloading
)
Question 17
Choose the correct answer. Saumya writes a code which has a
function which calls itself. Which programming concept is Saumya
using?
A This is bad programming practice and should not be done
)
B Recursion
)
C Decision Making
)
D Overloading
)
Ans: B
Question 18
What type of value does sizeof() return?

A) char
B) short
C) Unsigned int
D) long
Question 18
What type of value does sizeof() return?

A) char
B) short
C) Unsigned int
D) long

Ans: C
Question 19
What will be output of the following program

#include<stdio.h>
int main()
{
float a[]={12.4,2.3,4.5,6.7};
printf("%d,%d",sizeof(a),sizeof(a[0]));
return 0;
}
A 16bytes, 4bytes
)

B 14bytes, 4bytes
)

C 8bytes, 4bytes
)

D None of these
)
A 16bytes, 4bytes
)

B 14bytes, 4bytes
)

C 8bytes, 4bytes
)

D None of these
)

Ans: A
Question 20
Choose the correct answer.

function g(int n)
{
if (n > 0) return 1;
else return -1;
}

function f(int a, int b)


{
if (a > b) return g(b-a);
if (a < b) return g(a-b);
return 0;
}
If f(a,b) is called, what is returned?

A Always -1
)
B 1 if a>b, -1 if a<b, 0 otherwise
)

C -1 if a>b, 1 if a<b, 0 otherwise


)

D 0 if a equals b, -1 otherwise
)
If f(a,b) is called, what is returned?

A Always -1
)
B 1 if a>b, -1 if a<b, 0 otherwise
)

C -1 if a>b, 1 if a<b, 0 otherwise


)

D 0 if a equals b, -1 otherwise
)
Ans: D
Question 21
Choose the correct answer.

Afzal writes a piece of code, where a set of three lines occur around
10 times in different parts of the program. What programming
concept can he use to shorten his program code length?
A Use for loops
)

B Use functions
)

C Use arrays
)

D Use classes
)
A Use for loops
)

B Use functions
)

C Use arrays
)

D Use classes
)

Ans: B
Question 22
Talika wants to implement heterogeneous linked list for her project.
Which of the following will help her do the same?

A Void Pointer
)
B NULL Pointer
)
C Wild Pointer
)
D Heterogeneous lists follows the same procedure as the
) homogeneous.
Question 22
Talika wants to implement heterogeneous linked list for her project.
Which of the following will help her do the same?

A Void Pointer
)
B NULL Pointer
)
C Wild Pointer
)
D Heterogeneous lists follows the same procedure as the
) homogeneous.
Ans: A
Question 23
Which is correct with respect to size of the datatypes?

A char > int > float


)
B int > char > float
)
C char < int < double
)
D double > char > int
)
Question 23
Which is correct with respect to size of the datatypes?

A char > int > float


)
B int > char > float
)
C char < int < double
)
D double > char > int
)
Ans: C
Question 24
The format identifier ‘%i’ is also used for _____ data type?

A char
)
B double
)
C float
)
D int
)
Question 24
The format identifier ‘%i’ is also used for _____ data type?

A char
)
B double
)
C float
)
D int
)
Ans: D
Question 25
What will be the output?

#include <stdio.h>
int main()
{
int main = 5;
printf("%d", main);
return 0;
}
A compile-time error
)

B run-time error
)

C run without any error and prints 5


)

D experience infinite looping


)
A compile-time error
)

B run-time error
)

C run without any error and prints 5


)

D experience infinite looping


)

Ans: C
Question 26
Which of the following is true for variable names in C?

A They can contain alphanumeric characters as well as special


) characters
B It is not an error to declare a variable to be one of the
) keywords(like goto,
static)
C Variable names can't start with a digit
)
D Variable can be of any length
)
Question 26
Which of the following is true for variable names in C?

A They can contain alphanumeric characters as well as special


) characters
B It is not an error to declare a variable to be one of the
) keywords(like goto,
static)
C Variable names can't start with a digit
)
D Variable can be of any length
)
Ans: C
Question 27
The output of this C code is?

#include <stdio.h>
void main()
{
int i = 0;
if (i == 0)
{
printf("Hello");
break;
}
}
A Hello is printed infinite times
)

B Hello
)

C Varies
)

D Compile time error


)
A Hello is printed infinite times
)

B Hello
)

C Varies
)

D Compile time error


)

Ans: D
Question 28
The output of this C code is?

#include <stdio.h>
int main()
{
int i = 0;
do{
i++;
printf("Inside while loop\n");
}while (i < 3);
}
A Inside while loop
) Inside while loop
Inside while loop
B Inside while loop
) Inside while loop

C Depends on the compiler


)

D Compile time error


)
A Inside while loop
) Inside while loop
Inside while loop
B Inside while loop
) Inside while loop

C Depends on the compiler


)

D Compile time error


)

Ans: A
Question 29
The output of this C code is?

#include <stdio.h>
int main()
{
do
printf("Inside while loop ");
while (0);
printf("Outside loop\n");
}
A Inside while loop
)

B Inside while loop


) Outside loop

C Outside loop
)

D Infinite loop
)

Ans: B
Question 30
The output of this C code is?

#include <stdio.h>
void main()
{
double x = 0;
for (x = 0.0; x < 3.0; x++)
printf("Hello");
}
A Run time error
)

B Hello is printed thrice


)

C Hello is printed twice


)

D Hello is printed infinitely


)
A Run time error
)

B Hello is printed thrice


)

C Hello is printed twice


)

D Hello is printed infinitely


)

Ans: B
Question 31
The output of this C code is?

#include <stdio.h>
void main()
{
int x = 0;
for (x < 3; x++)
printf("Hello");
}
A Compile time error
)

B Hello is printed thrice


)

C Nothing
)

D Varies
)
A Compile time error
)

B Hello is printed thrice


)

C Nothing
)

D Varies
)

Ans: A
Question 32
What is the problem in the following declarations?

int func(int);

double func(int);

int func(float);
A A function with same name cannot have different signatures
)

B A function with same name cannot have different return types


)

C A function with same name cannot have different number of


) parameters

D All of the mentioned


)
A A function with same name cannot have different signatures
)

B A function with same name cannot have different return types


)

C A function with same name cannot have different number of


) parameters

D All of the mentioned


)

Ans: D
Question 33
In 2 Dimensional Array, it is necessary to mention _______
dimension.

A second
)
B first
)
C both
)
D none of these
)
Question 33
In 2 Dimensional Array, it is necessary to mention _______
dimension.

A second
)
B first
)
C both
)
D none of these
)

Ans: A
Question 34
An array can be passed to a function by __________

A Call by reference
)
B call by value
)
C Call by reference by passing base address to a function
)
D Both a and c
)
Question 34
An array can be passed to a function by __________

A Call by reference
)
B call by value
)
C Call by reference by passing base address to a function
)
D Both a and c
)

Ans: A
Question 35
What is the output of this C code?

#include<stdio.h>
int main()
{
int arr[4]={3,4,5,6};
int k[4];
k=arr;
printf("%d\n",k[1]);
}
A Compile Time Error
)

B 4
)

C No output
)

D Program crashes
)
A Compile Time Error
)

B 4
)

C No output
)

D Program crashes
)

Ans: A
Question 36
What will be output of the following program

#include<stdio.h>
int main()
{
int a[5],i=0;
while(i<5)
a[i]=++i;
for(i=0;i<5;i++)
printf("%d,",a[i]);
}
A garbage value,1,2,3,4
)

B 1,2,3,4,5
)

C Error
)

D Program crash
)
A garbage value,1,2,3,4
)

B 1,2,3,4,5
)

C Error
)

D Program crash
)

Ans: A
Question 37
What happen if we assign a value to an array element whose
subscript exceeds the size of array?

A The program will give error


)
B No output
)
C program will crash
)
D None of these
)
Question 37
What happen if we assign a value to an array element whose
subscript exceeds the size of array?

A The program will give error


)
B No output
)
C program will crash
)
D None of these
)
Ans: C
Question 38
If array is initialized where it is declared, then mentioning
__________ of array is optional.

A Data type
)
B Dimension
)
C name
)
D Data type and Dimension
)
Question 38
If array is initialized where it is declared, then mentioning
__________ of array is optional.

A Data type
)
B Dimension
)
C name
)
D Data type and Dimension
)
Ans: B
Question 39
Till the array elements are not given any specific value, they are
supposed to
contain all ____________
A Zero
)
B Garbage value
)
C One
)
D Combination of zero and one
)
Question 39
Till the array elements are not given any specific value, they are
supposed to
contain all ____________
A Zero
)
B Garbage value
)
C One
)
D Combination of zero and one
)
Ans: B
Question 40
An array is also known as ___________

A Subscripted variable
)
B Collective array
)
C Ordinary variable
)
D Similar Quantities variable
)
Question 40
An array is also known as ___________

A Subscripted variable
)
B Collective array
)
C Ordinary variable
)
D Similar Quantities variable
)
Ans: A
Question 41
What is the output of this C code?

#include <stdio.h>
void main()
{
int x = 97;
int y = sizeof(x++);
printf("x is %d", x);
}
A x is 97
)

B x is 98
)

C x is 99
)

D Run time error


)
A x is 97
)

B x is 98
)

C x is 99
)

D Run time error


)

Ans: A
Question 42
Which of the following statement is true about C language ?

A A static function can return only a static variable


)
B A static variable can be declared only inside a static function
)
C Variables passed to a static function should also be static
)
D None of the above
)
Question 42
Which of the following statement is true about C language ?

A A static function can return only a static variable


)
B A static variable can be declared only inside a static function
)
C Variables passed to a static function should also be static
)
D None of the above
)
Ans: D
Question 43
Which of the following statement is true about C language ?

A main() function should always be the first function present in a


) C program.
B All the elements of an union do not share their memory location
)
C A void pointer can hold the address of any type and can be
) typecasted to any type
D A static variable hold random junk value if it is not initialized
)
Question 43
Which of the following statement is true about C language ?

A main() function should always be the first function present in a


) C program.
B All the elements of an union do not share their memory location
)
C A void pointer can hold the address of any type and can be
) typecasted to any type
D A static variable hold random junk value if it is not initialized
)

Ans: C
Question 44
To print a double value which format specifier should be used?

A) %lf
B) %Lf

C) %f

D) %df
Question 44
To print a double value which format specifier should be used?

A) %lf
B) %Lf

C) %f

D) %df
Ans: A
Question 45
Which of the following statement is true about C language ?

A C language is not strict about indentation and alignment of if,


) for, while and do while statement
B The loop counter in a for loop should be of int data type only
)
C "=="operator is used to assign an exact value with correct
) accuracy
D Under special conditions keywords can be used as variable
) name
Question 45
Which of the following statement is true about C language ?

A C language is not strict about indentation and alignment of if,


) for, while and do while statement
B The loop counter in a for loop should be of int data type only
)
C "=="operator is used to assign an exact value with correct
) accuracy
D Under special conditions keywords can be used as variable
) name
Ans: A
Question 46
Which of the following statement is true about C language ?

A C language allows negative index values in an array


)
B Function rewind() makes execution of the program restart from
) the beginning
C We can not use any name in place of argv and argc as command
) line argument
D Constant pointer and pointer to a constant are the same
)
Question 46
Which of the following statement is true about C language ?

A C language allows negative index values in an array


)
B Function rewind() makes execution of the program restart from
) the beginning
C We can not use any name in place of argv and argc as command
) line argument
D Constant pointer and pointer to a constant are the same
)
Ans: A
Question 47
Which of the following statement is true about C language ?

A Realloc can be used to change size of an array


)
B If a function explicitly does not return a value, then default
) value 0 will return
C Unary operator takes only one operand
)
D It is not possible to write a working program in C without using
) semicolon
Question 47
Which of the following statement is true about C language ?

A Realloc can be used to change size of an array


)
B If a function explicitly does not return a value, then default
) value 0 will return
C Unary operator takes only one operand
)
D It is not possible to write a working program in C without using
) semicolon

Ans: C
Question 48
Which of the following statement is true about static variable?

A A variable that is static is assigned on address at compile time


)
B A static variable inside a function keep the values between
) invocation
C A static variable will auto initialize to zero at the start of the
) program/function
D All of the above
)
Question 48
Which of the following statement is true about static variable?

A A variable that is static is assigned on address at compile time


)
B A static variable inside a function keep the values between
) invocation
C A static variable will auto initialize to zero at the start of the
) program/function
D All of the above
)

Ans: D
Question 49
Which of the following statement is true about arrays and pointer?

A An array memory size can be modify using pointer


)
B Array has fixed memory size whereas pointer can point on array
) size as we required at runtime
C Both array and pointer can be resize using realloc()
)
D None of the above
)
Question 49
Which of the following statement is true about arrays and pointer?

A An array memory size can be modify using pointer


)
B Array has fixed memory size whereas pointer can point on array
) size as we required at runtime
C Both array and pointer can be resize using realloc()
)
D None of the above
)

Ans: B
Question 50
Memory allocation using malloc() is done in?

A) Static area
B) Heap area
C) Both a and b
D) None
Question 50
Memory allocation using malloc() is done in?

A) Static area
B) Heap area
C) Both a and b
D) None

Ans: B
THANK YOU

You might also like