SELFLESS FRESHERS JOB
Notebook: <Inbox>
Created: 30-07-2019 23:40 Updated: 07-08-2019 00:35
Author: [email protected]
Tags: Selfless(freshers job), TCS 2019
SELFLESS FRESHERS JOB
YOUR DREAM IS MINE DREAM......
1.Output of following program?
#include
int main()
printf("%d", printf("%d", printf(“%d”,543210)));
return 0;
1. 54321061
2. 543210
3. 5432101
4. 5432106
q2.
Predict the output of following code:
main()
printf(“ %d ”,printf(“ FACE ”)); //valid
1.FACE4
2. Error
3. Garbage value
4. FACE
quetion 3.#include
int main()
int i,j;
for(i=0;i<5;i++)
i=j=i;
j=0;
printf("%d",j);
ANS=0
quetion 4.Predict the output of following code:
main()
if(1) // True always
printf(“hai”);
else
printf(“hello”);
1. Error
2. hai
3. hello
4. No output
quetion 4.
Predict the output of following code:
main()
int a=10,x;
x= a-- + ++a;
printf(“%d”,x);
1. 19
2. 20
3. 22
4. 23
quetion 5.
Output of following program?
#include
int main()
printf("%d", printf("%d", 1234));
return 0;
1. 12344
2. 12341
3. 11234
4. 41234
quetion5.
Predict the output of following code:
main()
int a=b=c=d=10;
// error: ‘b’ , ‘c’, ‘d’ undeclared
printf(“%d,%d,%d,%d”,a,b,c,d);
1. Error
2. 10,10,10,10
3. GV,GV,GV,10
4. GV,GV,GV,GV
quetion6.
Predict the output of following code:
main()
int x,a=10;
x=a==10?printf("hait"):printf("hellon");
printf("%d",x);
1.hait4
2. Error
3. hello 3
4. hait hello
quetion 7.
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
Ex:- void *ptr; // Now ptr is a general purpose pointer variable
When a pointer variable is declared using keyword void – it becomes a general purpose pointer variable.
Address of any variable of any data type (char, int, float etc.)can be assigned to a void pointer variable.
2. Introduction to pointers in C, We use the indirection operator * to serve the purpose. But in the case of a void
pointer we need to typecast the pointer variable to dereference it. This is because a void pointer has no data type
associated with it. There is no way the compiler can know (or guess?) what type of data is pointed to by the void
pointer. So to take the data pointed to by a void pointer we typecast it with the correct type of the data holded
inside the void pointers location.
void *ptr; // Declaring a void pointer
(int*)ptr - is used for type casting. Where as *((int*)ptr) dereferences the typecasted void
pointer variable.
ptr=&b; // Assigning address of float to void pointer.
quetion8.
Predict the output of following code:
main()
int i=10;
printf(“%d,%d”,++i,++i);
1. 11,12
2. 12,11
3. 10,11
4. 11,10
quetion 9.
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
quetion 20.
Predict the output of following code:
main()
int x,a=10;
x=9*5+ 7/3 -6+a; //45+2-6+10 = 51 // 7/3 =2 int division
printf(“%d”,x);
1. 51
2. 51.5
3. 31
4. None of these
quetion 11.
Comment on the below while 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
quetion 12.
Is there any difference between following declarations?
A : extern int fun();
B : int fun();
1.Both are identical
2.No difference, except extern int fun(); is probably in another file
3.int fun(); is overrided with extern int fun();
4.None of these
quetion 13.
what will be the o/p of the program
main()
char s[ ]="man";
int i;
for(i=0;s[ i ];i++)
printf("n%c%c%c%c",s[i ],*(s+i),*(i+s),i[s]);
}
output::nmmmmnaaaannnnn
quetion 14.
Guess the output:
main()
printf(“n ks”);
printf(“b mi a”);
printf(“r ha n”);
1. ksmiha
2. mis
3. hai
4. hamiks
quetion 15.
Predict the output of following code:
main()
int a=2;
switch(a)
case 1: printf(“one”);
case 2: printf(“Two”);
// Executable code ; No break statement
case 3: printf(“Three”);
default:printf(“Invalid option”);
}
1. onetwothree
2. Invalid option
3. one two
4. None of these
quetion 16.
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
quetion 16. 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
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
quetion 17. Which of the following is NOT declared in string.h ?
a) strlen()
b) strcpy()
c) strptr()
d) strupr()
quetion 18. which of the below function is NOT declared in math.h ?
a) and()
b) pow()
c) exp()
d) acos()
quetion 19. Where are the local variable stored ?
a) In a Queue
b) In stack Memory
c) In hard Disk
d) In heap Memory
quetion20. 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[]
quetion21. 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
quetion22. The function ____ obtains block of memory dynamically.
a) calloc
b) malloc
c) Both calloc & malloc
d) free
quetion23. For a typical program, the input is taken using
a) scanf
b) Files
c) Command-line
d) All of the mentioned
quetion24. What is the default return-type of getchar()?
a) char
b) int
C. char *
D. reading character doesn’t require a return-type
quetion25. Memory allocation using malloc() is done in?
a) Static area
b) Stack area
c) Heap area
d) Both Stack & Heap area
quetion26. What is the sizeof(char) in a 32-bit C compiler?
a) 1 bit
b) 2 bits
c) 1 Byte
d) 2 Bytes
quetion26. What type of value does sizeof return?
a) char
b) short
c) unsigned int
d) long
quetion27. Which one is used during memory deallocation in C?
a) remove(p);
b) delete(p);
c) free(p);
d) terminate(p);
quetion28. 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
quetion29.Eesha was in a wonderland where she saw a treasure trove of seven items of various items (in
lakhs) and weights (in kgs) as per the table given below.
items values weights
1 12 4
2 10 6
3 8 5
4 11 7
5 14 3
6 5 10
7 5 12
She wanted to bring back maximum value of items but she was not able to carry more than 10 kgs. Using
dynamic programing, what is the maximum value of of the items that she could carry back with her.
Answer: 26
Question 30
In c language, if a function return type is not explicitly defined then it defaults to what data type?
Answer: Int
Question 31
Which of the following syntax is correct for command -line arguments?
a. int main (char *argv[], int argc)
b. none of the three options
c. int main ()
int argv, char *argc[];
d. int main(int var, char *varg[])
Answer: int main (int var,char *varg[])
Question 32
Advanced The figure depicts a search space in which the nodes are labelled with names like A,B,A1,B1.
Node S is the start node. The goal are drawn as square boxes and the other noted in circle Enter answer
as a sequence of node separated by a comma, please DO NOT enter any blanks anywhare in the response
For example, If the answer (order of nodes) is a followed by c, followed by A1, followed by D, the answer
should be A,C,A1,D
Starting with the node start node,list the order in which the depth first search algorithm explore the graph
till termination, searching from right to left until it reaches one of the goal nodes.
Answer: S,C,J,T,I1
Question 33
The full set of operations allowed on a stack are
a. Push ,pop
b. Push,pop,remove
c. Push,pop, add,remove
d. Push,pop,add,remove,substitute
Answer: push,pop
Question 34
Realloc () function is used to:
a. Get back the memory that was released earlier using dree() funcion
b. Reallocate a file pointer when switching between files
c. Change the size of an array
d. Change the size of dynamically allocated memory
Answer: change the size of dynamically allocated memory
Question 35
Advanced Consider a hash function that distributes keys uniformly. The hash table size is 20. After
hashing of how many keys will the probability that any new key hashed collides with an existing one
exceed 0.5.
a. 10
b. 7
c. 6
d. 5
Answer: 10
Question 37
Which of the below is NOT a data type in C language:
1. Signed int
2. Big int
3. Short int
4. Long int
Answer: Big int
Question 38
Eesha wants to implement an image viewer application to view images in a given folder. The application
will be able to display an image and will also know what its next and previous images are at any given
point of time so that the user can so that the user can view next/previous image by pressing right/left keys
on the keyboard. Which data structure is appropriate for Esha to use?
1. Tree
2. Queue
3. Linked list
4. Stack
Answer: Linked list
Question 39
The pseudo code below sorts an array using bubble sort. Here A is the array and the” n” is the number of
element in it. Function swap exchanges the value of 2 given value.
1. Function bubbleSort(A,B)
2. {
3. For i =0 to n-2 step 1
4. For j = 0 to n-1-2 step 1
5. if( A (j) > A(j+1))
6. Swap(A(j),A(j+1))
7. }
This function is called with A and 7 as parameter where the array a initially contains the element 64, 34,
25,12, 22, 11, 9
1. 34 25 12 22 11 9 64
2. 25 12 22 11 9 34 64
3. 11 9 12 22 25 34 64
4. 12 11 9 22 25 34 64
Answer:25 12 22 11 9 34 64
Question 40
Advanced Consider a hash function that distributes keys uniformly. The hash table size is 20. After
hashing of how many keys will the probability that any new key hashed collides with an existing one
exceed 0.5.
1. 10
2. 7
3. 6
4. 5
Question 41
#define is used to
a. Define a variable
b. Define a macro
c. Define a function
d. Define a constant
Question 42
What type of data structures are queues?
a. First in last out
b. First in first out
c. Last in first out
d. Last in last out
Question 43
Which of the following is NOT a valid storage class in C language?
a. Extern
b. Dynamic
c. Register
d. Auto
Question 44
Eesha is developing a word processing software in which she wants to provide undo feature.the software
will maintain all the sequential changes and at any point of time pressing control z will undo the latest
change,what data structure should Eesha use for this?
a. Stack
b. Queue
c. Linked list
d. Array
Question 45
#include<stdio.h>
Main(int argc,char**argv)
printf(“%s\n”,argv[–argc]);
Return 1;
The above program was run with the following command line parameters
Asha usha nisha easha
What was the output?
a. Nisha
b. Unable to run due to compilation error
c. No output,run time error
d. Eesha
Question 46
Considering a hash table with 100 slots. Collisions are resolved using chaining. Assuming simple uniform
hashing, what is the probability that the first 3 slots are unfilled after the first 3 insertions? (NOTE:100 ^ 3
means 100 raised to the power 3)
a. (97 * 96 * 95) / 100 ^ 3
b. (97 * 96 * 95) / (6 * 100 ^ 3)
c. (97 * 97 * 97 ) / 100 ^ 3
d. (99 * 98 * 97) / 100 ^3
Question 47
Advanced Consider the following graph starting at node A. In what order will the nodes be visited using a
breadth first search?
NOTE 1 : Is there is ever a decision between multiple neighbour nodes in the algorithm, assume we always
choose the letter closest to the beginning of the first alphabet
NOTE 2: Enter the answer as a sequence of nodes separated by a comma. Please do NOT enter any blanks
anywhere in the response. For example, is the answer (order of nodes) is A followed by C, followed by X,
followed by D. the answer should be A,C,X,D.
Answer: A,B,D,E,G,C,H,F
Question 48
This function is called with A and 7 as parameters where the array A initially contains the elements
34,14,65 be the value of the elements in A after 3 iterations of the outer loop?
a. 14 12 22 5 34 65 71
b. 14 34 22 12 65 5 71
c. 14 22 12 34 5 65 71
Question 50
Eesha is developing an IP telephony software in which the audio is encoded and transmitted by the sender
as network packets through a communication channel. At the other end these packets are assembled and
processed further.eesha recognizes that there maybe a very large number of packets this number is
unknown nd which will be processed while more packets are being received .assume that the packets
arrive in right order .what data structure should eesha use?
Array
List
Queue
Stack
Question 51
A structure in C language is
System defined data type that holds predefined collection of data types
User defined data type holding similar or dissimilar data types
Another name for union data type
A collection of similar user defined data type
Question 52
Which of the following is true for binary tree ?
A) a node can have a single child also
B) it must have two child only
C) other options I don’t remember r
Question 53
For(i=7;i!=0;i–)
Print(“%d”,i);
Ch=get char();
What will be the output?
Compilation error
infinite loop
Number display from 7 to 1 in descending order.
Number display from 7 to 0 in descending order
Question 54
The expression seems to be infix is solved using the data structure
stack
queue
linked list
tree
Question 55
To get the most accurate value we prefer the data type
int
long int
float
double
Question 56
main(int argc,char*argv[])
in the above Definition of main function the variable argv denotes:
An array of character pointers the first array item pointing to the program name and remaining
pointing to the command line parameters
An array of character pointer each pointing to the command line parameters
A pointer to character that points to command line parameters
A pointer to pointer that points to the memory location where the program has been loaded to
the memory
Question 57
#include <stdio.h> Int main()
Int n,ch, for(n=7;n!=0;n–)
printf(“n=%d”,n–) ch=getchar(); Return 0;
1.Infinite loop
2.Numbers 7 to 0 in descending order
3.None of the other choices as there is a compilation error Numbers 7 to 1 in descending order.
Ans: Infinite loop
Question 58
Eesha works for ISRO where she is involved in a mission to intercept a comet that is likely to collide with
in each with in 1 month.she is developing a c program to calculate the trajectory of the missile to be
launched to intercept and destroying the approaching comet.in order to achieve highest accuracy of the
missile trajectory what data type should she use for the variables in her equation??
1. Long int
2. Double
3. Float
4. Int
Question 59
a program reads in 500 integers in the range [0…100]representing the scores of 500 students.it then prints
the frequency of each score above 50.what would be the best way for the program to store the
frequencies?
1. An array of 101 numbers
2. An array of 50 numbers
3. An array of 500 numbers
4. A dynamically allocated array of 550 numbers
Question 60
Which of the following is TRUE about binary trees?
The number of nodes on the last level is equal to the sum of the number of nodes on all other levels
1.A node may have one child
2.The total number of nodes is one less than a power of 2
3. Every node must have 2 children
Question 61
#include <studio . h> Long int fact (int n);
Int main ()
Int n;
Printf (“enter a positive integer: “); Scanf (“%d”, &n);
printf(“factorial of %d = %ld “, n, fact (n)); Return 0;
Long int fact (int n)
If (n.=1)
Return n*fact (n-1)
Else
Return 1;
Ans: recursion
Question 62
Not a core of os
1. multi tasking
2. memory management
3. virus protection
4. file management
Question 63
Which of the following statements are true..?
1. DFS linearly grows with depth.
2. BFS always has the shortest path from start state to goal state.
3. DFS uses stack
4.BFS uses queue.
Question 64
Esha writes a prgm for factorial but she forgot to write the function fact what is the error displayed
A)file not found
B)syntax errors
c)it takes the function from standard library
Question 65
Eesha wants to incorporate a history feature .When she presses “go back” then it will be able to be vist the previous page.what
data type is used ?
1. Tree
2. Queue
3. Stack
4. Array.
Time Complexities of all Sorting Algorithm
Following is a quick revision sheet that you may refer at last minute
Algorithm Time Complexity
Best Average Worst
Selection Sort Ω(n^2) θ(n^2) O(n^2)
Bubble Sort Ω(n) θ(n^2) O(n^2)
Insertion Sort Ω(n) θ(n^2) O(n^2)
Heap Sort Ω(n log(n)) θ(n log(n)) O(n log(n))
Quick Sort Ω(n log(n)) θ(n log(n)) O(n^2)
Ω(n log(n)) θ(n log(n)) O(n log(n))
Merge Sort
Bucket Sort Ω(n+k) θ(n+k) O(n^2)
Radix Sort Ω(nk) θ(nk) O(nk)