Вы находитесь на странице: 1из 99

Table of Contents

SET 1: 2018012ALL ....................................................................................... 1

SET 2: 2018002PRIYA.................................................................................. 18

SET 1: 2018012ALL
1) Where the local variables are stored?
a) Disk
b) stack
c) heap
d) 13

2) which of the following indicate the end of the file ?


a)Feof()
b)EOF
c)both feof() and EOF
d)none of the mentioned options

3) When reading from a file, to test whether we have reached its end, which function can be
used?
a) eof()
b) endOfFile()
c) feof()
d) fend()

4) If a function‘s return type is not explicitly defined then it‘s default to __( in C)
a) Int
b) float
c) void
d) error

5) Select the missing statement ?


#include<stdio.h>
long int fact(int n)
int main()
{
\\missing statement
}
long int fact(int n)
{
if(n>=1)
return n*fact(n-1);
else
return 1;
}
a)printf(―%ll\n‖,fact(5));
b)printf(―%u\n‖,fact(5));
c)printf(―%d\n‖,fact(5));
d)printf(“%ld\n”,fact(5));

6) How many times the below loop will be executed?


#include<studio.h>
int main ( ) {
int x,y ;
for (x=5;x>=1;x--)
{
for(y=1;y<=x;y++)
printf(―%d\n‖,y);
}
}
a)15
b)10
c)11
d)13

7) Which datatype has more precision?


(a) double
(b) float
(c) insigned longint
(d) long int

8) Which of the following is user-defined data type?


a) Long int
b) double
c) enum
d) unsigned long int

9) What will be the output/error?(for input 6,9)


#include<stdio.h>
int fg(int,int)
int main()
{
int n1,n2,g;
scanf(%d%d‖,&n1,&n2);
g=fg(n1,n2);
printf(―%d‖,g);
}
int fg(int x,int y)
{
while(x!=y)
{
if(x>y)
return fg(x-y,y);
else
return fg(x,y-x);
}
return x;
}
a) 3
b) 6
c) 9
d) error

10) What is the dangling pointer?


A. points to garbage value
B. points to function
C. both a and b
D. none of the above

11) A dangling pointer is


A. pointer whose value is fixed
B. pointer that does not point to a valid memory location
C. pointer that has been wrongly assigned multiple memory locations
D. pointer that cannot be made to point to alternative memory location

12) int main(int argc, char **argv)


Comment about : char ** argv
a)Pointer to pointer
b) it is the file name and argument passed
c) it is an array of character pointers
d) Compile time error

13) main(int argc, char**argv)


In the above definition of main function the variable argv denotes…
a) An array of character pointers each pointing to the command line parameters
b) An array of character pointers the first array item pointing to the program name and
the remaining pointing to the command line parameters
c) A pointer to character that points to command line parameter
d) A pointer to a pointer to the points to the memory location where the program has been
loaded into the memory

14) How to release the dynamic memory?


a)Free( )
b) truncate( )
c) delete( )
d) release( )

15) What library function is used to release the allocated memory in C?


a) Dalloc()
b) Release()
c) Free()
d) Freemem()

16) What is the purpose of ftell?


A. to get the current file name
B. to get the current file status
C. to get the current file attribution
D. to get the current file position

17) What is recursion?


A. looping
B. a function calls another function repeatedly
C. function calls repeatedly
D. function call itself repeatedly

18) What is the similarity between enum and structure?


A. can assign new values
B. can create new data types
C. nothing is common
D. they are same
STAR QUESTION
19) What will be the output of the below code
# include <stdio.h>
int main()
{
float f = 0.1;
if (f ==0.1)
printf(―YES\n‖);
else
printf(―NO\n‖);
return 0;
}
ANS:NO

20) What will be the output of the below code


# include <stdio.h>
int main()
{
float f=0.1;
if (f ==0.1)
printf(―NO\n‖);
return 0;
}
a) NO
b) ERROR
c) NO OUTPUT
d) Successfully compiled but no Output

21) A memory leak happens when?


A. a program allocates memory in heap but forget to delete it
B. a program allocate memory in stack
C. when an un signed pointer is freed using free function
D. when reallocate () is called on a pointer that is not allocated

22) Which of the below is NOT a fundamental data type


a. Unsigned long int
b. Enum
c. Long int
d. double
23) The similarity between a structure, union and enumeration is?
a. All of them let us design new pointers.
b. All of them let us design new values.
c. All of them let us design new data types.
d. Size of all of them do not vary from program to program.

24) In the below code, what concept is used


# include <stdio.h>
long int fact (int n);
int main ( )
{
int n;
printf ( ― Enter a positive integer:‖);
scanf (― %d ‖, &n);
printf (― Factorial of %d = %1d‖, n , fact(n));
return 0;
}
long int fact ( int n )
{
if ( n >= 1)
return n * fact ( n – 1);
else
return 1;
}
a. Iteration
b. Segmentation
c. Encapsulation
d. Recursion

a)Function calls from one to other function


b) Repeatedly calls itself(recursive)
c) Conditional looping

25) Which of the following is the correct order of evaluation for the below expression?
z=x+y*z/4%2-1
[A].* / % + - =
[B].= * / % + -
[C]./ * % - + =
[D].* % / - + =
26) How many times Hello will print?
#include <stdio.h>
int main (void)
{
int I;
for (i=0;i-5;i--);
{
printf(―Hello‖);
}
}
A. compilation error
B. 1
C. 4
D. runtime error

27) How many times loop will be executed?


#include<stdio.h>
int main( )
{
int i;
for(i=0;i<5;i++)
{
printf("Hello\n");
}
}
A)5
B)1
C)0
D)3

28) How many times Hello will print?


#include<stdio.h>
int main( )
{
int i;
for(i=0;i<5;i++);
{
printf("Hello");
}
}
A. compilation error
B. 1
C. 4
D. runtime error

29) Which of the following statement is true about the c language?


A.(void *)0 is different from a null pointer (wikepedia says this is wrong)
B.null pointer is another name for un initialized pointer
C.calloc() can be used only for character pointer allocation
D.char* i=0 and char *i= null means the same

STAR QUESTION
30) In the below program expects the user to enter a word. If the user enter the word as
MADAM what is the output value printed:
#include <stdio.h >
#define MAX 20
Char*fn(char []);
Int main(){
Char str[MAX],*rev;
Printf(―Enter a word of size not more than 15 characters:‖);
Scanf(―%s‖,str);
r-fn(str);
printf(―%s\n‖,r);
return 0;
}
Char* fn (char str[]){
Static int i=0;
Static char r [MAX];
If (*str){
Fn (str+1);
r[i++]=*str;
}
Return r;
}
ANS: COMPILATION ERROR. Variable “r” is not declared.

31) In the below program expects the user to enter a word. If the user enter the word as
HELLO what is the output value printed:
#include <stdio.h >
#define MAX 20
Char*fn(char []);
Int main(){
Char str[MAX],*rev;
Printf(―Enter a word of size not more than 15 characters:‖);
Scanf(―\a‖,str);
r-fn(str);
printf(―\s\n‖,r);
return 0;
}
Char* fn (char str[]){
Static int i=0;
Static char r [MAX];
If (*str){
Fn (str+1);
r[i++]=*str;
}
Return r;
}
ANS: COMPILATION ERROR. Variable “r” is not declared.

STAR QUESTION
32) What is the if size for char is 1, int is 4,double is 8?
#include<stdio.h>
union u
{
int i;
char c;
double d;
};
int main()
{
union ui, u1;
printf(―%d‖,sizeof(u1));
return 0;
}
Ans.Error

33) atoi() function is used to


A. gets index value of character in an array
B. converts ASCII character to its integer value
C. converts an array of characters to array of equivalent integer
D. convert a character string to its equivalent integer value

34) Which has the highest precision?


a)Float
b) Double
c) unsigned long int
d) long int

35) Which of the following functions is NOT declared in string.h?


a)Strcpr ( )
b)strcpy ( )
c) strlen ( )
d) strptr()

36) While declaring parameters for main, the second parameter argv should be declared as
A.char arg
B.char argv[]
C. char argv[]
D.char**argv[]

37) Which of the following statement is true about C language?


a.There is a maximum limit to number of case instance inside a switch statements
b.Two case constant within the same statements can have the same value
c. Do while loop is used to ensure that the statements within the loop are executed at least
twice
d.Continue keyword skips one iteration of loop

38) What does the default header file contain?


a)Prototypes
b) Declaration
c) implementations
d) all the above

STAR QUESTION
39) In the below code the program expects the user to enter a word. If the user enters the
word as ABRACADABRA what is the output value printed?
#include<stdio.h>
#define MAX 20
char *fn(char( ) );
int main( )
{
char str[MAX], * rev;
Printf(― Enter word size not more than 15 characters: ‖);
Scanf(―%s‖,str);
r= fn(str);
printf(―%s\n‖,r);
return 0;
}
char* fn(char str( ) )
{
static int 1=0;
static char r[MAX];
if(*str)
{
fn(str+1);
r[i++]=*str;
}
return r;
}
ANS: COMPILATION ERROR. Variable “r” is not declared.

40) Which of the below statements is true (need to check)


a. None of the other three choices
b. A static function can return only a static variable
c. A static variable can be declared only inside a static function
d. Variables passed to a static function should also be static

41) The output of the below program :


# include <stdio.h>
int main ()
{
int n, ch;
for (n=7; n!=0; n --)
printf (―n = %d‖, n --);
ch = getchar();
return 0;
}
a) Numbers 7 to 1 in descending order
b) Numbers 7 to 0 in descending order
c) None of the other 3 choices as there is a compilation error
d) Infinite loop. Program never ends

42) Given the below statements about C programming language;


1) main() function should always be the first function present in a C program file
2) all the elements of an union share their memory location
3) A void pointer can hold address of any type and can be typcasted to any type
4) A static variable hold random junk value if it is not initialised
Which of the above are correct statements?
A) 2,3
B) 1,2
C) 1,2,3
D) 1,2,3,4

43) #include<stdio.h>
#include<stdlib.h>
Int main(argc, argv)
int argc;
char **argv;
{
FILE fp; - Error (it should be File *fp
fp=fopen(―foo‖, ―r‖); - Error
if(!fp)
{
printf(―unable to open file‖);
exit(1);
}
fclose(fp);
return 0;
}
In the above code, there is an error at line number_______
a) No error
b) Line 5
c) Line 8
d) Line 7

44) #include<stdio.h>
void fn(int **p);
int main()
{
int a[3][4]={1,2,3,4,5,6,7,8,9,10,11,12};
int *ptr;
ptr=&a[0][0];
fun(&ptr);
return 0;
}
void fun(int **p)
{
printf(―%d\n‖,**p);
}
The output of the above code will be ______
a) 2
b) The code has a error and hence will not run
c) 1
d) 0

STAR QUESTION

45) In the below code, the program expects the user to enter one number. if the user enters
the number as 13 what is the output value printed:
#include <stdio.h>
int fn(int,int);
int main()
{
int num, p;
printf(‗enter a positive integer : ―);
scanf (―%d‖, &num);
p = fn(num,num/2);
printf (―%d\n‖,p);
return 0;
}
int fn (int num,int i)
{
if(i==1)
{
return 1;
}
else
{
if (num% i==0)
return 0;
else
fn( num,i-1);
}}
// Answer : 1
Note : fn is a function to check whether input is prime or not.
fn (13, 6);
fn (13, 5);
fn (13, 4);
fn (13, 3);
fn (13, 2);
fn (13, 1); returns 1;

46) 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
statement TRUE
b. The loop counter in a for loop should be of int data type only - FALSE
c. "= =" operator is used to assign an exact value with correct accuracy. FALSE
d. Under special conditions keywords can be used as variable name. FALSE

47) Which of the below statements is true?


a. C language allows negative index values in an array. - TRUE
b. Function rewind() makes execution of the program restart from the beginning - FALSE
c. We cannot use any name in place of argv and argc as command line arguments - FALSE
d. Constant pointer and pointer to a constant are the same. - FALSE

48) 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 dose 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

49) Which of the following below about static variable is true?


a. A variable that is static is assigned on address at build [compile, link]time
b. A static variable inside a function keep the values between invocation
c. All of the three statement are true
d. A static variable will auto initialize to zero at the start of the program/function
50) Which of the statement about array and pointer is correct?
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 run time
c. Both array and pointer can be resize using realloc()
d. None of other three options are correct
51) Recursion is when
a. A dummy function is executed to create time delays
b. A function calls another function without passing any parameters
c. A block of code is executed multiple times based on a condition
d. A function calls itself
52) To print a double value which format specifier should be used?
a. %lf
b. %Lf
c. %f
d. %df
53) #include<stdio.h>
main(int argc, char **argv)
{
puts(argv[argc] );
}
The above C program is compiled and executable is named as test.
It is then invoked in command line as below :
Test 1 2 3 4 5
What will be the value of argv that will be printed?
a. 5
b. Run time error
c. No output
d. 1
54) What will be output of the program ?
#include<stdio.h>
main()
{
static int a=2,b= 4,c= 8;
static int *arr1[2] ={&a, &b};
static int *arr1[2] ={&b, &c};
int* (*arr[2] *arr1[2] )[2] = {&arr1, &arr2};
printf(―%d‖, *(*(**(arr +1)+1) ) ) ;
}
55) To write a struct into a file in C language, we can use
a. fwrite()
b. Not possible to write composite data types
c.
d. fputc()
56) A program tried to compile and link the below code. What he would have encountered ?
main()
{
int i=10;
printf(―%d‖,i);
}
a. Run time error as stdio.h is not present
b. Compile time error as stdio.h is not included
c. Compile error as there is no returns statement in the main function
d. Program would have printed 10
57) What will be the output of the below program?
#include <stdio.h>
Main ()
{
static int a=2, b=4, c=8;
static int *arr1[2]=(&a, &b);
static int *arr2[2]=(&b, &c);
int* (*arr[2]) [2]=(&arr 1, &arr2);
printf(―%d‖, *(*(**(arr+1)+1))):
}
58) #include <stdio.h>
Main (int argc, char ** argv)
{
puts (argv[argc]);
}
The above program is complied and executable is named as test. It is then invoked in
command line as below:
Test 1 2 3 4 5
What will be the value of argv that will be printed?
a) 5
b) Run time error
c) No output
d) 1
59) #include
int main(){
float a=5.89
printf(%.0f,a);
}
a) 6
b) 2.89
c)2.890000
d)it has no conio.h so its error

60)
int a=5;
char c='c';
printf("%d",a+c);
a) compiles and runs
b) compilation error
c) integer and character cannot be added
d) conio.h is not given so error

61) Eesha writes function and save as file.c but she forget to call the function
a) programs compiles and runs
b) it compiles but causes runtime error
c)run time error

62) Which of the following is correct


i) (a=b)? (c==d):(e==f)
ii) (a==b)?(c=d):(e=f)
iii) (a=b)?(c=d):(e=f)
iv) (a==b)?(c==d):(e==f)
a) i is correct
b) i and ii is correct
c) ii and iv is correct
d) all the above.

63) which is true?


i) global variable can't start auto variable
ii)local variable are static
iii)extern are auto variable
iv) all the above
64) #include<stdio.h>
int main()
{
static int i;
int j;
for(j=0;j<10;j++)
{
i+=2;
i-=j;
}
printf("%d",i) ;
}
a) - 27 b) - 25 c) cannot be determined d) – 21

SET 2: 2018002PRIYA
TCS DATA TYPE QUESTIONS WITH SOLUTIONS
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
Answer: D
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.
A.30
B.4165
C.40
D.4166
Answer: C
3.A data type is stored as an 6 bit signed integer. Which of the following cannot be
represented by this data type?
A. -12
B. 0
C.32
D.18
E.64
Answer: c
4.A language has 28 different letters in total. Each word in the language iscomposed of
maximum 7 letters. You want to create a data-type to store a word ofthis 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
Answer: b
5. A 10-bit unsigned integer has the following range:
a.0 to 1000
b.0 to 1024
c.1 to 1025
d.0 to 1023
Answer: D
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 = 100D
d. a = 100 b = 50
Answer: a
7.Which is used to convert source code to target language
a. linker
b. compiler
c. executer
d. loader
Answer: b
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
Answer: d
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
Answer: d
10. The datatype is store as 6 but unsigned integer. Which of the following can‘t be
represented by the this datatype:
a. -12
b. 0
c. 32
d. 18
Answer: a
TCS PROGRAMMING QUESTIONS ON FUNCTIONS AND SCOPE – 1
11.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
Answer: b
12. Consider the following function function calculate( n ) { if(n equals 5) return 5 else return
(n + calculate(n-5)) end } Shishir calls the function by the statement, calculate(20). What value
will the function return?
a. 50
b. 200
c. 35
d. 20
Answer: a
13. 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
Answer: d
14.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
Answer: b
15. 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 list follows the same procedure as the homogeneous list. Hence no different
pointer is required.
Answer: a
TCS PROGRAMMING QUESTIONS ON FUNCTIONS AND SCOPE – 2
16. 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
Answer : a
17. Consider the following code:
function modify(a,b)
{
Integer c,d=2
c= a*d+ b
return c
}
function calculate()
{
integer a = 5, b = 20, c
integer d= 10
c = modify(a, b);
c = c+ d
print c
}
a. 80
b. 40
c. 32
d. 72
Answer: b
Explaination : c=? d=2 c=a*d+b c=a*2+b then a=5 b=20 , c=? c=c+d c=a*2+b+d
c=5*2+20+10=40
18. 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
Answer : b
19.Anu wants to make a function that is not bound to any identifier.which of the following
functions should she incorporate in her program?
a. Anonymous Function
b. Friend Function
c. Null Function
d. Global Function
Answer: a
20. Which of the following accessibility modes can be the specifier of a top level class‘?Top-
level classes can only have public, abstract, and final modifiers, and it is also possible to not
define any class modifiers at all. This is called default/package accessibility. Besides that,
private, protected, and static modifiers cannot be used when declaring top-level classes.
Private, Protected, Public, No Modifier
a. Only Private
b. Protected and Private
c. Public and No Modifier
d. Only No Modifier
Answer: c
21. Top-level classes can only have public, abstract, and final modifiers, and it is also possible
to not define any class modifiers at all. This is called default/package accessibility. Besides
that, private, protected, and static modifiers cannot be used when declaring top-level classes.
Question 6 WRONG
Which of the following accessibility modes can be the specifier of a top level class‘?Top-level
classes can only have public, abstract, and final modifiers, and it is also possible to not define
any class modifiers at all. This is called default/package accessibility. Besides that, private,
protected, and static modifiers cannot be used when declaring top-level classes. Private,
Protected, Public, No Modifier
a. Only Private
b. Protected and Private
c. Public and No Modifier
d. Only No Modifier
Answer:c
22.Top-level classes can only have public, abstract, and final modifiers, and it is also possible
to not define any class modifiers at all. This is called default/package accessibility. Besides
that, private, protected, and static modifiers cannot be used when declaring top-level classes.
Question 7 WRONG
Choose the correct answer. A pseudo-code which is similar to that of C++ and self-explanatory
An accessible member function or data member for an object are accessed by the statement
objectname.functionname or objectname. data member name respectively. class brush {
Private: integer size, colorcode function getdata( ) {–}//Statement 1 public: integer name //
Statement 2 function putdata(){…} } function main { brush b1, b2 print bl.name //Statement 3
b2.getdata() //Statement 4 } Deleting which line will correct the error in the code?
a.Statement 1
b.Statement 2
c.Statement 3
d.Statement 4
Answer:d
Explaination : Since, get data is private
23.Function MyDisplay(string MyStr) //statement 1 { print ―Hello !‖ print MyStr return 1 //
statement 2 } function main() //statement 3 { string str= ―Mickey‖ MyDisplay(str) // statement
4 } Which statement will generate an error.
a.Statement 1
b.Statement 2
c.Statement 3
d.Statement 4
Answer:b
24.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 equals 1
b. n equals 2
c. n >= 1
d. n > 1
Answer: a
25.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)
Answer: d
TCS C PROGRAMMING QUESTIONS ON FILE HANDLING

26. The value of EOF is_____


a) -1
b) 0
c) 1
d) 10
Answer:a
27. Which of the following true about FILE *fp
a) FILE is a keyword in C for representing files and fp is a variable of FILE type.
b) FILE is a structure and fp is a pointer to the structure of FILE type
c) FILE is a stream
d) FILE is a buffered stream
Answer:b
Explanation: fp is a pointer of FILE type and FILE is a structure that store following
information about opened file.
28. The first and second arguments of fopen are ______
a) A character string containing the name of the file & the second argument is the mode
b) A character string containing the name of the user & the second argument is the mode
c) A character string containing file poniter & the second argument is the mode
d) None of the mentioned
Answer:a
29. If there is any error while opening a file, fopen will return
a) Nothing
b) EOF
c) NULL
d) Depends on compiler
Answer:c
30. fseek() should be preferred over rewind() mainly because
a) rewind() doesn‘t work for empty files
b) rewind() may fail for large files
c) In rewind, there is no way to check if the operations completed successfully
d) All of the above
Answer:c
31. FILE is of type ______
a) int type
b) char * type
c) struct type
d) None of the mentioned
Answer:c
32. FILE reserved word is
a) A structure tag declared in stdio.h
b) One of the basic datatypes in c
c) Pointer to the structure defined in stdio.h
d) It is a type name defined in stdio.h
Answer:d
33. 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
Answer:c
34. Which of the following functions from ―stdio.h‖ can be used in place of printf()?
a) fputs() with FILE stream as stdout.
b) fprintf() with FILE stream as stdout.
c) fwrite() with FILE stream as stdout.
d) All of the above three – a, b and c.
e) In ―stdio.h‖, there‘s no other equivalent function of printf()
Answer:b
35. fputs adds newline character
a) True
b) False
c) Depends on the standard
d) Undefined behaviour
Answer:b
36. puts function adds newline character
a) True
b) False
c) Depends on the standard
d) Undefined behaviour
Answer:a
TCS ARRAY QUESTIONS

37) An array is also known as ___________


a) Subscripted variable
b) Collective array
c) Ordinary variable
d) Similar Quantities variable
Answer:a
38) 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.
Answer:b
39) 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
Answer:b
40) 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
Answer:c
41) What will be output of the following program
int main()
{
int b[4]={5,1,32,4};
int k,l,m;
k=++b[1];
l=b[1]++;
m=b[k++];
printf(―%d, %d, %d‖,k,l,m);
return 0;
}
a) 2, 2, 4
b) 3, 2, 32
c) 3, 2, 4
d) 2, 3, 32
Answer:b
Explaination:Here, ++b[1] means that firstly b[1] will be incremented so, b[1]=2 then assigned
to k i.e. k=2.
b[1]++ means firstly b[1] will be assigned to variable l i.e. l=2, Then value stored in b[1] will be
incremented i.e. b[1]=3.
b[k++] means first b[k] will be assigned to m i.e. m=32, then value of k will be incremented i.e.
k=3.
42) What will be output of the following program where c=65474 and int=2 bytes.
int main()
{
int c[3][4]={2,3,1,6,4,1,6,2,2,7,1,10};
printf(―%u, %u\n‖, c+1, &c+1);
return 0;
}
a) 65482, 65498
b) 65476, 65476
c) 65476, 65498
d) No output
Answer:a
Explaination: Here c[3][4]= {
{2,3,1,6};
{4,1,6,2};
{2,7,1,10}
};
c+1 means c is base address i.e. address of 1st one Dimensional array and on incrementing it
by 1 means it points to 2nd one 2 Dimensional array.
So, c+1=65474 + ( 4 * 2)= 65482
But, when we are writing &c, that means address of this whole array i.e. address of next new
array.
So, &c+1=65474 + (12 * 2)=65498
43) what will be output of the following program
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
Answer:a
Explaination: firstly right side of any expression is evaluated, then the left side is evaluated.
So, here ++i will be evaluated at first, then a[i].
Hence, when i=0, a[1]=1, then i=1, a[2]=2,…a[4]=4
and a[0]=garbage value
44) What will be output of the following program
int main()
{
float a[]={12.4, 2.3, 4.5, 6.7};
printf(―%d, %d‖, sizeof(a), sizeof(a[0]));
return 0;
}
a) 16 bytes, 4 bytes
b) 4 bytes, 4 bytes
c) 8 bytes, 4 bytes
d) None of these
Answer:a
Explaination: sizeof(a)=number of element * size of each element
=4 * 4 bytes
=16 bytes
sizeof(a[0])=size of 1st element of array a
= 4 bytes
45 Which one of this is equivalent to
int fun(int arr[])
a) int fun(arr)
b) int fun(int s[])
c) int fun(int arr[2])
d) None of these
Answer:c
Explaination: int fun(int arr[]) and int fun(int arr[0]) are equivalent. Both are prototype for
function fun(), that accepts one integer array as parameter and return an integer value.
46) In 2 Dimensional Array, it is necessary to mention _______ dimension.
a) second
b) first
c) both
d) none of these
Answer:a
Explaination :In 2D array, it is necessary to mention the second dimension, whereas the first
dimension is optional.
int arr[][3]={12,34,33,45,56,73};
47) 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
Answer:d
48) What will be output of the following program
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
Answer:a
Explaination: We cannot assign one array to another directly. We can do assignment
operation element by element. Thus reports compile time error.
TCS TECHNICAL MCQ
49) Which of the following syntax is correct for command-line arguments?
a) int main(int var, char *argv[])
b) int main(char *arv[], int arg)
c) int main(char c,int v)
d) int main(int v,char c)
Answer:a
50) What does argv and argc indicate in int main(int argc, char *argv[]) ?
a) argument constant, argument variable
b) argument count, argument vector
c) argument constant, argument vector
d) argument count, argument variable
Answer:b
51) What type of array is generally generated in Command-line argument?
a) MultiDimensional Array
b) Jagged Array
c) 2-Dimensional Array
d) Single Dimensional Array
Answer:b
52) The maximum length of the command-line arguments including the spaces is
a)May vary from one OS to another
b)256 characters
c)Depends on the Number of arguments
d)128 characters
Answer:a
53) The index of the last argument in command line arguments is
a) argc
b) argc * 2
c) argc – 1
d) argc + 1
Answer:c
54) What is the first argument of command line ?
a)File Name
b)Program Designation
c)argument passed by user
d)Program Name
Answer:a
55)What argv means in command line argument?
a)Array of pointers
b)pointer to a character array
c)Array of character pointers
d)Array of Strings
Answer:c
56) What will be the output of the following program if argument passed to command lines are
: prog 1 4 2
#include<stdio.h>
int main(int argc, char *argv[])
{
int j;
j = argv[1] + argv[2] – argv[3];
printf(―%d‖, j);
return 0;
}
a)Error
b)3
c)Garbage Value
d)None of these
Exp : > Here, argv[1], argv[2] and argv[3] are of type String. So, we have to convert String to
integer before performing arithmetic operation.
Answer:a
57) What argv[0] and argv[1] denote in Command line Arguments ?
a) Pointers to first two command line argument supplied.
b) File Name and pointer to first command line argument supplied.
c) Program Name and Pointer to the 1st argument.
d) None of these.
Answer:b
58) Which one of these is equivalent to argc ?
a) Number of Arguments
b) Number of Arguments – 1
c) Number of Arguments + 2
d) Number of Arguments + 1
Answer:d
59) What will be output of the following program if argument passed to command lines are :
prog 1 4 2
#include<stdio.h>
int main(int argc, char *argv[])
{
while(argc–)
printf(―%s\n‖,argv[argc]);
return 0;
}
a) 2 4 1
b) Garbage-value 2 4 1
c) Garbage-value 2 4 1 prog
d) Infinte Loop
Answer:a
60) What will be output of the following program if argument passed to command lines are :
demo one two three
#include<stdio.h>
int main(int argc, char *argv[])
{
printf(―%c\n‖,**+argv);
return 0;
}
a) n
b) o
c) t
d) Compile Time Error
Answer:b
Explaination: > Here, char * argv[ ] denotes Array of Pointers. So, argv[ ] holds the address of
the command line argument passed. ++argv denote the address of next location, which holds
the address of the 2nd argument.
*++argv denote the value stored at that address i.e. the address of the 1st character of the 2nd
argument and **++argv itself denote the character ‗o‘ .
61) What will be output of the following program if argument passed to command lines are :
demo friday
#include<stdio.h>
int main(int argc, char *argv[])
{
printf(―%c‖,*++argv[1]);
return 0;
}
a) r
b) f
c) i
d) d
Answer:a
Explaination :>argv[1] can be wriiten as *(argv+1), (argv+1) denote the address of next
location, which holds the address of 2nd argument. Thus *(argv+1) or argv[1] denote the value
stored at that address i.e. denote the address of 1st character of the 2nd Argument. ++argv[1]
denote the address of 2nd character of the 2nd Argument. So *++argv[1] itself denote the
character ‗r‘ .
TCS FUNCTIONS QUESTIONS WITH SOLUTIONS
62. What is the output of this C code?
#include
void main()
{
m();
void m()
{
printf(―SimpleWay2Code‖);
}
}
a) SimpleWay2Code
b) Compile time error
c) Nothing
d) Varies
Answer:b
63. What is the output of this C code?
#include
void main()
{
static int x = 3;
x++;
if (x <= 5) { printf(―hello‖); main(); } } a) Run time error b) hello c) Infinite hello d) hello hello
Answer:d 3. The value obtained in the function is given back to main by using ________
keyword? a) return b) static c) new d) volatile Answer:a 4. 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 Answer:d 5. What is the return-type of the function sqrt() a) int b) float c) double d)
depends on the data type of the parameter Answer:c 6. What is the output of this code having
void return-type function? #include
void foo()
{
return 1;
}
void main()
{
int x = 0;
x = foo();
printf(―%d‖, x);
}
a) 1
b) 0
c) Runtime error
d) Compile time error
Answer:d
64. The output of the code below is
#include
void main()
{
int k = m();
printf(―%d‖, k);
}
void m()
{
printf(―hello‖);
}
a) hello 5
b) Error
c) Nothing
d) Garbage value
Answer:a
65. The output of the code below is
#include
int *m()
{
int *p = 5;
return p;
}
void main()
{
int *k = m();
printf(―%d‖, k);
}
a) 5
b) Junk value
c) 0
d) Error
Answer:a
66. What will be the output of the program?
#include
int main()
{
int i=1;
if(!i)
printf(―SimpleWay2Code,‖);
else
{
i=0;
printf(―C-Program‖);
main();
}
return 0;
}
A. prints ―SimpleWay2Code, C-Program‖ infinitely
B. prints ―C-Program‖ infinetly
C. prints ―C-Program, SimpleWay2Code‖ infinitely
D. Error: main() should not inside else statement
Answer:b
67. How many times the program will print ―SimpleWay2Code‖ ?
#include
int main()
{
printf(―SimpleWay2Code‖);
main();
return 0;
}
A. Infinite times
B. 32767 times
C. 65535 times
D. Till stack overflows
Answer:d
TCS RECURSION AND ITERATION QUESTIONS
68.function main()
{
integer a=5,b=7
switch(a)
{
case 5 :print ―I am 5‖
break
case b:print ―I am not 5‖
break
default:print ―I am different‖
}
}
a.I am 5
b.I am not 5
c.I am different
d.Error
Answer:d
Explanation: Break doesn‘t have -> ;
69.Ashima wants to print a pattern which includes checking and changing a variables value
iteratively She decides to use a loop/condition Which of the following options should she use
such that the body of the loop/condition is executed atleast once whether the variable
satisfies the entering condition or not?
a.For Loop
b.While Loop
c.Do While Loop
d.Switch Case
Answer:c
70.The construct ―if (condition) then A else B‖ is for which of the following purposes? 1) 2) 3)
4)
a.Decision-Making
b.Iteration
c.Recursion
d.Object Oriented Programming
Answer:a
71.Ravi and Rupali are asked to write a program to sum the rows of 2X2 matrices stored in
the array A. Ravi writes the following code (Code A): for n = 0 to 1 sumRow1[n] = A[n][1] +
A[n][2] end Rupali writes the following code (Code B): sumRow1[0] = A[0][1] + A[0][2]
sumRow1[1] = A[1][1] + A[1][2] Comment upon these codes (Assume no loop unrolling done by
compiler):
a.Code A will execute faster than Code B.
b.Code B will execute faster than Code A
c.Code A is logically incorrect.
d.Code B is logically incorrect.
Answer:b
72.Integer a =40, b =35, c=20, d =10 Comment about the output of the following two
statements •
Print a*b/c-d
Print a*b/(c-d)
Comment about the output of the following two statements
a.Differ by 80
b.Same
c.Differ by 50
d.Differ by 160
Answer:a
73.What is the output of the following pseudo code? Int a =456,b,c,d=10; b=a/d; c=a-b; print
c;
a.411.4
b.411
c.410.4
d.410
Answer: b
74.Ashima wants to print a pattern which includes checking and changing a variables value
iteratively She decides to use a loop/condition Which of the following options should she use
such that the body of the loop/condition is executed atleast once whether the variable
satisfies the entering condition or not?
a.For Loop
b.While Loop
c.Do While Loop
d.Switch Case
Answer:c
75.The construct ―if (condition) then A else B‖ is for which of the following purposes?
a.Decision-Making
b.Iteration
c.Recursion
d.Object Oriented Programming
Answer:a
76.Function main() { Integer i=0.7 Static float m=0.7 If(m equals i) Print(―We are equal‖) Else
If(m>i) Print(―I am greater‖) Else Print(―I am lesser‖)
a.We are equal
b.I am greater
c.I am lesser
d.This code will generate an error
Answer:d
TCS VARIABLES AND REGISTERS QUESTIONS
77. What is the output of this C code?
#include
void main()
{
static int i;
printf(―i is %d‖, i);
}
a) 0
b) 1
c) Garbage Value
d) Run time error
Answer:a
78. What is the output of this C code?
#include
int *i;
int main()
{
if (i == NULL)
printf(―true\n‖);
return 0;
}
a) true
b) true only if NULL value is 0
c) Compile time error
d) Nothing
Answer:a
79. What is the output of this C code?
#include
static int i;
void main()
{
int i;
printf(―i is %d‖, i);
}
a) 0
b) Garbage Value
c) Run time error
d) Nothing
Answer:b
80. What is the output of this C code?
#include
static int x = 5;
void main()
{
x = 9;
{
int x = 4;
}
printf(―%d‖, x);
}
a) 9
b) 4
c) 5
d) 0
Answer:a
81. The scope of an automatic variable is:
a) Within the block it appears
b) Within the blocks of the block it appears
c) Until the end of program
d) Within the block it appears & Within the blocks of the block it appears
Answer:d
82. Automatic variables are allocated space in the form of a:
a) stack
b) queue
c) priority queue
d) random
Answer:a
83. Which of the following is a storage specifier?
a) enum
b) union
c) auto
d) volatile
Answer:c
84. Automatic variables are stored in
a) stack
b) data segment
c) register
d) heap
Answer:a
85. What is the output of this C code?
#include
int main()
{
register int i = 10;
int *q = &i;
*q = 11;
printf(―%d %d\n‖, i, *q);
}
a) Depends on whether i is actually stored in machine register
b) 10 10
c) 11 11
d) Compile time error
Answer:d
86. Register storage class can be specified to global variables
a) true
b) false
c) Depends on the compiler
d) Depends on the standard
Answer:b
87. Register variables reside in
a) stack
b) registers
c) heap
d) main memory
Answer:b
88. Which of the following operation is not possible in a register variable?
a) Reading the value into a register variable
b) Copy the value from a memory variable
c) Global declaration of register variable
d) All of the mentioned
Answer:d
TCS QUESTIONS ON LOOPS
89. The output of the code below is
#include
int a;
void main()
{
if (a)
printf(―Hello‖);
else
printf(―world‖);
}
a) Hello
b) World
c) compile time error
d) none of the mentioned
Answer:b
90. The output of the code below is
#include
void main()
{
int a = 5;
if (true);
printf(―hello‖);
}
a) It will display hello
b) It will throw an error
c) No Output
d) Depends on Compiler
Answer:b
91. The output of the code below is
#include
void main()
{
int a = 0;
if (a == 0)
printf(―hi‖);
else
printf(―how are u‖);
printf(―hello‖);
}
a) hi
b) how are you
c) hello
d) hihello
Answer:d
92. The following code ‗for(;;)‘ represents an infinite loop. It can be terminated by.
a) break
b) exit(0)
c) abort()
d) all of the mentioned
Answer:a
93. The correct syntax for running two variable for loop simultaneously is.
a) for (i = 0; i < n; i++) for (j = 0; j < n; j += 5) b) for (i = 0, j = 0;i < n, j < n; i++, j += 5) c) for (i =
0; i < n;i++){} d) for (j = 0; j < n;j += 5){} Answer:b 6. Which for loop has range of similar indexes
of ‗i‘ used in for (i = 0;i < n; i++)? a) for (i = n; i>0; i–)
b) for (i = n; i >= 0; i–)
c) for (i = n-1; i>0; i–)
d) for (i = n-1; i>-1; i–)
Answer:d
94. The output of this C code is?
#include
void main()
{
int x = 0;
for (x < 3; x++) printf(―Hello‖); } a) Compile time error b) Hello is printed thrice c) Nothing d)
Varies Answer:a 8. The output of this C code is? #include
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 Answer:b 9. The output of this C code is? #include
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
Answer:b
95. The output of this C code is?
#include
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
Answer:a
96. Which of the following cannot be used as LHS of the expression in for (exp1 ;exp2 ; exp3) ?
a) Variable
b) Function
c) typedef
d) macros
Answer:d
97. Which keyword can be used for coming out of recursion?
a) break
b) return
c) exit
d) Both break and return
Answer:b
98. The keyword ‗break‘ cannot be simply used within:
a) do-while
b) if-else
c) for
d) while
Answer:b
99. Which keyword is used to come out of a loop only for single iteration?
a) break
b) continue
c) return
d) none of the mentioned
Answer:b
100. The output of this C code is? #include
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
Answer:d
TCS VARIABLES AND DATA TYPES QUESTIONS
101. Which of the following is not valid variable name declaration?
a) int __v1;
b) int __1v;
c) int __V1;
d) None
Ans:d
102. Which of the following is not a valid variable name declaration?
a) int _v1;
b) int v_1;
c) int 1_v;
d) int _1v
Ans:c
Explanation:Variable name can‘t start with a digit.
103. Variable names beginning with underscore is not encouraged. Why?
a) It is not standard form
b) To avoid conflicts since assemblers and loaders use such names
c) To avoid conflicts since library routines use such names
d) To avoid conflicts with environment variables of an operating system
Ans:c
104. Which is not a valid C variable name?
a) int number;
b) float rate;
c) int variable_count;
d) int $main;
Ans:d
105.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
106. What will be the output?
#include
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
Ans:c
Explanation:A C program can have same function name and same variable name.
107. Which of the following cannot be a variable name in C?
a) friend
b) true
c) volatile
d) export
Ans: c
Explanation:volatile is C keyword
108. The format identifier ‗%i‘ is also used for _____ data type?
a) char
b) double
c) float
d) int
Ans:d
Explanation:Both %d and %i can be used as a format identifier for int data type.
109. Which of the following is a User-defined data type?
a) struct {char name[10], int age};
b) typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays;
c) typedef int Boolean;
d) all of the mentioned
Answer:d
110. What is short int in C programming?
a) Basic datatype of C
b) Qualifier
c) short is the qualifier and int is the basic datatype
d) All of the mentioned
Ans:c
111. What is the output of this C code?
#include
int main()
{
signed char chr;
chr = 128;
printf(―%d\n‖, chr);
return 0;
}
a) 128
b) -128
c) Depends on the compiler
d) None of the mentioned
Ans:b
Explanation:signed char will be a negative number.
112. What is the size of an int data type?
a) 4 Bytes
b) 8 Bytes
c) Depends on the system/compiler
d) Cannot be determined
Ans:c
113. Which of the datatypes have size that is variable?
a) int
b) struct
c) float
d) double
Ans:b
Explanation:Since the size of the structure depends on its fields, it has a variable size.
114. What is the output of this C code?
#include
int main()
{
float x = ‗a‘;
printf(―%f‖, x);
return 0;
}
a) 97.000000
b) run time error
c) a.0000000
d) a
Ans:a
Explanation:Since the ASCII value of a is 97, the same is assigned to the float variable and
printed.
TCS TECHNICAL QUESTIONS ON ABSTRACTION
115.What makes a class abstract?
a.By making all member functions constant.
b.By making at least one member function as pure virtual function.
c.By declaring it abstract using the static keyword.
d.By declaring it abstract using the virtual keyword.
Answer:b
116.Which type of class allows only one object of it to be created?
a.Virtual class
b.Abstract class
c.Singleton class
d.Friend class
Answer:c
117.Which of the following concepts of OOPS means exposing only necessary information to
client?
a.Encapsulation
b.Abstraction
c.Data hiding
d.Data binding
Answer:d
118.Which type of inheritance needs a virtual function:
a.Multi level inheritance
b.Multiple inheritance
c.Hybrid inheritance
d.All of the above
Answer:d
119.Which of the following cannot be inherited?
a.Friend function
b.Static function
c.Destructor
Answer:b
120.Which of the following are available only in the class hierarchy chain?
a.Public data members
b.Private data members
c.Protected data members
d.Member functions
Answer:c
121.Which of the following is not a type of inheritance?
a.Multiple
b.Multilevel
c.Distributive
d.Hierarchical
Answer:c
122.The process of building new classes from existing one is called ______.
a.Polymorphism
B
b.Structure
c.Inheritance
d.Cascading
Answer:c
123.Which of the following supports the concept of hierarchical classification?
a.Polymorphism
b.Encapsulation
c.Abstraction
d.Inheritance
Answer:d
124.Which Keyword from the following is used to inherit properties from one class into
another?
a.extends
b.subclasses
c.native
d.all of the mentioned
Answer:a
TCS PLACEMENTS INPUT OUTPUT QUESTIONS
125.Which one of the following connects the high-speed high-bandwidth device to memory
subsystem and CPU.
a.expansion bus
b.PCI bus
c.SCSI bus
d.none of the mentioned
Answer:a
126.The _________ present a uniform device-access interface to the I/O subsystem, much as
system calls provide a standard interface between the application and the operating system.
a.devices
b.buses
c.device drivers
d.I/O systems
Answer:c
127.When device A has a cable that plugs into device B, and device B has a cable that plugs
into device C and device C plugs into a port on the computer, this arrangement is called a
_________.
a.port
b.daisy chain
c.bus
d.cable
Answer:b
128.The _________ determines the cause of the interrupt, performs the necessary processing
and executes a return from the interrupt instruction to return the CPU to the execution state
prior to the interrupt.
a.interrupt request line
b.device driver
c.interrupt handler
d.All of these
Answer:c
129.The ______ register is read by the host to get input.
a.flow in
b.flow out
c.data in
d.data out
Answer:c
130.The ______ register is written by the host to send output.
a.status
b.control
c.data in
d.data out
Answer:d
131.The CPU hardware has a wire called __________ that the CPU senses after executing every
instruction.
a.interrupt request line
b.interrupt bus
c.interrupt receive line
d.interrupt sense line
Answer:a
132.The _________ are reserved for events such as unrecoverable memory errors.
a.non-maskable interrupts
b.blocked interrupts
c.maskable interrupts
d.None of these
Answer:a
133.The hardware mechanism that allows a device to notify the CPU is called _______.
a.polling
b.interrupt
c.driver
d.controlling
Answer:b
134.Spooling :
a.holds a copy of the data
b.is fast memory
c.holds the only copy of the data
d.holds output for a device
Answer:c,d
TCS QUESTIONS ON POLYMORPHISM
135.Which of the following is not a valid type of polymorphism?
a.adhoc polymorphism
b.imperative polymorphism
c.predicative polymorphism
d.inclusion polymorphism
Answer:b
136.What is the function used to describe the situation, when a function in base class is
redefined in inherited class?
a.Inheritance
b.Overriding
c.Overloading
d.Encapsulation
Answer:b
137.How can a call to an overloaded function be ambiguous?
a.By misspelling the name
b.There might be two or more functions with the same name
c.There might be two or more functions with equally appropriate signatures
d.None of these
Answer:b
138.A complete binary tree with the property that the value at each node is at least as large as
the values at its children is known as
a.Binary search tree
b.AVL tree
c.Completely balanced tree
d.Heap
Answer:d
Exp:A max-heap is a complete binary tree in which the value in each internal node is greater
than or equal to the values in the children of that node.
139.Which of the following correctly describes overloading of functions?
a.Virtual polymorphism
b.Transient polymorphism
c.Ad-hoc polymorphism
d.Pseudo polymorphism
Answer:c
140.Which of the following operator is overloaded for object cout?
a.>>
b.<< c.+ d.= Answer:a 7.Which of the following operators cannot be overloaded? a.[] b.->
c.?:
d.*
Answer:d
141.Which of the following is a mechanism of static polymorphism?
a.Operator overloading
b.Function overloading
c.Templates
d.All of the above
Answer:d
142.Which of the following keyword is used to overload an operator?
a.Overload
b.Operator
c.Friend
d.Override
Answer:b
143.The operator << when overloaded in a class a.must be a member function b.must be a
non member function c.can be both (A) & (B) above d.cannot be overloaded Answer:c
TCS TECHINCAL QUESTIONS WITH SOLUTIONS SET -1
144.Which of this is used to skip one iteration:
A) break
B) continue
C) goto
D) return
Answer:b
145.Which of the following does not require to include math.h header file?
A) pow()
B) rand()
C)sqrt()
D) sinh()
Answer:b
146.Which has the highest precision?
A. float
B. double
C. unsigned long int
D. Long int
Answer:b
147.Choose the correct statement
while (0 == 0) { }
A) It has syntax error as there are no statements within braces {}
B) It will run forever
C) It compares 0 with 0 and since they are equal it will exit the loop immediately
D) It has syntax error as the same number is being compared with itself
Answer:b
148.Predict the output of following code:
main()
{
int a=10,x;
x= a– + ++a;
printf(―%d‖,x);
}
A) 19
B) 20
C) 22
D) 23
Answer:b
149.Guess the output:
main()
{
printf(―%d‖, sizeof(‗a‘));
//same as → sizeof(97)
}
A) 2 or 4 —
B) 1 or 3
C) Garbage value
D) ASCII value of a
Explaination:
sizeof takes ascii value of character and determines number of bytes required by it. Ascii is
number, Number is of type int. so integer requires either 2 in 16 or 4 in 32 bit machine
Answer:a
150.Predict the output of following code:
main()
{
int a=b=c=d=10;
printf(―%d,%d,%d,%d‖,a,b,c,d);
}
A) Error
B) 10,10,10,10
C) Garbage Value,Garbage Value,Garbage Value,10
D) Garbage Value,Garbage Value,Garbage Value,Garbage Value
Explaination: error: ‗b‘ , ‗c‘, ‗d‘ undeclared
Answer:
151.Select the missing statement?
#include
long int fact(int n);
int main()
{
\\missing statement
}
long int fact(int n)
{
if(n>=1)
return n*fact(n-1);
else
return 1;
}
A) printf(―%ll\n‖,fact(5));
B) printf(―%u\n‖,fact(5));
C) printf(―%d\n‖,fact(5));
D) printf(―%ld\n‖,fact(5));
Answer:d
152. If a function‘s return type is not explicitly defined then it‘s default to ______ (In C).
A) int
B) float
C) void
D) Error
Answer:a
153. How many times the below loop will be executed?
#include
int main()
{
int i;
for(i=0;i<5;i++) printf(―Hello\n‖); } A) 5 B) 1 C) 0 D) 3 Answer:a
TCS TECHINCAL QUESTIONS WITH SOLUTIONS SET -2
154. How many times loop will executed ?
#include
int main()
{
int x,y;
for(x=5;x>=1;x–)
{
for(y=1;y<=x;y++)
printf(―%d\n‖,y);
}
}
a) 11
b) 13
c) 15
d) 10
Answer:c
155. Which of the following indicate the end of file ?
a) feof()
b) EOF
c) Both feof() and EOF
d) None of the mentioned
Answer:c
156. If a functions return type is not explicitly defined then it is default to ……….(in C).
a) int
b) float
c) void
d) error
Answer:a
157. Where the local variable is stored ?
a) Disk
b) Stack
c) Heap
d) Register
Answer:b
158. How many times loop will executed ?
#include
int main()
{
int i;
for(i=0;i<5;i++)
{
printf(―Hello\n‖);
}
}
a) 0
b) 1
c) 3
d) 5
Answer:d
159. What is dangling pointer?
a) points to garbage value
b) points to function
c) Both A and B
d) None of these
Answer:a
160. what is the purpose of ftell ?
a)to get the current file position
b)to get the current file attribute
c)to get the current file status
d)to get the current file name
Answer:a
161. What is recursion ?
a) looping
b) a function calls another function repeatedly
c) a fnction calls repeatedly
d) function calls itself repeatedly
Answer:d
162. What is the similarity between enum and struct ?
a) can assign new values
b) can create new data types
c) nothing in common
d) they are same
Answer:b
163. which of the following is not a fundamental datatype?
a) Enum
b) unsigned long int
c) Long int
d) double
Answer:
164. How many times hello will print ?
#include
int main(void)
{
int i;
for(i=0;i<5;i++);
printf(―hello‖);
}
a) Compilation error
b) Runtime error
c) 4
d) 1
Answer:b
TCS C PROGRAMMING MULTIPLE CHOICE SET- 3
165. atoi() function is used for:
a)convert ASCII character to integer value
b)convert a character string to its equivalent integer value
c)gets index value of character in an array
d)converts an array of characters to array of equivalent integers
Answer:b
166. Which of the following is NOT declared in string.h ?
a) strlen()
b) strcpy()
c) strptr()
d) strupr()
Answer:c
167. which of the below function is NOT declared in math.h ?
a) and()
b) pow()
c) exp()
d) acos()
Answer:a
168. Where are the local variable stored ?
a) In a Queue
b) In stack Memory
c) In hard Disk
d) In heap Memory
Answer:a
169. while declaring parameters for main, the second parameter argv should be declared as
a) char argv[]
b) char argv
c) char ** argv[]
d) char * argv[]
Answer:d
170. A memory leak happens when
a) a program allocates memory in heap but forgets to be allocate it
b) when an un-assigned pointer is used is freed using free function
c) when realloc() is called on a pointer that is not allocated
d) A program allocates memory in stack
Answer:a
TCS TECHNICAL MCQS SET 4
171.A pointer variable can be
1. Changed within function.
2. Assigned an integer value.
3. None of these
4. Passed to a function as argument.
172. Which of the following uses structure?
1. Linked Lists
2. Array of structures
3. All of these
4. Binary Tree
173. Strings are character arrays. The last index of it contains the null-terminated
character
1. \t
2. \1
3. \0
4. \n
174. Which of the following is a collection of different data types?
1. String
2. Structure
3. Array
4. Files
175. What function should be used to free the memory allocated by calloc() ?
1. free();
2. malloc(variable_name, 0)
3. dealloc();
4. memalloc(variable_name, 0)
176. In the standard library of C programming language, which of the following header
file is designed for basic mathematical operations?
1. conio.h
2. stdio.h
3. math.h
4. dos.h
177. int **ptr; is?
1. Pointer to integer
2. None of these
3. Pointer to pointer
4. Invalid declaration
178. Which of the following special symbol allowed in a variable name?
1. (underscore)
2. – (hyphen)
3. | (pipeline)
4. * (asterisk)
179. All keywords in C are in
1. Uppercase letters
2. None of these
3. Lowercase letters
4. Camel Case letters
180. What should the program below print?
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void myfunc(char** param){
++param;
}
int main(){
char* string = (char*)malloc(64);
strcpy(string, ―hello_World‖);
myfunc(&string);
myfunc(&string);
printf(―%s\n‖, string);
// ignore memory leak for sake of quiz
return 0;
}
1. hello_World
2. ello_World
3. lo_World
4. llo_World
TCS COMPUTER PROGRAMMING MCQ QUESTIONS – 5
181: What is the output of this C code?
#include <stdio.h>
void main()
{
int k = 5;
int *p = &k;
int **m = &p;
printf(―%d%d%d\n‖, k, *p, **p);
}
a) 5 5 5
b) 5 5 junk
c) 5 junk junk
d) Compile time error
182. Which of the following statements about stdout and stderr are true?
a) They both are the same
b) Run time errors are automatically displayed in stderr
c) Both are connected to the screen by default.
d) stdout is line buffered but stderr is unbuffered.
183: Given the below statements about C programming language;
1) main() function should always be the first function present in a C program file
2) all the elements of an union share their memory location
3) A void pointer can hold address of any type and can be typecasted to any type
4) A static variable hold random junk value if it is not initialised
Which of the above are correct statements?
A) 2,3
B) 1,2
C) 1,2,3
D) 1,2,3,4
Q4 If a function is defined as static, it means
A) The value returned by the function does not change
B) all the variable declared inside the function automatically will be assigned initial value of
zero
C) It should be called only within the same source code/program file.
D) None of the other choices as it is wrong to add static prefix to a function
185: Comment on the below while statement18while (0 == 0) { }
A) It has syntax error as there are no statements within braces {}
B) It will run forever
C) It compares 0 with 0 and since they are equal it will exit the loop immediately
D) It has syntax error as the same number is being compared with itself
TCS COMPUTER PROGRAMMING MCQ QUESTIONS – 6
186. The function ____ obtains block of memory dynamically.
a) calloc
b) malloc
c) Both calloc & malloc
d) free

187. For a typical program, the input is taken using


a) scanf
b) Files
c) Command-line
d) All of the mentioned
188. What is the default return-type of getchar()?
a) char
b) int
C. char *
D. reading character doesn‘t require a return-type

189. Memory allocation using malloc() is done in?


a) Static area
b) Stack area
c) Heap area
d) Both Stack & Heap area

190. What is the sizeof(char) in a 32-bit C compiler?


a) 1 bit
b) 2 bits
c) 1 Byte
d) 2 Bytes

191. What type of value does sizeof return?


a) char
b) short
c) unsigned int
d) long

192. Which one is used during memory deallocation in C?


a) remove(p);
b) delete(p);
c) free(p);
d) terminate(p);

193. 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
TCS C PROGRAMMING MCQ QUESTIONS – 7
194. Which is the character array used to accept command line arguments?
A) char argv
B) char* argv[]
C) char argv[]
D) char* argv
Ans: b
195 Which is not a string function?
A) strstr
B)strcmp
C) strupr
D) strchr
Ans: c
196 Which of the following does not require to include math.h header file?
A) pow()
B) rand()
C)sqrt()
D) sinh()
Ans: b
197 What is the task of pre-processor?
A) Expanding
B) Compiling
C) Linking
D) All of the above
Ans: a
198 Which of the following is true?
A) realloc() can change the memory size of arrays
B) Unary operator works on only one operand
C) Struct and Union works in same way.
D) None of the above
Ans: b
199 Which of this is used to skip one iteration:
A) break
B) continue
C) goto
D) return
Ans: b
200 Which address does a pointer to an array store:
A) Memory address of the first element of the array Don‘t remember the other options.
201 Predict the output:
float a = 0.1;
if(a==0.1)
printf(―Yes‖);
else
printf(―No‖); Answer would be No.
Ans: no

Table of Contents
SET 1: 2018012ALL ....................................................................................... 1
SET 2: 2018002PRIYA.................................................................................. 18
SET 1: 2018012ALL
65) Where the local variables are stored?
a) Disk b) stack c) heap d) 13
66) which of the following indicate the end of the file ?
a) Feof() b) EOF c) both feof() and EOF d) none of the mentioned options
67) When reading from a file, to test whether we have reached its end, which function can be
used?
a) eof() b) endOfFile() c) feof() d) fend()
68) If a function‘s return type is not explicitly defined then it‘s default to __( in C)
a) Int b) float c) void d) error
69) Select the missing statement ?
#include<stdio.h>
long int fact(int n)
int main()
{
\\missing statement
}
long int fact(int n)
{
if(n>=1)
return n*fact(n-1);
else
return 1;
}
a) printf(―%ll\n‖,fact(5)); b) printf(―%u\n‖,fact(5));
c) printf(―%d\n‖,fact(5)); d) printf(“%ld\n”,fact(5));
70) How many times the below loop will be executed?
#include<studio.h>
int main ( ) {
int x,y ;
for (x=5;x>=1;x--)
{
for(y=1;y<=x;y++)
printf(―%d\n‖,y);
}
}
a) 15 b) 10 c) 11 d) 13
71) Which datatype has more precision?
(a) double (b) float (c) insigned longint (d) long int
72) Which of the following is user-defined data type?
a) Long int b) double c) enum d) unsigned long int
73) What will be the output/error?(for input 6,9)
#include<stdio.h> {
int fg(int,int) while(x!=y)
int main() {
{ if(x>y)
int n1,n2,g; return fg(x-y,y);
scanf(%d%d‖,&n1,&n2); else
g=fg(n1,n2); return fg(x,y-x);
printf(―%d‖,g); }
} return x;
int fg(int x,int y) }

a) 3 b) 6 c) 9 d) error
74) What is the dangling pointer?
A. points to garbage value B. points to function C. both a and b D. none of the
above

75) A dangling pointer is


E. pointer whose value is fixed
F. pointer that does not point to a valid memory location
G. pointer that has been wrongly assigned multiple memory locations
H. pointer that cannot be made to point to alternative memory location
76) int main(int argc, char **argv)
Comment about : char ** argv
a)Pointer to pointer b) it is the file name and argument passed
c) it is an array of character pointers d) Compile time error
77) main(int argc, char**argv)
In the above definition of main function the variable argv denotes…
a) An array of character pointers each pointing to the command line
parameters
b) An array of character pointers the first array item pointing to the
program name and the remaining pointing to the command line
parameters
c) A pointer to character that points to command line parameter
d) A pointer to a pointer to the points to the memory location where the
program has been loaded into the memory
78) How to release the dynamic memory?
a)Free( ) b) truncate( ) c) delete( ) d) release( )
79) What library function is used to release the allocated memory in C?
a) Dalloc() b) Release() c) Free() d) Freemem()
80) What is the purpose of ftell?
A. to get the current file name B. to get the current file status
C. to get the current file attribution D. to get the current file position
81) What is recursion?
A. looping B. a function calls another function
repeatedly
C. function calls repeatedly D. function call itself repeatedly
82) What is the similarity between enum and structure?
A. can assign new values B. can create new data types
C. nothing is common D. they are same

STAR QUESTION
83) What will be the output of the below code
# include <stdio.h>
int main()
{
float f = 0.1;
if (f ==0.1)
printf(―YES\n‖);
else
printf(―NO\n‖);
return 0;
}
ANS:NO
84) What will be the output of the below code
# include <stdio.h>
int main()
{
float f=0.1;
if (f ==0.1)
printf(―NO\n‖);
return 0;
}
a) NO b) ERROR
c) NO OUTPUT d) Successfully compiled but no Output
85) A memory leak happens when?
A. a program allocates memory in heap but forget to delete it
B. a program allocate memory in stack
C. when an un signed pointer is freed using free function
D. when reallocate () is called on a pointer that is not allocated
86) Which of the below is NOT a fundamental data type
a. Unsigned long int b. Enum c. Long int d. double
87) The similarity between a structure, union and enumeration is?
a. All of them let us design new pointers.
b. All of them let us design new values.
c. All of them let us design new data types.
d. Size of all of them do not vary from program to program.
88) In the below code, what concept is used
# include <stdio.h>
long int fact (int n);
int main ( )
{
int n;
printf ( ― Enter a positive integer:‖);
scanf (― %d ‖, &n);
printf (― Factorial of %d = %1d‖, n , fact(n));
return 0;
}
long int fact ( int n )
{
if ( n >= 1)
return n * fact ( n – 1);
else
return 1;
}
a. Iteration b. Segmentation c. Encapsulationd. Recursion

a) Function calls from one to other function


b) Repeatedly calls itself (recursive)
c) Conditional looping
89) Which of the following is the correct order of evaluation for the below
expression?
z=x+y*z/4%2-1
[A].* / % + - = [B].= * / % + - [C]./ * % - + = [D].* % / -
+=
90) How many times Hello will print?
#include <stdio.h>
int main (void)
{
int I;
for (i=0;i-5;i--);
{
printf(―Hello‖);
}
}
A. compilation error B. 1 C. 4 D. runtime error

91) How many times loop will be executed?


#include<stdio.h>
int main( )
{
int i;
for(i=0;i<5;i++)
{
printf("Hello\n");
}
}
A) 5 B)1 C)0 D)3

92) How many times Hello will print?


#include<stdio.h>
int main( )
{
int i;
for(i=0;i<5;i++);
{
printf("Hello");
}
}
A. compilation error B. 1 C. 4 D. runtime error
93) Which of the following statement is true about the c language?
A.(void *)0 is different from a null pointer (wikepedia says this is wrong)
B.null pointer is another name for un initialized pointer
C.calloc() can be used only for character pointer allocation
D.char* i=0 and char *i= null means the same
STAR QUESTION
94) In the below program expects the user to enter a word. If the user enter the
word as MADAM what is the output value printed:
#include <stdio.h >
#define MAX 20
Char*fn(char []);
Int main(){
Char str[MAX],*rev;
Printf(―Enter a word of size not more than 15 characters:‖);
Scanf(―%s‖,str);
r-fn(str);
printf(―%s\n‖,r);
return 0;
}
Char* fn (char str[]){
Static int i=0;
Static char r [MAX];
If (*str){
Fn (str+1);
r[i++]=*str;
}
Return r;
}
ANS: COMPILATION ERROR. Variable “r” is not declared.
95) In the below program expects the user to enter a word. If the user enter the
word as HELLO what is the output value printed:
#include <stdio.h >
#define MAX 20
Char*fn(char []);
Int main(){
Char str[MAX],*rev;
Printf(―Enter a word of size not more than 15 characters:‖);
Scanf(―\a‖,str);
r-fn(str);
printf(―\s\n‖,r);
return 0;
}
Char* fn (char str[]){
Static int i=0;
Static char r [MAX];
If (*str){
Fn (str+1);
r[i++]=*str;
}
Return r;
}
ANS: COMPILATION ERROR. Variable “r” is not declared.
STAR QUESTION
96) What is the if size for char is 1, int is 4,double is 8?
#include<stdio.h>
union u
{
int i;
char c;
double d;
};
int main()
{
union ui, u1;
printf(―%d‖,sizeof(u1));
return 0;
}
Ans.Error
97) atoi() function is used to
A. gets index value of character in an array
B. converts ASCII character to its integer value
C. converts an array of characters to array of equivalent integer
D. convert a character string to its equivalent integer value
98) Which has the highest precision?
a)Float b) Double c) unsigned long int d) long int
99) Which of the following functions is NOT declared in string.h?
a)Strcpr ( ) b)strcpy ( ) c) strlen ( ) d) strptr()
100) While declaring parameters for main, the second parameter argv should be
declared as
A.char arg B.char argv[] C. char argv[] D.char**argv[]
101) Which of the following statement is true about C language?
a) There is a maximum limit to number of case instance inside a switch
statements
b) Two case constant within the same statements can have the same value
c) Do while loop is used to ensure that the statements within the loop are
executed at least twice
d) Continue keyword skips one iteration of loop
102) What does the default header file contain?
a)Prototypes b) Declaration c) implementations d) all the
above
STAR QUESTION
103) In the below code the program expects the user to enter a word. If the user
enters the word as ABRACADABRA what is the output value printed?
#include<stdio.h>
#define MAX 20
char *fn(char( ) );
int main( )
{
char str[MAX], * rev;
Printf(― Enter word size not more than 15 characters: ‖);
Scanf(―%s‖,str);
r= fn(str);
printf(―%s\n‖,r);
return 0;
}
char* fn(char str( ) )
{
static int 1=0;
static char r[MAX];
if(*str)
{
fn(str+1);
r[i++]=*str;
}
return r;
}
ANS: COMPILATION ERROR. Variable “r” is not declared.
104) Which of the below statements is true (need to check)
a. None of the other three choices
b. A static function can return only a static variable
c. A static variable can be declared only inside a static function
d. Variables passed to a static function should also be static
105) The output of the below program :
# include <stdio.h>
int main ()
{
int n, ch;
for (n=7; n!=0; n --)
printf (―n = %d‖, n --);
ch = getchar();
return 0;
}
e) Numbers 7 to 1 in descending order
f) Numbers 7 to 0 in descending order
g) None of the other 3 choices as there is a compilation error
h) Infinite loop. Program never ends
106) Given the below statements about C programming language;
1) main() function should always be the first function present in a C program
file
2) all the elements of an union share their memory location
3) A void pointer can hold address of any type and can be typcasted to any type
4) A static variable hold random junk value if it is not initialised
Which of the above are correct statements?
A) 2,3 B) 1,2 C) 1,2,3 D) 1,2,3,4
107) #include<stdio.h>
#include<stdlib.h>
Int main(argc, argv)
int argc;
char **argv;
{
FILE fp; - Error (it should be File *fp
fp=fopen(―foo‖, ―r‖); - Error
if(!fp)
{
printf(―unable to open file‖);
exit(1);
}
fclose(fp);
return 0;
}
In the above code, there is an error at line number_______
e) No error b) Line 5 c) Line 8 d) Line 7
108) #include<stdio.h>
void fn(int **p);
int main()
{
int a[3][4]={1,2,3,4,5,6,7,8,9,10,11,12};
int *ptr;
ptr=&a[0][0];
fun(&ptr);
return 0;
}
void fun(int **p)
{
printf(―%d\n‖,**p);
}
The output of the above code will be ______
a) 2 b) The code has a error and hence will not run
c) 1 d) 0
STAR QUESTION
109) In the below code, the program expects the user to enter one number. if the
user enters the number as 13 what is the output value printed:
#include <stdio.h>
int fn(int,int);
int main()
{
int num, p;
printf(‗enter a positive integer : ―);
scanf (―%d‖, &num);
p = fn(num,num/2);
printf (―%d\n‖,p);
return 0;
}
int fn (int num,int i)
{
if(i==1)
{
return 1;
}
else
{
if (num% i==0)
return 0;
else
fn( num,i-1);
}}
// Answer : 1
Note : fn is a function to check whether input is prime or not.
fn (13, 6);
fn (13, 5);
fn (13, 4);
fn (13, 3);
fn (13, 2);
fn (13, 1); returns 1;
110) 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 statement TRUE
b) The loop counter in a for loop should be of int data type only – FALSE
c) "= =" operator is used to assign an exact value with correct accuracy. FALSE
d) Under special conditions keywords can be used as variable name. FALSE
111) Which of the below statements is true?
a) C language allows negative index values in an array. – TRUE
b) Function rewind() makes execution of the program restart from the
beginning – FALSE
c) We cannot use any name in place of argv and argc as command line
arguments – FALSE
d) Constant pointer and pointer to a constant are the same. - FALSE
112) Which of the following statement is true about C language?
e. Realloc can be used to change size of an array
f. If a function explicitly dose not return a value, then default value 0 will
return
g. Unary operator takes only one operand
h. It is not possible to write a working program in C without using semicolon
113) Which of the following below about static variable is true?
e. A variable that is static is assigned on address at build [compile, link]time
f. A static variable inside a function keep the values between invocation
g. All of the three statement are true
h. A static variable will auto initialize to zero at the start of the
program/function
114) Which of the statement about array and pointer is correct?
e. An array memory size can be modify using pointer
f. Array has fixed memory size whereas pointer can point on array size as
we required at run time
g. Both array and pointer can be resize using realloc()
h. None of other three options are correct
115) Recursion is when
e. A dummy function is executed to create time delays
f. A function calls another function without passing any parameters
g. A block of code is executed multiple times based on a condition
h. A function calls itself
116) To print a double value which format specifier should be used?
a) %lf b) %Lf c) %f d) %df
117) #include<stdio.h>
main(int argc, char **argv)
{
puts(argv[argc] );
}
The above C program is compiled and executable is named as test.
It is then invoked in command line as below :
Test 1 2 3 4 5
What will be the value of argv that will be printed?
a) 5 b) Run time error c) No output d) 1
118) What will be output of the program ?
#include<stdio.h>
main()
{
static int a=2,b= 4,c= 8;
static int *arr1[2] ={&a, &b};
static int *arr1[2] ={&b, &c};
int* (*arr[2] *arr1[2] )[2] = {&arr1, &arr2};
printf(―%d‖, *(*(**(arr +1)+1) ) ) ;
}
119) To write a struct into a file in C language, we can use
a) fwrite() b) Not possible to write composite data types c) fputc()
120) A program tried to compile and link the below code. What he would have
encountered ?
main()
{
int i=10;
printf(―%d‖,i);
}
e. Run time error as stdio.h is not present
f. Compile time error as stdio.h is not included
g. Compile error as there is no returns statement in the main function
h. Program would have printed 10
121) What will be the output of the below program?
#include <stdio.h>
Main ()
{
static int a=2, b=4, c=8;
static int *arr1[2]=(&a, &b);
static int *arr2[2]=(&b, &c);
int* (*arr[2]) [2]=(&arr 1, &arr2);
printf(―%d‖, *(*(**(arr+1)+1))):
}
122) #include <stdio.h>
Main (int argc, char ** argv)
{
puts (argv[argc]);
}
The above program is complied and executable is named as test. It is then
invoked in command line as below:
Test 1 2 3 4 5
What will be the value of argv that will be printed?
a) 5 b) Run time error c) No output d) 1
123) #include
int main(){
float a=5.89
printf(%.0f,a);
}
a) 6 b) 2.89 c)2.890000 d)it has no conio.h so its error

124)
int a=5;
char c='c';
printf("%d",a+c);
a) compiles and runs b) compilation error
c) integer and character cannot be added d) conio.h is not given so error
125) Eesha writes function and save as file.c but she forget to call the function
a) programs compiles and runs b) it compiles but causes runtime error
c)run time error
126) Which of the following is correct
i) (a=b)? (c==d):(e==f)
ii) (a==b)?(c=d):(e=f)
iii) (a=b)?(c=d):(e=f)
iv) (a==b)?(c==d):(e==f)
a) i is correct b) i and ii is correct c) ii and iv is correct d) all the
above.
127) which is true?
i) global variable can't start auto variable
ii)local variable are static
iii)extern are auto variable
iv) all the above
128) #include<stdio.h>
int main()
{
static int i;
int j;
for(j=0;j<10;j++)
{
i+=2;
i-=j;
}
printf("%d",i) ;
}
a) - 27 b) - 25 c) cannot be determined d) – 21
SET 2: 2018002PRIYA
TCS DATA TYPE QUESTIONS WITH SOLUTIONS
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
Answer: D
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.
A.30 B.4165 C.40 D.4166 Answer: C
3.A data type is stored as an 6 bit signed integer. Which of the following cannot be
represented by this data type?
A. -12 B. 0 C.32 D.18 E.64 Answer: c
4.A language has 28 different letters in total. Each word in the language
iscomposed of maximum 7 letters. You want to create a data-type to store a word
ofthis 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 Answer: b
5. A 10-bit unsigned integer has the following range:
a.0 to 1000 b.0 to 1024 c.1 to 1025 d.0 to 1023 Answer:
D
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 = 100D d. a = 100 b = 50
Answer: a
7.Which is used to convert source code to target language
a. linker b. compiler c. executer d. loader Answer: b
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 Answer: d
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 Answer: d
10. The datatype is store as 6 but unsigned integer. Which of the following can‘t be
represented by the this datatype:
a. -12 b. 0 c. 32 d. 18 Answer: a
TCS PROGRAMMING QUESTIONS ON FUNCTIONS AND SCOPE – 1
11.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 Answer: b
12. Consider the following function function calculate( n ) { if(n equals 5) return 5
else return (n + calculate(n-5)) end } Shishir calls the function by the statement,
calculate(20). What value will the function return?
a. 50 b. 200 c. 35 d. 20 Answer: a
13. 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 Answer:
d
14.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
Answer: b
15. 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 list follows the same procedure as the homogeneous list. Hence
no different pointer is required. Answer: a
TCS PROGRAMMING QUESTIONS ON FUNCTIONS AND SCOPE – 2
16. 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
Answer : a
17. Consider the following code:
function modify(a,b)
{
Integer c,d=2
c= a*d+ b
return c
}
function calculate()
{
integer a = 5, b = 20, c
integer d= 10
c = modify(a, b);
c = c+ d
print c
}
a. 80 b. 40 c. 32 d. 72 Answer: b
Explaination : c=? d=2 c=a*d+b c=a*2+b then a=5 b=20 , c=? c=c+d c=a*2+b+d
c=5*2+20+10=40
18. 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 Answer : b
19.Anu wants to make a function that is not bound to any identifier.which of the
following functions should she incorporate in her program?
a. Anonymous Function b. Friend Function
c. Null Function d. Global Function Answer: a
20. Which of the following accessibility modes can be the specifier of a top level
class‘?Top-level classes can only have public, abstract, and final modifiers, and it is
also possible to not define any class modifiers at all. This is called default/package
accessibility. Besides that, private, protected, and static modifiers cannot be used
when declaring top-level classes. Private, Protected, Public, No Modifier
a. Only Private b. Protected and Private
c. Public and No Modifier d. Only No Modifier Answer: c
21. Top-level classes can only have public, abstract, and final modifiers, and it is
also possible to not define any class modifiers at all. This is called default/package
accessibility. Besides that, private, protected, and static modifiers cannot be used
when declaring top-level classes.
Question 6 WRONG
Which of the following accessibility modes can be the specifier of a top level
class‘?Top-level classes can only have public, abstract, and final modifiers, and it is
also possible to not define any class modifiers at all. This is called default/package
accessibility. Besides that, private, protected, and static modifiers cannot be used
when declaring top-level classes. Private, Protected, Public, No Modifier
a. Only Private b. Protected and Private
c. Public and No Modifier d. Only No Modifier Answer:c
22.Top-level classes can only have public, abstract, and final modifiers, and it is
also possible to not define any class modifiers at all. This is called default/package
accessibility. Besides that, private, protected, and static modifiers cannot be used
when declaring top-level classes.
Question 7 WRONG
Choose the correct answer. A pseudo-code which is similar to that of C++ and self-
explanatory An accessible member function or data member for an object are
accessed by the statement objectname.functionname or objectname. data member
name respectively. class brush { Private: integer size, colorcode function getdata( )
{–}//Statement 1 public: integer name // Statement 2 function putdata(){…} }
function main { brush b1, b2 print bl.name //Statement 3 b2.getdata()
//Statement 4 } Deleting which line will correct the error in the code?
a.Statement 1 b.Statement 2 c.Statement 3 d.Statement 4
Answer:d
Explaination : Since, get data is private
23.Function MyDisplay(string MyStr) //statement 1 { print ―Hello !‖ print MyStr
return 1 // statement 2 } function main() //statement 3 { string str= ―Mickey‖
MyDisplay(str) // statement 4 } Which statement will generate an error.
a.Statement 1 b.Statement 2 c.Statement 3 d.Statement 4
Answer:b
24.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 equals 1 b. n equals 2 c. n >= 1 d. n > 1 Answer: a
25.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) Answer: d
TCS C PROGRAMMING QUESTIONS ON FILE HANDLING
26. The value of EOF is_____
a) -1 b) 0 c) 1 d) 10 Answer:a
27. Which of the following true about FILE *fp
a) FILE is a keyword in C for representing files and fp is a variable of FILE type.
b) FILE is a structure and fp is a pointer to the structure of FILE type
c) FILE is a stream
d) FILE is a buffered stream Answer:b
Explanation: fp is a pointer of FILE type and FILE is a structure that store following
information about opened file.
28. The first and second arguments of fopen are ______
a) A character string containing the name of the file & the second argument is the
mode
b) A character string containing the name of the user & the second argument is the
mode
c) A character string containing file poniter & the second argument is the mode
d) None of the mentioned Answer:a
29. If there is any error while opening a file, fopen will return
a) Nothing b) EOF c) NULL d) Depends on compiler Answer:c
30. fseek() should be preferred over rewind() mainly because
a) rewind() doesn‘t work for empty files b) rewind() may fail for large files
c) In rewind, there is no way to check if the operations completed successfully
d) All of the above Answer:c
31. FILE is of type ______
a) int type b) char * type c) struct type d) None of the mentioned
Answer:c
32. FILE reserved word is
a) A structure tag declared in stdio.h b) One of the basic datatypes in c
c) Pointer to the structure defined in stdio.h d) It is a type name defined in
stdio.h
Answer:d
33. 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 Answer:c
34. Which of the following functions from ―stdio.h‖ can be used in place of printf()?
a) fputs() with FILE stream as stdout. b) fprintf() with FILE stream as
stdout.
c) fwrite() with FILE stream as stdout. d) All of the above three – a, b and c.
e) In ―stdio.h‖, there‘s no other equivalent function of printf() Answer:b
35. fputs adds newline character
a) True b) False c) Depends on the standard d) Undefined behaviour
Answer:b
36. puts function adds newline character
a) True b) False c) Depends on the standard d) Undefined behaviour
Answer:a
TCS ARRAY QUESTIONS
37) An array is also known as ___________
a) Subscripted variable b) Collective array
c) Ordinary variable d) Similar Quantities variable Answer:a
38) 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.
Answer:b
39) 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
Answer:b
40) 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 Answer:c
41) What will be output of the following program
int main()
{
int b[4]={5,1,32,4};
int k,l,m;
k=++b[1];
l=b[1]++;
m=b[k++];
printf(―%d, %d, %d‖,k,l,m);
return 0;
}
a) 2, 2, 4 b) 3, 2, 32 c) 3, 2, 4 d) 2, 3, 32 Answer:b
Explaination:Here, ++b[1] means that firstly b[1] will be incremented so, b[1]=2
then assigned to k i.e. k=2.
b[1]++ means firstly b[1] will be assigned to variable l i.e. l=2, Then value stored in
b[1] will be incremented i.e. b[1]=3.
b[k++] means first b[k] will be assigned to m i.e. m=32, then value of k will be
incremented i.e. k=3.
42) What will be output of the following program where c=65474 and int=2 bytes.
int main()
{
int c[3][4]={2,3,1,6,4,1,6,2,2,7,1,10};
printf(―%u, %u\n‖, c+1, &c+1);
return 0;
}
a) 65482, 65498 b) 65476, 65476 c) 65476, 65498 d) No output Answer:a
Explaination: Here c[3][4]= {
{2,3,1,6};
{4,1,6,2};
{2,7,1,10}
};
c+1 means c is base address i.e. address of 1st one Dimensional array and on
incrementing it by 1 means it points to 2nd one 2 Dimensional array.
So, c+1=65474 + ( 4 * 2)= 65482
But, when we are writing &c, that means address of this whole array i.e. address of
next new array.
So, &c+1=65474 + (12 * 2)=65498
43) what will be output of the following program
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
Answer:a
Explaination: firstly right side of any expression is evaluated, then the left side is
evaluated. So, here ++i will be evaluated at first, then a[i].
Hence, when i=0, a[1]=1, then i=1, a[2]=2,…a[4]=4
and a[0]=garbage value
44) What will be output of the following program
int main()
{
float a[]={12.4, 2.3, 4.5, 6.7};
printf(―%d, %d‖, sizeof(a), sizeof(a[0]));
return 0;
}
a) 16 bytes, 4 bytes b) 4 bytes, 4 bytes c) 8 bytes, 4 bytes d) None of
these
Answer:a
Explaination: sizeof(a)=number of element * size of each element
=4 * 4 bytes
=16 bytes
sizeof(a[0])=size of 1st element of array a
= 4 bytes
45 Which one of this is equivalent to
int fun(int arr[])
a) int fun(arr) b) int fun(int s[]) c) int fun(int arr[2]) d) None of these
Answer:c
Explaination: int fun(int arr[]) and int fun(int arr[0]) are equivalent. Both are
prototype for function fun(), that accepts one integer array as parameter and return
an integer value.
46) In 2 Dimensional Array, it is necessary to mention _______ dimension.
a) second b) first c) both d) none of these Answer:a
Explaination :In 2D array, it is necessary to mention the second dimension,
whereas the first dimension is optional.
int arr[][3]={12,34,33,45,56,73};
47) 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
Answer:d
48) What will be output of the following program
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
Answer:a
Explaination: We cannot assign one array to another directly. We can do
assignment operation element by element. Thus reports compile time error.
TCS TECHNICAL MCQ
49) Which of the following syntax is correct for command-line arguments?
a) int main(int var, char *argv[]) b) int main(char *arv[], int arg)
c) int main(char c,int v) d) int main(int v,char c)
Answer:a
50) What does argv and argc indicate in int main(int argc, char *argv[]) ?
a) argument constant, argument variable b) argument count, argument
vector
c) argument constant, argument vector d) argument count, argument
variable
Answer:b
51) What type of array is generally generated in Command-line argument?
a) MultiDimensional Array b) Jagged Array
c) 2-Dimensional Array d) Single Dimensional Array Answer:b
52) The maximum length of the command-line arguments including the spaces is
a)May vary from one OS to another b)256 characters
c)Depends on the Number of arguments d)128 characters Answer:a
53) The index of the last argument in command line arguments is
a) argc b) argc * 2 c) argc – 1 d) argc + 1 Answer:c
54) What is the first argument of command line ?
a)File Name b)Program Designation
c)argument passed by user d)Program Name Answer:a
55)What argv means in command line argument?
a)Array of pointers b)pointer to a character array
c)Array of character pointers d)Array of Strings Answer:c
56) What will be the output of the following program if argument passed to
command lines are : prog 1 4 2
#include<stdio.h>
int main(int argc, char *argv[])
{
int j;
j = argv[1] + argv[2] – argv[3];
printf(―%d‖, j);
return 0;
}
a)Error b)3 c)Garbage Value d)None of these
Exp : > Here, argv[1], argv[2] and argv[3] are of type String. So, we have to convert
String to integer before performing arithmetic operation.
Answer:a
57) What argv[0] and argv[1] denote in Command line Arguments ?
a) Pointers to first two command line argument supplied.
b) File Name and pointer to first command line argument supplied.
c) Program Name and Pointer to the 1st argument.
d) None of these.
Answer:b
58) Which one of these is equivalent to argc ?
a) Number of Arguments b) Number of Arguments – 1
c) Number of Arguments + 2 d) Number of Arguments + 1 Answer:d
59) What will be output of the following program if argument passed to command
lines are : prog 1 4 2
#include<stdio.h>
int main(int argc, char *argv[])
{
while(argc–)
printf(―%s\n‖,argv[argc]);
return 0;
}
a) 2 4 1 b) Garbage-value 2 4 1
c) Garbage-value 2 4 1 prog d) Infinte Loop Answer:a
60) What will be output of the following program if argument passed to command
lines are : demo one two three
#include<stdio.h>
int main(int argc, char *argv[])
{
printf(―%c\n‖,**+argv);
return 0;
}
a) n b) o c) t d) Compile Time Error Answer:b
Explaination: > Here, char * argv[ ] denotes Array of Pointers. So, argv[ ] holds the
address of the command line argument passed. ++argv denote the address of next
location, which holds the address of the 2nd argument.
*++argv denote the value stored at that address i.e. the address of the 1st character
of the 2nd argument and **++argv itself denote the character ‗o‘ .
61) What will be output of the following program if argument passed to command
lines are : demo friday
#include<stdio.h>
int main(int argc, char *argv[])
{
printf(―%c‖,*++argv[1]);
return 0;
}
a) r b) f c) I d) d Answer:a
Explaination :>argv[1] can be wriiten as *(argv+1), (argv+1) denote the address of
next location, which holds the address of 2nd argument. Thus *(argv+1) or argv[1]
denote the value stored at that address i.e. denote the address of 1st character of
the 2nd Argument. ++argv[1] denote the address of 2nd character of the 2nd
Argument. So *++argv[1] itself denote the character ‗r‘ .
TCS FUNCTIONS QUESTIONS WITH SOLUTIONS
62. What is the output of this C code?
#include
void main()
{
m();
void m()
{
printf(―SimpleWay2Code‖);
}
}
a) SimpleWay2Code b) Compile time error c) Nothing d) Varies
Answer:b
63. What is the output of this C code?
#include
void main()
{
static int x = 3;
x++;
if (x <= 5) { printf(―hello‖); main(); } } a) Run time error b) hello c) Infinite hello d)
hello hello Answer:d 3. The value obtained in the function is given back to main by
using ________ keyword? a) return b) static c) new d) volatile Answer:a 4. 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
Answer:d 5. What is the return-type of the function sqrt() a) int b) float c) double d)
depends on the data type of the parameter Answer:c 6. What is the output of this
code having void return-type function? #include
void foo()
{
return 1;
}
void main()
{
int x = 0;
x = foo();
printf(―%d‖, x);
}
a) 1 b) 0 c) Runtime error d) Compile time error
Answer:d
64. The output of the code below is
#include
void main()
{
int k = m();
printf(―%d‖, k);
}
void m()
{
printf(―hello‖);
}
a) hello 5 b) Error c) Nothing d) Garbage value Answer:a
65. The output of the code below is
#include
int *m()
{
int *p = 5;
return p;
}
void main()
{
int *k = m();
printf(―%d‖, k);
}
a) 5 b) Junk value c) 0 d) Error Answer:a
66. What will be the output of the program?
#include
int main()
{
int i=1;
if(!i)
printf(―SimpleWay2Code,‖);
else
{
i=0;
printf(―C-Program‖);
main();
}
return 0;
}
A. prints ―SimpleWay2Code, C-Program‖ infinitely
B. prints ―C-Program‖ infinetly
C. prints ―C-Program, SimpleWay2Code‖ infinitely
D. Error: main() should not inside else statement
Answer:b
67. How many times the program will print ―SimpleWay2Code‖ ?
#include
int main()
{
printf(―SimpleWay2Code‖);
main();
return 0;
}
A. Infinite times B. 32767 times
C. 65535 times D. Till stack overflows Answer:d
TCS RECURSION AND ITERATION QUESTIONS
68.function main()
{
integer a=5,b=7
switch(a)
{
case 5 :print ―I am 5‖
break
case b:print ―I am not 5‖
break
default:print ―I am different‖
}
}
a.I am 5 b.I am not 5 c.I am different d.Error Answer:d
Explanation: Break doesn‘t have -> ;
69.Ashima wants to print a pattern which includes checking and changing a
variables value iteratively She decides to use a loop/condition Which of the
following options should she use such that the body of the loop/condition is
executed atleast once whether the variable satisfies the entering condition or not?
a.For Loop b.While Loop c.Do While Loop d.Switch Case Answer:c
70.The construct ―if (condition) then A else B‖ is for which of the following
purposes? 1) 2) 3) 4)
a.Decision-Making b.Iteration c.Recursion d.Object Oriented Programming
Answer:a
71.Ravi and Rupali are asked to write a program to sum the rows of 2X2 matrices
stored in the array A. Ravi writes the following code (Code A): for n = 0 to 1
sumRow1[n] = A[n][1] + A[n][2] end Rupali writes the following code (Code B):
sumRow1[0] = A[0][1] + A[0][2] sumRow1[1] = A[1][1] + A[1][2] Comment upon these
codes (Assume no loop unrolling done by compiler):
a.Code A will execute faster than Code B. b.Code B will execute faster than
Code A
c.Code A is logically incorrect. d.Code B is logically incorrect.
Answer:b
72.Integer a =40, b =35, c=20, d =10 Comment about the output of the following
two statements •
Print a*b/c-d
Print a*b/(c-d)
Comment about the output of the following two statements
a.Differ by 80 b.Same c.Differ by 50 d.Differ by 160 Answer:a
73.What is the output of the following pseudo code? Int a =456,b,c,d=10; b=a/d;
c=a-b; print c;
a.411.4 b.411 c.410.4 d.410 Answer: b
74.Ashima wants to print a pattern which includes checking and changing a
variables value iteratively She decides to use a loop/condition Which of the
following options should she use such that the body of the loop/condition is
executed atleast once whether the variable satisfies the entering condition or not?
a.For Loop b.While Loop c.Do While Loop d.Switch Case
Answer:c
75.The construct ―if (condition) then A else B‖ is for which of the following
purposes?
a.Decision-Making b.Iteration c.Recursion d.Object Oriented
Programming
Answer:a
76.Function main() { Integer i=0.7 Static float m=0.7 If(m equals i) Print(―We are
equal‖) Else If(m>i) Print(―I am greater‖) Else Print(―I am lesser‖)
a.We are equal b.I am greater c.I am lesser d.This code will generate an
error
Answer:d
TCS VARIABLES AND REGISTERS QUESTIONS
77. What is the output of this C code?
#include
void main()
{
static int i;
printf(―i is %d‖, i);
}
a) 0 b) 1 c) Garbage Value d) Run time error Answer:a
78. What is the output of this C code?
#include
int *i;
int main()
{
if (i == NULL)
printf(―true\n‖);
return 0;
}
a) true b) true only if NULL value is 0
c) Compile time error d) Nothing Answer:a
79. What is the output of this C code?
#include
static int i;
void main()
{
int i;
printf(―i is %d‖, i);
}
a) 0 b) Garbage Value c) Run time error d) Nothing
Answer:b
80. What is the output of this C code?
#include
static int x = 5;
void main()
{
x = 9;
{
int x = 4;
}
printf(―%d‖, x);
}
a) 9 b) 4 c) 5 d) 0 Answer:a
81. The scope of an automatic variable is:
a) Within the block it appears
b) Within the blocks of the block it appears
c) Until the end of program
d) Within the block it appears & Within the blocks of the block it appears
Answer:d
82. Automatic variables are allocated space in the form of a:
a) stack b) queue c) priority queue d) random
Answer:a
83. Which of the following is a storage specifier?
a) enum b) union c) auto d) volatile Answer:c
84. Automatic variables are stored in
a) stack b) data segment c) register d) heap Answer:a
85. What is the output of this C code?
#include
int main()
{
register int i = 10;
int *q = &i;
*q = 11;
printf(―%d %d\n‖, i, *q);
}
a) Depends on whether i is actually stored in machine register
b) 10 10 c) 11 11 d) Compile time error Answer:d
86. Register storage class can be specified to global variables
a) true b) false c) Depends on the compiler d) Depends on the
standard
Answer:b
87. Register variables reside in
a) stack b) registers c) heap d) main memory Answer:b
88. Which of the following operation is not possible in a register variable?
a) Reading the value into a register variable b) Copy the value from a memory
variable
c) Global declaration of register variable d) All of the mentioned Answer:d
TCS QUESTIONS ON LOOPS
89. The output of the code below is
#include
int a;
void main()
{
if (a)
printf(―Hello‖);
else
printf(―world‖);
}
a) Hello b) World c) compile time error d) none of the mentioned
Answer:b
90. The output of the code below is
#include
void main()
{
int a = 5;
if (true);
printf(―hello‖);
}
a) It will display hello b) It will throw an error c) No Output d) Depends on
Compiler
Answer:b
91. The output of the code below is
#include
void main()
{
int a = 0;
if (a == 0)
printf(―hi‖);
else
printf(―how are u‖);
printf(―hello‖);
}
a) hi b) how are you c) hello d) hihello
Answer:d
92. The following code ‗for(;;)‘ represents an infinite loop. It can be terminated by.
a) break b) exit(0) c) abort() d) all of the mentioned Answer:a
93. The correct syntax for running two variable for loop simultaneously is.
a) for (i = 0; i < n; i++) for (j = 0; j < n; j += 5) b) for (i = 0, j = 0;i < n, j < n; i++, j +=
5) c) for (i = 0; i < n;i++){} d) for (j = 0; j < n;j += 5){} Answer:b 6. Which for loop has
range of similar indexes of ‗i‘ used in for (i = 0;i < n; i++)? a) for (i = n; i>0; i–)
b) for (i = n; i >= 0; i–) c) for (i = n-1; i>0; i–) d) for (i = n-1;
i>-1; i–)
Answer:d
94. The output of this C code is?
#include
void main()
{
int x = 0;
for (x < 3; x++) printf(―Hello‖); } a) Compile time error b) Hello is printed thrice c)
Nothing d) Varies Answer:a 8. The output of this C code is? #include
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 Answer:b 9. The output of this
C code is? #include
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
Answer:b
95. The output of this C code is?
#include
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 Answer:a
96. Which of the following cannot be used as LHS of the expression in for (exp1
;exp2 ; exp3) ?
a) Variable b) Function c) typedef d) macros
Answer:d
97. Which keyword can be used for coming out of recursion?
a) break b) return c) exit d) Both break and return
Answer:b
98. The keyword ‗break‘ cannot be simply used within:
a) do-while b) if-else c) for d) while Answer:b
99. Which keyword is used to come out of a loop only for single iteration?
a) break b) continue c) return d) none of the mentioned
Answer:b
100. The output of this C code is? #include
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
Answer:d
TCS VARIABLES AND DATA TYPES QUESTIONS
101. Which of the following is not valid variable name declaration?
a) int __v1;
b) int __1v;
c) int __V1;
d) None
Ans:d
102. Which of the following is not a valid variable name declaration?
a) int _v1; b) int v_1; c) int 1_v; d) int _1v Ans:c
Explanation:Variable name can‘t start with a digit.
103. Variable names beginning with underscore is not encouraged. Why?
a) It is not standard form
b) To avoid conflicts since assemblers and loaders use such names
c) To avoid conflicts since library routines use such names
d) To avoid conflicts with environment variables of an operating system
Ans:c
104. Which is not a valid C variable name?
a) int number; b) float rate; c) int variable_count; d) int $main;
Ans:d
105.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
106. What will be the output?
#include
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 Ans:c
Explanation:A C program can have same function name and same variable name.
107. Which of the following cannot be a variable name in C?
a) friend b) true c) volatile d) export Ans: c
Explanation:volatile is C keyword
108. The format identifier ‗%i‘ is also used for _____ data type?
a) char b) double c) float d) int Ans:d
Explanation:Both %d and %i can be used as a format identifier for int data type.
109. Which of the following is a User-defined data type?
a) struct {char name[10], int age};
b) typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays;
c) typedef int Boolean;
d) all of the mentioned
Answer:d
110. What is short int in C programming?
a) Basic datatype of C
b) Qualifier
c) short is the qualifier and int is the basic datatype
d) All of the mentioned
Ans:c
111. What is the output of this C code?
#include
int main()
{
signed char chr;
chr = 128;
printf(―%d\n‖, chr);
return 0;
}
a) 128
b) -128
c) Depends on the compiler
d) None of the mentioned
Ans:b
Explanation:signed char will be a negative number.
112. What is the size of an int data type?
a) 4 Bytes
b) 8 Bytes
c) Depends on the system/compiler
d) Cannot be determined
Ans:c
113. Which of the datatypes have size that is variable?
a) int
b) struct
c) float
d) double
Ans:b
Explanation:Since the size of the structure depends on its fields, it has a variable
size.
114. What is the output of this C code?
#include
int main()
{
float x = ‗a‘;
printf(―%f‖, x);
return 0;
}
a) 97.000000
b) run time error
c) a.0000000
d) a
Ans:a
Explanation:Since the ASCII value of a is 97, the same is assigned to the float
variable and printed.
TCS TECHNICAL QUESTIONS ON ABSTRACTION
115.What makes a class abstract?
a.By making all member functions constant.
b.By making at least one member function as pure virtual function.
c.By declaring it abstract using the static keyword.
d.By declaring it abstract using the virtual keyword.
Answer:b
116.Which type of class allows only one object of it to be created?
a.Virtual class
b.Abstract class
c.Singleton class
d.Friend class
Answer:c
117.Which of the following concepts of OOPS means exposing only necessary
information to client?
a.Encapsulation
b.Abstraction
c.Data hiding
d.Data binding
Answer:d
118.Which type of inheritance needs a virtual function:
a.Multi level inheritance
b.Multiple inheritance
c.Hybrid inheritance
d.All of the above
Answer:d
119.Which of the following cannot be inherited?
a.Friend function
b.Static function
c.Destructor
Answer:b
120.Which of the following are available only in the class hierarchy chain?
a.Public data members
b.Private data members
c.Protected data members
d.Member functions
Answer:c
121.Which of the following is not a type of inheritance?
a.Multiple
b.Multilevel
c.Distributive
d.Hierarchical
Answer:c
122.The process of building new classes from existing one is called ______.
a.Polymorphism
B
b.Structure
c.Inheritance
d.Cascading
Answer:c
123.Which of the following supports the concept of hierarchical classification?
a.Polymorphism
b.Encapsulation
c.Abstraction
d.Inheritance
Answer:d
124.Which Keyword from the following is used to inherit properties from one class
into another?
a.extends
b.subclasses
c.native
d.all of the mentioned
Answer:a
TCS PLACEMENTS INPUT OUTPUT QUESTIONS
125.Which one of the following connects the high-speed high-bandwidth device to
memory subsystem and CPU.
a.expansion bus
b.PCI bus
c.SCSI bus
d.none of the mentioned
Answer:a
126.The _________ present a uniform device-access interface to the I/O subsystem,
much as system calls provide a standard interface between the application and the
operating system.
a.devices
b.buses
c.device drivers
d.I/O systems
Answer:c
127.When device A has a cable that plugs into device B, and device B has a cable
that plugs into device C and device C plugs into a port on the computer, this
arrangement is called a _________.
a.port
b.daisy chain
c.bus
d.cable
Answer:b
128.The _________ determines the cause of the interrupt, performs the necessary
processing and executes a return from the interrupt instruction to return the CPU
to the execution state prior to the interrupt.
a.interrupt request line
b.device driver
c.interrupt handler
d.All of these
Answer:c
129.The ______ register is read by the host to get input.
a.flow in
b.flow out
c.data in
d.data out
Answer:c
130.The ______ register is written by the host to send output.
a.status
b.control
c.data in
d.data out
Answer:d
131.The CPU hardware has a wire called __________ that the CPU senses after
executing every instruction.
a.interrupt request line
b.interrupt bus
c.interrupt receive line
d.interrupt sense line
Answer:a
132.The _________ are reserved for events such as unrecoverable memory errors.
a.non-maskable interrupts
b.blocked interrupts
c.maskable interrupts
d.None of these
Answer:a
133.The hardware mechanism that allows a device to notify the CPU is called
_______.
a.polling
b.interrupt
c.driver
d.controlling
Answer:b
134.Spooling :
a.holds a copy of the data
b.is fast memory
c.holds the only copy of the data
d.holds output for a device
Answer:c,d
TCS QUESTIONS ON POLYMORPHISM
135.Which of the following is not a valid type of polymorphism?
a.adhoc polymorphism
b.imperative polymorphism
c.predicative polymorphism
d.inclusion polymorphism
Answer:b
136.What is the function used to describe the situation, when a function in base
class is redefined in inherited class?
a.Inheritance
b.Overriding
c.Overloading
d.Encapsulation
Answer:b
137.How can a call to an overloaded function be ambiguous?
a.By misspelling the name
b.There might be two or more functions with the same name
c.There might be two or more functions with equally appropriate signatures
d.None of these
Answer:b
138.A complete binary tree with the property that the value at each node is at least
as large as the values at its children is known as
a.Binary search tree
b.AVL tree
c.Completely balanced tree
d.Heap
Answer:d
Exp:A max-heap is a complete binary tree in which the value in each internal node
is greater than or equal to the values in the children of that node.
139.Which of the following correctly describes overloading of functions?
a.Virtual polymorphism
b.Transient polymorphism
c.Ad-hoc polymorphism
d.Pseudo polymorphism
Answer:c
140.Which of the following operator is overloaded for object cout?
a.>>
b.<< c.+ d.= Answer:a 7.Which of the following operators cannot be overloaded? a.[]
b.->
c.?:
d.*
Answer:d
141.Which of the following is a mechanism of static polymorphism?
a.Operator overloading
b.Function overloading
c.Templates
d.All of the above
Answer:d
142.Which of the following keyword is used to overload an operator?
a.Overload
b.Operator
c.Friend
d.Override
Answer:b
143.The operator << when overloaded in a class a.must be a member function
b.must be a non member function c.can be both (A) & (B) above d.cannot be
overloaded Answer:c
TCS TECHINCAL QUESTIONS WITH SOLUTIONS SET -1
144.Which of this is used to skip one iteration:
A) break
B) continue
C) goto
D) return
Answer:b
145.Which of the following does not require to include math.h header file?
A) pow()
B) rand()
C)sqrt()
D) sinh()
Answer:b
146.Which has the highest precision?
A. float
B. double
C. unsigned long int
D. Long int
Answer:b
147.Choose the correct statement
while (0 == 0) { }
A) It has syntax error as there are no statements within braces {}
B) It will run forever
C) It compares 0 with 0 and since they are equal it will exit the loop immediately
D) It has syntax error as the same number is being compared with itself
Answer:b
148.Predict the output of following code:
main()
{
int a=10,x;
x= a– + ++a;
printf(―%d‖,x);
}
A) 19
B) 20
C) 22
D) 23
Answer:b
149.Guess the output:
main()
{
printf(―%d‖, sizeof(‗a‘));
//same as → sizeof(97)
}
A) 2 or 4 —
B) 1 or 3
C) Garbage value
D) ASCII value of a
Explaination:
sizeof takes ascii value of character and determines number of bytes required by it.
Ascii is number, Number is of type int. so integer requires either 2 in 16 or 4 in 32
bit machine
Answer:a
150.Predict the output of following code:
main()
{
int a=b=c=d=10;
printf(―%d,%d,%d,%d‖,a,b,c,d);
}
A) Error
B) 10,10,10,10
C) Garbage Value,Garbage Value,Garbage Value,10
D) Garbage Value,Garbage Value,Garbage Value,Garbage Value
Explaination: error: ‗b‘ , ‗c‘, ‗d‘ undeclared
Answer:
151.Select the missing statement?
#include
long int fact(int n);
int main()
{
\\missing statement
}
long int fact(int n)
{
if(n>=1)
return n*fact(n-1);
else
return 1;
}
A) printf(―%ll\n‖,fact(5));
B) printf(―%u\n‖,fact(5));
C) printf(―%d\n‖,fact(5));
D) printf(―%ld\n‖,fact(5));
Answer:d
152. If a function‘s return type is not explicitly defined then it‘s default to ______ (In
C).
A) int
B) float
C) void
D) Error
Answer:a
153. How many times the below loop will be executed?
#include
int main()
{
int i;
for(i=0;i<5;i++) printf(―Hello\n‖); } A) 5 B) 1 C) 0 D) 3 Answer:a
TCS TECHINCAL QUESTIONS WITH SOLUTIONS SET -2
154. How many times loop will executed ?
#include
int main()
{
int x,y;
for(x=5;x>=1;x–)
{
for(y=1;y<=x;y++)
printf(―%d\n‖,y);
}
}
a) 11
b) 13
c) 15
d) 10
Answer:c
155. Which of the following indicate the end of file ?
a) feof()
b) EOF
c) Both feof() and EOF
d) None of the mentioned
Answer:c
156. If a functions return type is not explicitly defined then it is default to ……….(in
C).
a) int
b) float
c) void
d) error
Answer:a
157. Where the local variable is stored ?
a) Disk
b) Stack
c) Heap
d) Register
Answer:b
158. How many times loop will executed ?
#include
int main()
{
int i;
for(i=0;i<5;i++)
{
printf(―Hello\n‖);
}
}
a) 0
b) 1
c) 3
d) 5
Answer:d
159. What is dangling pointer?
a) points to garbage value
b) points to function
c) Both A and B
d) None of these
Answer:a
160. what is the purpose of ftell ?
a)to get the current file position
b)to get the current file attribute
c)to get the current file status
d)to get the current file name
Answer:a
161. What is recursion ?
a) looping
b) a function calls another function repeatedly
c) a fnction calls repeatedly
d) function calls itself repeatedly
Answer:d
162. What is the similarity between enum and struct ?
a) can assign new values
b) can create new data types
c) nothing in common
d) they are same
Answer:b
163. which of the following is not a fundamental datatype?
a) Enum
b) unsigned long int
c) Long int
d) double
Answer:
164. How many times hello will print ?
#include
int main(void)
{
int i;
for(i=0;i<5;i++);
printf(―hello‖);
}
a) Compilation error
b) Runtime error
c) 4
d) 1
Answer:b
TCS C PROGRAMMING MULTIPLE CHOICE SET- 3
165. atoi() function is used for:
a)convert ASCII character to integer value
b)convert a character string to its equivalent integer value
c)gets index value of character in an array
d)converts an array of characters to array of equivalent integers
Answer:b
166. Which of the following is NOT declared in string.h ?
a) strlen()
b) strcpy()
c) strptr()
d) strupr()
Answer:c
167. which of the below function is NOT declared in math.h ?
a) and()
b) pow()
c) exp()
d) acos()
Answer:a
168. Where are the local variable stored ?
a) In a Queue
b) In stack Memory
c) In hard Disk
d) In heap Memory
Answer:a
169. while declaring parameters for main, the second parameter argv should be
declared as
a) char argv[]
b) char argv
c) char ** argv[]
d) char * argv[]
Answer:d
170. A memory leak happens when
a) a program allocates memory in heap but forgets to be allocate it
b) when an un-assigned pointer is used is freed using free function
c) when realloc() is called on a pointer that is not allocated
d) A program allocates memory in stack
Answer:a
TCS TECHNICAL MCQS SET 4
171.A pointer variable can be
1. Changed within function.
2. Assigned an integer value.
3. None of these
4. Passed to a function as argument.
172. Which of the following uses structure?
1. Linked Lists
2. Array of structures
3. All of these
4. Binary Tree
173. Strings are character arrays. The last index of it contains the null-
terminated character
1. \t
2. \1
3. \0
4. \n
174. Which of the following is a collection of different data types?
1. String
2. Structure
3. Array
4. Files
175. What function should be used to free the memory allocated by calloc() ?
1. free();
2. malloc(variable_name, 0)
3. dealloc();
4. memalloc(variable_name, 0)
176. In the standard library of C programming language, which of the
following header file is designed for basic mathematical operations?
1. conio.h
2. stdio.h
3. math.h
4. dos.h
177. int **ptr; is?
1. Pointer to integer
2. None of these
3. Pointer to pointer
4. Invalid declaration
178. Which of the following special symbol allowed in a variable name?
1. (underscore)
2. – (hyphen)
3. | (pipeline)
4. * (asterisk)
179. All keywords in C are in
1. Uppercase letters
2. None of these
3. Lowercase letters
4. Camel Case letters
180. What should the program below print?
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void myfunc(char** param){
++param;
}
int main(){
char* string = (char*)malloc(64);
strcpy(string, ―hello_World‖);
myfunc(&string);
myfunc(&string);
printf(―%s\n‖, string);
// ignore memory leak for sake of quiz
return 0;
}
1. hello_World
2. ello_World
3. lo_World
4. llo_World
TCS COMPUTER PROGRAMMING MCQ QUESTIONS – 5
181: What is the output of this C code?
#include <stdio.h>
void main()
{
int k = 5;
int *p = &k;
int **m = &p;
printf(―%d%d%d\n‖, k, *p, **p);
}
a) 5 5 5
b) 5 5 junk
c) 5 junk junk
d) Compile time error
182. Which of the following statements about stdout and stderr are true?
a) They both are the same
b) Run time errors are automatically displayed in stderr
c) Both are connected to the screen by default.
d) stdout is line buffered but stderr is unbuffered.
183: Given the below statements about C programming language;
1) main() function should always be the first function present in a C program file
2) all the elements of an union share their memory location
3) A void pointer can hold address of any type and can be typecasted to any type
4) A static variable hold random junk value if it is not initialised
Which of the above are correct statements?
A) 2,3
B) 1,2
C) 1,2,3
D) 1,2,3,4
Q4 If a function is defined as static, it means
A) The value returned by the function does not change
B) all the variable declared inside the function automatically will be assigned initial
value of zero
C) It should be called only within the same source code/program file.
D) None of the other choices as it is wrong to add static prefix to a function
185: Comment on the below while statement18while (0 == 0) { }
A) It has syntax error as there are no statements within braces {}
B) It will run forever
C) It compares 0 with 0 and since they are equal it will exit the loop immediately
D) It has syntax error as the same number is being compared with itself
TCS COMPUTER PROGRAMMING MCQ QUESTIONS – 6
186. The function ____ obtains block of memory dynamically.
a) calloc
b) malloc
c) Both calloc & malloc
d) free

187. For a typical program, the input is taken using


a) scanf
b) Files
c) Command-line
d) All of the mentioned

188. What is the default return-type of getchar()?


a) char
b) int
C. char *
D. reading character doesn‘t require a return-type

189. Memory allocation using malloc() is done in?


a) Static area
b) Stack area
c) Heap area
d) Both Stack & Heap area

190. What is the sizeof(char) in a 32-bit C compiler?


a) 1 bit
b) 2 bits
c) 1 Byte
d) 2 Bytes

191. What type of value does sizeof return?


a) char
b) short
c) unsigned int
d) long

192. Which one is used during memory deallocation in C?


a) remove(p);
b) delete(p);
c) free(p);
d) terminate(p);

193. 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
TCS C PROGRAMMING MCQ QUESTIONS – 7
194. Which is the character array used to accept command line arguments?
A) char argv
B) char* argv[]
C) char argv[]
D) char* argv
Ans: b
195 Which is not a string function?
A) strstr
B)strcmp
C) strupr
D) strchr
Ans: c
196 Which of the following does not require to include math.h header file?
A) pow()
B) rand()
C)sqrt()
D) sinh()
Ans: b
197 What is the task of pre-processor?
A) Expanding
B) Compiling
C) Linking
D) All of the above
Ans: a
198 Which of the following is true?
A) realloc() can change the memory size of arrays
B) Unary operator works on only one operand
C) Struct and Union works in same way.
D) None of the above
Ans: b
199 Which of this is used to skip one iteration:
A) break
B) continue
C) goto
D) return
Ans: b
200 Which address does a pointer to an array store:
A) Memory address of the first element of the array Don‘t remember the other
options.
201 Predict the output:
float a = 0.1;
if(a==0.1)
printf(―Yes‖);
else
printf(―No‖); Answer would be No.
Ans: no

Вам также может понравиться