Go Back   2021-2022 StudyChaCha > StudyChaCha Discussion Forum > General Topics

Old May 17th, 2014, 03:51 PM
Sashwat's Avatar
Super Moderator
Join Date: Jun 2011
Default Re: TCS Mechanical Engineering Technical Question Papers

Tata Consultancy Services is a big software development Company. The questions in Technical round are generally of the kind:

About your project
Resume related topics
They may ask to write a simple program.

Sample Questions:

What is a pointer?

What are the uses of a pointer?

What is a structure?

What is a union?

What are the differences between structures and union?

What are the differences between structures and arrays?

1. What does static variable mean?
Ans: Static variables are the variables which retain their values between the function calls. They are initialized only once their scope is within the function in which they are defined.

2. What is a pointer?
Ans: Pointers are variables which stores the address of another variable. That variable may be a scalar (including another pointer), or an aggregate (array or structure). The pointed-to object may be part of a larger object, such as a field of a structure or an element in an array.

3. What are the uses of a pointer?
Ans: Pointer is used in the following cases i) It is used to access array elements ii) It is used for dynamic memory allocation. iii) It is used in Call by reference iv) It is used in data structures like trees, graph, linked list etc.

4. What is a structure?
Ans: Structure constitutes a super data type which represents several different data types in a single unit. A structure can be initialized if it is static or global.

5. What is a union?
Ans: Union is a collection of heterogeneous data type but it uses efficient memory utilization technique by allocating enough memory to hold the largest member. Here a single area of memory contains values of different types at different time. A union can never be initialized.
6. What are the differences between structures and union?
Ans: A structure variable contains each of the named members, and its size is large enough to hold all the members. Structure elements are of same size. A union contains one of the named members at a given time and is large enough to hold the largest member. Union element can be of different sizes.

7. What are the differences between structures and arrays?
Ans: Structure is a collection of heterogeneous data type but array is a collection of homogeneous data types. Array 1-It is a collection of data items of same data type. 2-It has declaration only 3-.There is no keyword. 4- array name represent the address of the starting element.
Structure 1-It is a collection of data items of different data type. 2- It has declaration and definition 3- keyword struct is used 4-Structure name is known as tag it is the short hand notation of the declaration.

8. In header files whether functions are declared or defined?
Ans: Functions are declared within header file. That is function prototypes exist in a header file,not function bodies. They are defined in library (lib).

9. What are the differences between malloc () and calloc ()?
Ans: Malloc Calloc 1-Malloc takes one argument Malloc(a);where a number of bytes 2-memory allocated contains garbage values 1-Calloc takes two arguments Calloc(b,c) where b no of object and c size of object 2-It initializes the contains of block of memory to zerosMalloc takes one argument, memory allocated contains garbage values. It allocates contiguous memory locations. Calloc takes two arguments, memory allocated contains all zeros, and the memory allocated is not contiguous.

10. What are macros? What are its advantages and disadvantages?
Ans: Macros are abbreviations for lengthy and frequently used statements. When a macro is called the entire code is substituted by a single line though the macro definition is of several lines. The advantage of macro is that it reduces the time taken for control transfer as in case of function. The disadvantage of it is here the entire code is substituted so the program becomes lengthy if a macro is called several times.

11. Difference between pass by reference and pass by value?
Ans: Pass by reference passes a pointer to the value. This allows the callee to modify the variable directly.Pass by value gives a copy of the value to the callee. This allows the callee to modify the value without modifying the variable. (In other words, the callee simply cannot modify the variable, since it lacks a reference to it.)

12. What is static identifier?
Ans: A file-scope variable that is declared static is visible only to functions within that file. A function-scope or block-scope variable that is declared as static is visible only within that scope. Furthermore, static variables only have a single instance. In the case of function- or block-scope variables, this means that the variable is not ―automatic‖ and thus retains its value across function invocations.

13. Where is the auto variables stored?
Ans: Auto variables can be stored anywhere, so long as recursion works. Practically, they‘re stored on the stack. It is not necessary that always a stack exist. You could theoretically allocate function invocation records from the heap.

14. Where does global, static, and local, register variables, free memory and C Program instructions get stored?
Ans: Global: Wherever the linker puts them. Typically the ―BSS segment‖ on many platforms. Static: Again, wherever the linker puts them. Often, they‘re intermixed with the globals. The only difference between globals and statics is whether the linker will resolve the symbols across
compilation units.Local: Typically on the stack, unless the variable gets register allocated and never spills.Register: Nowadays, these are equivalent to ―Local‖ variables. They live on the stack unless they get register-allocated.

15. Difference between arrays and linked list?
Ans: An array is a repeated pattern of variables in contiguous storage. A linked list is a set of structures scattered through memory, held together by pointers in each element that point to the next element. With an array, we can (on most architectures) move from one element to the next by adding a fixed constant to the integer value of the pointer. With a linked list, there is a ―next‖ pointer in each structure which says what element comes next.

16. What are enumerations?
Ans: They are a list of named integer-valued constants. Example:enum color { black , orange=4, yellow, green, blue, violet };This declaration defines the symbols ―black‖, ―orange‖, ―yellow‖, etc. to have the values ―1,‖ ―4,‖ ―5,‖ … etc. The difference between an enumeration and a macro is that the enum actually declares a type, and therefore can be type checked.

17. Describe about storage allocation and scope of global, extern, static, local and register variables?
Ans: Globals have application-scope. They‘re available in any compilation unit that includes an appropriate declaration (usually brought from a header file). They‘re stored wherever the linker puts them, usually a place called the ―BSS segment.‖ Extern? This is essentially ―global.‖ Static: Stored the same place as globals, typically, but only available to the compilation unit that contains them. If they are block-scope global, only available within that block and its subblocks. Local: Stored on the stack, typically. Only available in that block and its subblocks. (Although pointers to locals can be passed to functions invoked from within a scope where that local is valid.) Register: See tirade above on ―local‖ vs. ―register.‖ The only difference is that the C compiler will not let you take the address of something you‘ve declared as ―register.‖

18. What are register variables? What are the advantages of using register variables?
Ans: If a variable is declared with a register storage class,it is known as register variable.The register variable is stored in the cpu register instead of main memory.Frequently used variables are declared as register variable as it‘s access time is faster.

19. What is the use of typedef?
Ans: The typedef help in easier modification when the programs are ported to another machine. A descriptive new name given to the existing data type may be easier to understand the code.

20. Can we specify variable field width in a scanf() format string? If possible how? Ans: All field widths are variable with scanf(). You can specify a maximum field width for a given field by placing an integer value between the ‗%‘ and the field type specifier. (e.g. %64s). Such a specifier will still accept a narrower field width.
The one exception is %#c (where # is an integer). This reads EXACTLY # characters, and it is the only way to specify a fixed field width with scanf().

21. Out of fgets() and gets() which function is safe to use and why?
Ans: fgets() is safer than gets(), because we can specify a maximum input length. Neither one is completely safe, because the compiler can‘t prove that programmer won‘t overflow the buffer he pass to fgets ().

22. Difference between strdup and strcpy?
Ans: Both copy a string. strcpy wants a buffer to copy into. strdup allocates a buffer using malloc(). Unlike strcpy(), strdup() is not specified by ANSI

23. What is recursion?
Ans: A recursion function is one which calls itself either directly or indirectly it must halt at a definite point to avoid infinite recursion.

24. Differentiate between for loop and a while loop? What are it uses?
Ans: For executing a set of statements fixed number of times we use for loop while when the number of iterations to be performed is not known in advance we use while loop.

25. What is storage class? What are the different storage classes in C?
Ans: Storage class is an attribute that changes the behavior of a variable. It controls the lifetime, scope and linkage. The storage classes in c are auto, register, and extern, static, typedef.

26. What the advantages of using Unions?
Ans: When the C compiler is allocating memory for unions it will always reserve enough room for the largest member.

27. What is the difference between Strings and Arrays?
Ans: String is a sequence of characters ending with NULL .it can be treated as a one dimensional array of characters terminated by a NULL character.

28. What is a far pointer? Where we use it?
Ans: In large data model (compact, large, huge) the address B0008000 is acceptable because in these model all pointers to data are 32bits long. If we use small data model(tiny, small, medium) the above address won‘t work since in these model each pointer is 16bits long. If we are working in a small data model and want to access the address B0008000 then we use far pointer. Far pointer is always treated as a 32bit pointer and contains a segment address and offset address both of 16bits each. Thus the address is represented using segment : offset format B000h:8000h. For any given memory address there are many possible far address segment : offset pair. The segment
register contains the address where the segment begins and offset register contains the offset of data/code from where segment begins.

29. What is a huge pointer?
Ans: Huge pointer is 32bit long containing segment address and offset address. Huge pointers are normalized pointers so for any given memory address there is only one possible huge address segment: offset pair. Huge pointer arithmetic is doe with calls to special subroutines so its arithmetic slower than any other pointers.

30. What is a normalized pointer, how do we normalize a pointer?
Ans: It is a 32bit pointer, which has as much of its value in the segment register as possible. Since a segment can start every 16bytes so the offset will have a value from 0 to F. for normalization convert the address into 20bit address then use the 16bit for segment address and 4bit for the offset address. Given a pointer 500D: 9407,we convert it to a 20bitabsolute address 549D7,Which then normalized to 549D:0007.

31. What is near pointer?
Ans: A near pointer is 16 bits long. It uses the current content of the CS (code segment) register (if the pointer is pointing to code) or current contents of DS (data segment) register (if the pointer is pointing to data) for the segment part, the offset part is stored in a 16 bit near pointer. Using near pointer limits the data/code to 64kb segment. 32. In C, why is the void pointer useful? When would you use it?
Ans: The void pointer is useful because it is a generic pointer that any pointer can be cast into and back again without loss of information.

33. What is a NULL Pointer? Whether it is same as an uninitialized pointer?
Ans: Null pointer is a pointer which points to nothing but uninitialized pointer may point to anywhere.

34. Are pointers integer?
Ans: No, pointers are not integers. A pointer is an address. It is a positive number. 35. What does the error ‘Null Pointer Assignment’ means and what causes this error?
Ans: As null pointer points to nothing so accessing a uninitialized pointer or invalid location may cause an error.

36. What is generic pointer in C?
Ans: In C void* acts as a generic pointer. When other pointer types are assigned to generic pointer, conversions are applied automatically (implicit conversion).

37. Are the expressions arr and &arr same for an array of integers?
Ans: Yes for array of integers they are same.

38. IMP>How pointer variables are initialized?
Ans: Pointer variables are initialized by one of the following ways. I. Static memory allocation II. Dynamic memory allocation

39. What is static memory allocation?
Ans: Compiler allocates memory space for a declared variable. By using the address of operator, the reserved address is obtained and this address is assigned to a pointer variable. This way of assigning pointer value to a pointer variable at compilation time is known as static memory allocation.

40. What is dynamic memory allocation?
Ans: A dynamic memory allocation uses functions such as malloc() or calloc() to get memory dynamically. If these functions are used to get memory dynamically and the values returned by these function are assigned to pointer variables, such a way of allocating memory at run time is known as dynamic memory allocation.

41. What is the purpose of realloc?
Ans: It increases or decreases the size of dynamically allocated array. The function realloc (ptr,n) uses two arguments. The first argument ptr is a pointer to a block of memory for which the size is to be altered. The second argument specifies the new size. The size may be increased or decreased. If sufficient space is not available to the old region the function may create a new region.

42. What is pointer to a pointer?
Ans: If a pointer variable points another pointer value. Such a situation is known as a pointer to a pointer. Example: int *p1,**p2,v=10; P1=&v; p2=&p1; Here p2 is a pointer to a pointer.

43. What is an array of pointers?
Ans: if the elements of an array are addresses, such an array is called an array of pointers.

44. Difference between linker and linkage?
Ans: Linker converts an object code into an executable code by linking together the necessary built in functions. The form and place of declaration where the variable is declared in a program determine the linkage of variable.
45. Is it possible to have negative index in an array?
Ans: Yes it is possible to index with negative value provided there are data stored in this location. Even if it is illegal to refer to the elements that are out of array bounds, the compiler will not produce error because C has no check on the bounds of an array

. 46. Why is it necessary to give the size of an array in an array declaration?
Ans: When an array is declared, the compiler allocates a base address and reserves enough space in memory for all the elements of the array. The size is required to allocate the required space and hence size must be mentioned.

47. What modular programming?
Ans: If a program is large, it is subdivided into a number of smaller programs that are called modules or subprograms. If a complex problem is solved using more modules, this approach is known as modular programming.

48. What is a function?
Ans: A large program is subdivided into a number of smaller programs or subprograms. Each subprogram specifies one or more actions to be performed for the larger program. Such sub programs are called functions.

49. What is an argument? Ans: An argument is an entity used to pass data from the calling to a called function. 50. What are built in functions?
Ans: The functions that are predefined and supplied along with the compiler are known as built-in functions. They are also known as library functions. 1. Difference between formal argument and actual argument? Ans: Formal arguments are the arguments available in the function definition. They are preceded by their own data type. Actual arguments are available in the function call. These arguments are given as constants or variables or expressions to pass the values to the function. 52. Is it possible to have more than one main() function in a C program ? Ans: The function main() can appear only once. The program execution starts from main. 53. What is the difference between an enumeration and a set of pre-processor # defines? Ans: There is hardly any difference between the two, except that #defines has a global effect (throughout the file) whereas an enumeration can have an effect local to the block if desired. Some advantages of enumeration are that the numeric values are automatically assigned whereas in #define we have to explicitly define them. A disadvantage is that we have no control over the size of enumeration variables.
54. How are Structure passing and returning implemented by the complier?
Ans: When structures are passed as argument to functions, the entire structure is typically pushed on the stack. To avoid this overhead many programmer often prefer to pass pointers to structure instead of actual structures. Structures are often returned from functions in a location pointed to by an extra, compiler-supported ‗hidden‘ argument to the function.

55. IMP>what is the similarity between a Structure, Union and enumeration?
Ans: All of them let the programmer to define new data type.

56. Can a Structure contain a Pointer to itself?
Ans: Yes such structures are called self-referential structures.

57. How can we read/write Structures from/to data files?
Ans: To write out a structure we can use fwrite() as Fwrite( &e, sizeof(e),1,fp);Where e is a structure variable. A corresponding fread() invocation can read the structure back from file. calling fwrite() it writes out sizeof(e) bytes from the address &e. Data files written as memory images with fwrite(),however ,will not be portable, particularly if they contain floating point fields or Pointers. This is because memory layout of structures is machine and compiler dependent. Therefore, structures written as memory images cannot necessarily be read back by programs running on other machine, and this is the important concern if the data files you‘re writing will ever be interchanged between machines.

58. Write a program which employs Recursion?
Ans: int fact(int n) { return n > 1 ? n * fact(n – 1) : 1; } 59.Write a program which uses Command Line Arguments? Ans: #include void main(int argc,char *argv[]) { int i; clrscr(); for(i=0;i printf(―\n%d‖,argv[i]); }

60. Difference between array and pointer?
Ans: Array 1- Array allocates space automatically 2- It cannot be resized 3- It cannot be reassigned 4- sizeof (arrayname) gives the number of bytes occupied by the array.
Pointer 1-Explicitly assigned to point to an allocated space. 2-It can be sized using realloc() 3-pointer can be reassigned. 4-sizeof (p) returns the number of bytes used to store the pointer variable p.

61. What do the ‘c’ and ‘v’ in argc and argv stand for?
Ans: The c in argc(argument count) stands for the number of command line argument the program is invoked with and v in argv(argument vector) is a pointer to an array of character string that contain the arguments.

62. IMP>what are C tokens?
Ans: There are six classes of tokens: identifier, keywords, constants, string literals, operators and other separators.

63. What are C identifiers?
Ans: These are names given to various programming element such as variables, function, arrays.It is a combination of letter, digit and underscore.It should begin with letter. Backspace is not allowed.

64. Difference between syntax vs logical error?
Ans: Syntax Error 1-These involves validation of syntax of language. 2-compiler prints diagnostic message. Logical Error 1-logical error are caused by an incorrect algorithm or by a statement mistyped in such a way that it doesn‘t violet syntax of language. 2-difficult to find.

65. What is preincrement and post increment?
Ans: ++n (pre increment) increments n before its value is used in an assignment operation or any expression containing it. n++ (post increment) does increment after the value of n is used.

66. Write a program to interchange 2 variables without using the third one.
Ans: a ^= b; ie a=a^b b ^= a; ie b=b^a; a ^= b ie a=a^b; here the numbers are converted into binary and then xor operation is performed. You know, you‘re just asking ―have you seen this overly clever trick that‘s not worth applying on modern architectures and only really applies to integer variables?‖

67. What is the maximum combined length of command line arguments including the space between adjacent arguments?
Ans: It depends on the operating system.

68. What are bit fields? What is the use of bit fields in a Structure declaration?
Ans: A bit field is a set of adjacent bits within a single implementation based storage unit that we will call a ―word‖. The syntax of field definition and access is based on structure. Struct { unsigned int k :1; unsigned int l :1; unsigned int m :1; }flags; the number following the colon represents the field width in bits.Flag is a variable that contains three bit fields.

69. What is a preprocessor, what are the advantages of preprocessor?
Ans: A preprocessor processes the source code program before it passes through the compiler. 1- a preprocessor involves the readability of program 2- It facilitates easier modification 3- It helps in writing portable programs 4- It enables easier debugging 5- It enables testing a part of program 6- It helps in developing generalized program

70. What are the facilities provided by preprocessor?
Ans: 1-file inclusion 2-substitution facility 3-conditional compilation

71. What are the two forms of #include directive?
Ans: 1.#include‖filename‖ 2.#include the first form is used to search the directory that contains the source file.If the search fails in the home directory it searches the implementation defined locations.In the second form ,the preprocessor searches the file only in the implementation defined locations.

72. How would you use the functions randomize() and random()?
Ans: Randomize() initiates random number generation with a random value. Random() generates random number between 0 and n-1;

73. What do the functions atoi(), itoa() and gcvt() do?
atoi() is a macro that converts integer to character. itoa() It converts an integer to string gcvt() It converts a floating point number to string

74. How would you use the functions fseek(), freed(), fwrite() and ftell()?
Ans: fseek(f,1,i) Move the pointer for file f a distance 1 byte from location i. fread(s,i1,i2,f) Enter i2 dataitems,each of size i1 bytes,from file f to string s. fwrite(s,i1,i2,f) send i2 data items,each of size i1 bytes from string s to file f. ftell(f) Return the current pointer position within file f. The data type returned for functions fread,fseek and fwrite is int and ftell is long int.

75. What is the difference between the functions memmove() and memcpy()?
Ans: The arguments of memmove() can overlap in memory. The arguments of memcpy() cannot.

76. What is a file?
Ans: A file is a region of storage in hard disks or in auxiliary storage devices.It contains bytes of information .It is not a data type.

77. IMP>what are the types of file?
Ans: Files are of two types 1-high level files (stream oriented files) :These files are accessed using library functions 2-low level files(system oriented files) :These files are accessed using system calls

78. IMP>what is a stream?
Ans: A stream is a source of data or destination of data that may be associated with a disk or other I/O device. The source stream provides data to a program and it is known as input stream. The destination stream eceives the output from the program and is known as output stream.

79. What is meant by file opening?
Ans: The action of connecting a program to a file is called opening of a file. This requires creating an I/O stream before reading or writing the data.

80. What is FILE?
Ans: FILE is a predefined data type. It is defined in stdio.h file.

81. What is a file pointer?
Ans: The pointer to a FILE data type is called as a stream pointer or a file pointer. A file pointer points to the block of information of the stream that had just been opened.

82. How is fopen()used ?
Ans: The function fopen() returns a file pointer. Hence a file pointer is declared and it is
assigned as FILE *fp; fp= fopen(filename,mode); filename is a string representing the name of the file and the mode represents: ―r‖ for read operation ―w‖ for write operation ―a‖ for append operation ―r+‖,‖w+‖,‖a+‖ for update operation

83How is a file closed ?
Ans: A file is closed using fclose() function Eg. fclose(fp); Where fp is a file pointer.

84. What is a random access file?
Ans: A file can be accessed at random using fseek() function fseek(fp,position,origin); fp file pointer position number of bytes offset from origin origin 0,1 or 2 denote the beginning ,current position or end of file respectively.

85. What is the purpose of ftell ?
Ans: The function ftell() is used to get the current file represented by the file pointer. ftell(fp); returns a long integer value representing the current file position of the file pointed by the file pointer fp.If an error occurs ,-1 is returned.

86. What is the purpose of rewind() ?
Ans: The function rewind is used to bring the file pointer to the beginning of the file. Rewind(fp); Where fp is a file pointer.Also we can get the same effect by feek(fp,0,0);

87. Difference between a array name and a pointer variable?
Ans: A pointer variable is a variable where as an array name is a fixed address and is not a variable. A pointer variable must be initialized but an array name cannot be initialized. An array name being a constant value , ++ and — operators cannot be applied to it.

88. Represent a two-dimensional array using pointer?
Ans: Address of a[I][j] Value of a[I][j] &a[I][j] or
a[I] + j or *(a+I) + j *&a[I][j] or a[I][j] or *(a[I] + j ) or *( * ( a+I) +j )

89. Difference between an array of pointers and a pointer to an array?
Ans: Array of pointers 1- Declaration is: data_type *array_name[size]; 2-Size represents the row size. 3- The space for columns may be dynamically
Pointers to an array 1-Declaration is data_type ( *array_name)[size]; 2-Size represents the column size.

90. Can we use any name in place of argv and argc as command line arguments ? Ans: yes we can use any user defined name in place of argc and argv;

91. What are the pointer declarations used in C?
Ans: 1- Array of pointers, e.g , int *a[10]; Array of pointers to integer 2-Pointers to an array,e.g , int (*a)[10]; Pointer to an array of into 3-Function returning a pointer,e.g, float *f( ) ; Function returning a pointer to float 4-Pointer to a pointer ,e.g, int **x; Pointer to apointer to int 5-pointer to a data type ,e.g, char *p; pointer to char

92. Differentiate between a constant pointer and pointer to a constant?
Ans: const char *p; //pointer to a const character. char const *p; //pointer to a const character. char * const p; //const pointer to a char variable. const char * const p; // const pointer to a const character.

93. Is the allocated space within a function automatically deallocated when the function returns?
Ans: No pointer is different from what it points to .Local variables including local pointers variables in a function are deallocated automatically when function returns.,But in case of a local pointer variable ,deallocation means that the pointer is deallocated and not the block of memory allocated to it. Memory dynamically allocated always persists until the allocation is freed or the program terminates.

94. Discuss on pointer arithmetic?
Ans: 1- Assignment of pointers to the same type of pointers. 2- Adding or subtracting a pointer and an integer. 3-subtracting or comparing two pointer. 4-incrementing or decrementing the pointers pointing to the elements of an array. When a pointer to an integer is incremented by one , the address is incremented by two. It is done automatically by the compiler. 5-Assigning the value 0 to the pointer variable and comparing 0 with the pointer. The pointer having address 0 points to nowhere at all.

95. What is the invalid pointer arithmetic?
Ans: i) adding ,multiplying and dividing two pointers. ii) Shifting or masking pointer. iii) Addition of float or double to pointer. iv) Assignment of a pointer of one type to a pointer of another type ?

96. What are the advantages of using array of pointers to string instead of an array of strings?
Ans: i) Efficient use of memory. ii) Easier to exchange the strings by moving their pointers while sorting.

97. Are the expressions *ptr ++ and ++ *ptr same?
Ans: No,*ptr ++ increments pointer and not the value pointed by it. Whereas ++ *ptr increments the value being pointed to by ptr.

98. What would be the equivalent pointer expression foe referring the same element as a[p][q][r][s] ? Ans : *( * ( * ( * (a+p) + q ) + r ) + s)

99. Are the variables argc and argv are always local to main?
Ans: Yes they are local to main.

100. Can main () be called recursively?
Ans: Yes any function including main () can be called recursively.

101. IMP>Can we initialize unions?
Ans: ANSI Standard C allows an initializer for the first member of a union. There is no standard way of initializing any other member (nor, under a pre-ANSI compiler, is there generally any way of initializing a union at all).

102. What’s the difference between these two declarations?
Ans: struct x1 { … };
typedef struct { … } x2; The first form declares a structure tag; the second declares a typedef. The main difference is that the second declaration is of a slightly more abstract type.its users don‘t necessarily know that it is a structure, and the keyword struct is not used when declaring instances of it.

103. Why doesn’t this code: a[i] = i++; work?
Ans: The subexpression i++ causes a side effect.it modifies i‘s value.which leads to undefined behavior since i is also referenced elsewhere in the same expression.

104.WHy doesn’t struct x { … }; x thestruct; work?
Ans: C is not C++. Typedef names are not automatically generated for structure tags.

105. Why can’t we compare structures?
Ans: There is no single, good way for a compiler to implement structure comparison which is consistent with C‘s low-level flavor. A simple byte-by-byte comparison could founder on random bits present in unused ―holes‖ in the structure (such padding is used to keep the alignment of later fields correct). A field-by-field comparison might require unacceptable amounts of repetitive code for large structures.

106. How are structure passing and returning implemented?
Ans: When structures are passed as arguments to functions, the entire structure is typically pushed on the stack, using as many words as are required. Some compilers merely pass a pointer to the structure, though they may have to make a local copy to preserve pass-by-value semantics. Structures are often returned from functions in a location pointed to by an extra,compiler-supplied ―hidden‖ argument to the function. Some older compilers used a special,static location for structure returns, although this made structure-valued functions non-reentrant, which ANSI C disallows.
Answered By StudyChaCha Member
Reply With Quote
Old February 20th, 2015, 10:03 AM
Super Moderator
Join Date: Dec 2011
Default Re: TCS Mechanical Engineering Technical Question Papers

As per your request, I am giving you some Mechanical Engineering questions which are asked in TCS placements.

Can any one explain about blue prints&performance tuning in cognos?
Is there any procedure for amendment of power? If Pl. X-Plane?
Theory of Machines
Fluid Mechanics etc.
Usage of Stored Procedures in Cognos
Which modulation is good for Radio Broadcasting. AM(Amplitude Modulation) or FM(Frequency Modulation)?
What is the unit of hardness

Here, I am giving you TCS Placement paper questions.

1) If log 0.317=0.3332 and log 0.318=0.3364 then find log 0.319 ?
Sol) log 0.317=0.3332 and log 0.318=0.3364, then
log 0.319=log0.318+(log0.318-log0.317) = 0.3396

2) A box of 150 packets consists of 1kg packets and 2kg packets. Total weight of box is 264kg. How many 2kg packets are there ?
Sol) x= 2 kg Packs
y= 1 kg packs
x + y = 150 .......... Eqn 1
2x + y = 264 .......... Eqn 2
Solve the Simultaneous equation; x = 114
so, y = 36
ANS : Number of 2 kg Packs = 114.

3) My flight takes of at 2am from a place at 18N 10E and landed 10 Hrs later at a place with coordinates 36N70W. What is the local time when my plane landed?
6:00 am b) 6:40am c) 7:40 d) 7:00 e) 8:00
Sol) The destination place is 80 degree west to the starting place. Hence the time difference between these two places is 5 hour 20 min. (=24hr*80/360).
When the flight landed, the time at the starting place is 12 noon (2 AM + 10 hours).
Hence, the time at the destination place is 12 noon - 5:20 hours = 6: 40 AM

4) A plane moves from 9°N40°E to 9°N40°W. If the plane starts at 10 am and takes 8 hours to reach the destination, find the local arrival time ?
Sol) Since it is moving from east to west longitide we need to add both
multiply the ans by 4
convert this min to hours ie, 5hrs 33min
It takes 8hrs totally . So 8-5hr 30 min=2hr 30min
So the ans is 10am+2hr 30 min
=>ans is 12:30 it will reach

5) The size of the bucket is N kb. The bucket fills at the rate of 0.1 kb per millisecond. A programmer sends a program to receiver. There it waits for 10 milliseconds. And response will be back to programmer in 20 milliseconds. How much time the program takes to get a response back to the programmer, after it is sent? Please tell me the answer with explanation. Very urgent.
Sol) see it doesn't matter that wat the time is being taken to fill the bucket.after reaching program it waits there for 10ms and back to the programmer in 20 ms.then total time to get the response is 20ms +10 ms=30ms...it's so simple....

6) A file is transferred from one location to another in 'buckets'. The size of the bucket is 10 kilobytes. Each bucket gets filled at the rate of 0.0001 kilobytes per millisecond. The transmission time from sender to receiver is 10 milliseconds per bucket. After the receipt of the bucket the receiver sends an acknowledgement that reaches sender in 100 milliseconds. Assuming no error during transmission, write a formula to calculate the time taken in seconds to successfully complete the transfer of a file of size N kilobytes.
(n/1000)*(n/10)*10+(n/100)....as i hv calculated...~~!not 100% sure

7) A fisherman's day is rated as good if he catches 9 fishes, fair if 7 fishes and bad if 5 fishes. He catches 53 fishes in a week n had all good, fair n bad days in the week. So how many good, fair n bad days did the fisher man had in the week
Ans:4 good, 1 fair n 2 bad days
Sol) Go to river catch fish
take what is given 53
good days means --- 9 fishes so 53/9=4(remainder=17) if u assume 5 then there is no chance for bad days.
fair days means ----- 7 fishes so remaining 17 --- 17/7=1(remainder=10) if u assume 2 then there is no chance for bad days.
bad days means -------5 fishes so remaining 10---10/5=2days.
Ans: 4 good, 1 fair, 2bad. ==== total 7 days.

x+y+z=7--------- eq1
9*x+7*y+5*z=53 -------eq2
multiply eq 1 by 9,
9*x+9*y+9*z=35 -------------eq3
from eq2 and eq3
since all x,y and z are integer i sud put a integer value of y such that z sud be integer in eq 4 .....and ther will be two value y=1 or 3 then z = 2 or 1 from eq 4

for first y=1,z=2 then from eq1 x= 4
so 9*4+1*7+2*5=53.... satisfied
now for second y=3 z=1 then from eq1 x=3
so 9*3+3*7+1*5=53 ......satisfied
so finally there are two solution of this question
(x,y,z)=(4,1,2) and (3,3,1)...

8) Y catches 5 times more fishes than X. If total number of fishes caught by X and Y is 42, then number of fishes caught by X?
Sol) Let no. of fish x catches=p
no. caught by y =r
then p=7,r=35

9) Three companies are working independently and receiving the savings 20%, 30%, 40%. If the companies work combinely, what will be their net savings?
suppose total income is 100
so amount x is getting is 80
y is 70
z =60

but total money is 300
so they are getting 90 rs less
90 is 30% of 300 so they r getting 30% discount

10) The ratio of incomes of C and D is 3:4.the ratio of their expenditures is 4:5. Find the ratio of their savings if the savings of C is one fourths of his income?
Sol) incomes:3:4

11) If G(0) = -1 G(1)= 1 and G(N)=G(N-1) - G(N-2) then what is the value of G(6)?
ans: -1
bcoz g(2)=g(1)-g(0)=1+1=2

12) If A can copy 50 pages in 10 hours and A and B together can copy 70 pages in 10 hours, how much time does B takes to copy 26 pages?
Sol) A can copy 50 pages in 10 hrs.
A can copy 5 pages in 1hr.(50/10)
now A & B can copy 70 pages in 10hrs.
thus, B can copy 90 pages in 10 hrs.[eqn. is (50+x)/2=70, where x--> no. of pages B can copy in 10 hrs.]
so, B can copy 9 pages in 1hr.
therefore, to copy 26 pages B will need almost 3hrs.
since in 3hrs B can copy 27 pages.

13) what's the answer for that :
A, B and C are 8 bit no's. They are as follows:
A -> 1 1 0 0 0 1 0 1
B -> 0 0 1 1 0 0 1 1
C -> 0 0 1 1 1 0 1 0 ( - =minus, u=union)
Find ((A - C) u B) =?

To find A-C, We will find 2's compliment of C and them add it with A,
That will give us (A-C)
2's compliment of C=1's compliment of C+1
Now (A-C) U B is .OR. logic operation on (A-C) and B
10001001 .OR . 00110011
The answer is = 10111011,
Whose decimal equivalent is 187.

14) One circular array is given(means memory allocation tales place in circular fashion) diamension(9X7) and sarting add. is 3000, What is the address of (2,3)........
Sol) it's a 9x7 int array so it reqiure a 126 bytes for storing.b'ze integer value need 2 byes of memory allocation. and starting add is 3000
so starting add of 2x3 will be 3012.

15) In a two-dimensional array, X (9, 7), with each element occupying 4 bytes of memory, with the address of the first element X (1, 1) is 3000, find the address of X (8, 5).
Sol) initial x (1,1) = 3000 u hav to find from x(8,1)so u have x(1,1),x(1,2) ... x(7,7) = so u have totally 7 * 7 = 49 elementsu need to find for x(8,5) ? here we have 5 elements each element have 4 bytes : (49 + 5 -1) * 4 = 212 -----( -1 is to deduct the 1 element ) 3000 + 212 = 3212

16) Which of the following is power of 3 a) 2345 b) 9875 c) 6504 d) 9833

17) The size of a program is N. And the memory occupied by the program is given by M = square root of 100N. If the size of the program is increased by 1% then how much memory now occupied ?
Sol) M=sqrt(100N)
N is increased by 1%
therefore new value of N=N + (N/100)
M=sqrt(100 * (101N/100) )
Hence, we get M=sqrt(101 * N)

2.OXYGEN----------- WATER ------- B. A Type of
4. BUG -------------REPTILE------ D. A SUPERSET OF
1)B 2)A 3)D 4)C

19) A bus started from bustand at 8.00a m and after 30 min staying at destination, it returned back to the bustand. the destination is 27 miles from the bustand. the speed of the bus 50 percent fast speed. at what time it returns to the bustand
this is the step by step solution:
a bus cover 27 mile with 18 mph in =27/18= 1 hour 30 min. and it wait at stand =30 min.
after this speed of return increase by 50% so 50%of 18 mph=9mph
Total speed of returnig=18+9=27
Then in return it take 27/27=1 hour
then total time in joureny=1+1:30+00:30 =3 hour
so it will come at 8+3 hour=11 a.m.
So Ans==11 a.m

20) In two dimensional array X(7,9) each element occupies 2 bytes of memory.If the address of first element X(1,1)is 1258 then what will be the address of the element X(5,8) ?
Sol) Here, the address of first element x[1][1] is 1258 and also 2 byte of memory is given. now, we have to solve the address of element x[5][8], therefore, 1258+ 5*8*2 = 1258+80 = 1338 so the answer is 1338.

21) The temperature at Mumbai is given by the function: -t2/6+4t+12 where t is the elapsed time since midnight. What is the percentage rise (or fall) in temperature between 5.00PM and 8.00PM?

22) Low temperature at the night in a city is 1/3 more than 1/2 high as higher temperature in a day. Sum of the low temperature and highest temp. is 100 degrees. Then what is the low temp?
Sol) Let highest temp be x
so low temp=1/3 of x of 1/2 of x plus x/2 i.e. x/6+x/2
total temp=x+x/6+x/2=100
therefore, x=60
Lowest temp is 40

23) In Madras, temperature at noon varies according to -t^2/2 + 8t + 3, where t is elapsed time. Find how much temperature more or less in 4pm to 9pm. Ans. At 9pm 7.5 more
Sol) In equestion first put t=9,
we will get 34.5...........................(1)
now put t=4,
we will get 27..............................(2)
so ans=34.5-27

24) A person had to multiply two numbers. Instead of multiplying by 35, he multiplied by 53 and the product went up by 540. What was the raised product?
a) 780 b) 1040 c) 1590 d) 1720
Sol) x*53-x*35=540=> x=30 therefore, 53*30=1590 Ans

25) How many positive integer solutions does the equation 2x+3y = 100 have?
a) 50 b) 33 c) 16 d) 35
Sol) There is a simple way to answer this kind of Q's given 2x+3y=100, take l.c.m of 'x' coeff and 'y' coeff i.e. l.c.m of 2,3 ==6then divide 100 with 6 , which turns out 16 hence answer is 16short cut formula--- constant / (l.cm of x coeff and y coeff)

26) The total expense of a boarding house are partly fixed and partly variable with the number of boarders. The charge is Rs.70 per head when there are 25 boarders and Rs.60 when there are 50 boarders. Find the charge per head when there are 100 boarders.
a) 65 b) 55 c) 50 d) 45
Let a = fixed cost and k = variable cost and n = number of boarders
total cost when 25 boarders c = 25*70 = 1750 i.e. 1750 = a + 25k
total cost when 50 boarders c = 50*60 = 3000 i.e. 3000 = a + 50k
solving above 2 eqns, 3000-1750 = 25k i.e. 1250 = 25k i.e. k = 50
therefore, substituting this value of k in either of above 2 eqns we get
a = 500 (a = 3000-50*50 = 500 or a = 1750 - 25*50 = 500)
so total cost when 100 boarders = c = a + 100k = 500 + 100*50 = 5500
so cost per head = 5500/100 = 55

27) Amal bought 5 pens, 7 pencils and 4 erasers. Rajan bought 6 pens, 8 erasers and 14 pencils for an amount which was half more than what Amal had paid. What % of the total amount paid by Amal was paid for pens?
a) 37.5% b) 62.5% c) 50% d) None of these
Let, 5 pens + 7 pencils + 4 erasers = x rupees
so 10 pens + 14 pencils + 8 erasers = 2*x rupees
also mentioned, 6 pens + 14 pencils + 8 erarsers = 1.5*x rupees
so (10-6) = 4 pens = (2-1.5)x rupees
so 4 pens = 0.5x rupees => 8 pens = x rupees
so 5 pens = 5x/8 rupees = 5/8 of total (note x rupees is total amt paid byamal)
i.e 5/8 = 500/8% = 62.5% is the answer

28) I lost Rs.68 in two races. My second race loss is Rs.6 more than the first race. My friend lost Rs.4 more than me in the second race. What is the amount lost by my friend in the second race?
x + x+6 = rs 68
2x + 6 = 68
2x = 68-6
2x = 62
x is the amt lost in I race
x+ 6 = 31+6=37 is lost in second race
then my friend lost 37 + 4 = 41 Rs

29) Ten boxes are there. Each ball weighs 100 gms. One ball is weighing 90 gms. i) If there are 3 balls (n=3) in each box, how many times will it take to find 90 gms ball? ii) Same question with n=10 iii) Same question with n=9
to me the chances are
when n=3
(i) nC1= 3C1 =3 for 10 boxes .. 10*3=30
(ii) 10C1=10 for 10 boxes ....10*10=100
(iii)9C1=9 for 10 boxes .....10*9=90

30) (1-1/6) (1-1/7).... (1- (1/ (n+4))) (1-(1/ (n+5))) = ?
leaving the first numerater and last denominater, all the numerater and denominater will cancelled out one another. Ans. 5/(n+5)

31) A face of the clock is divided into three parts. First part hours total is equal to the sum of the second and third part. What is the total of hours in the bigger part?
Sol) the clock normally has 12 hr
three parts x,y,z
so the largest part is 6 hrs

32) With 4/5 full tank vehicle travels 12 miles, with 1/3 full tank how much distance travels
Sol) 4/5 full tank= 12 mile
1 full tank= 12/(4/5)
1/3 full tank= 12/(4/5)*(1/3)= 5 miles

33) wind blows 160 miles in 330min.for 80 miles how much time required
Sol) 160 miles= 330 min
1 mile = 330/160
80 miles=(330*80)/160=165 min.

34) A person was fined for exceeding the speed limit by 10mph.another person was also fined for exceeding the same speed limit by twice the same if the second person was travelling at a speed of 35 mph. find the speed limit
solving the eqn we get x=15

35) A sales person multiplied a number and get the answer is 3 instead of that number divided by 3. what is the answer he actually has to get.
Sol) Assume 1
1* 3 = 3
so he has to got 1/3
this is the exact answer

36) A person who decided to go weekend trip should not exceed 8 hours driving in a day average speed of forward journey is 40 mph due to traffic in Sundays the return journey average speed is 30 mph. How far he can select a picnic spot.

37) Low temperature at the night in a city is 1/3 more than 1/2 hinge as higher temperature in a day. Sum of the low temp and high temp is 100 c. then what is the low temp.
ans is 40 c.
Sol) let x be the highest temp. then,
therefore, x=60 which is the highest temp
and 100-x=40 which is the lowest temp.

38) car is filled with four and half gallons of oil for full round trip. Fuel is taken 1/4 gallons more in going than coming. What is the fuel consumed in coming up.
Sol) let feul consumed in coming up is x. thus equation is: x+1.25x=4.5ans:2gallons

39) A work is done by the people in 24 min. One of them can do this work alone in 40 min. How much time required to do the same work for the second person
Sol) Two people work together in 24 mins.
So, their one day work is
One man can complete the work in 40mins
one man's one day work (1/B)= (1/40)
So, A can complete the work in 60 mins.

40) In a company 30% are supervisors and 40% employees are male if 60% of supervisors are male. What is the probability? That a randomly chosen employee is a male or female?
Sol) 40% employees are male if 60% of supervisors are male so for 100% is 26.4%so the probability is 0.264

41) In 80 coins one coin is counterfeit what is minimum number of weighing to find out counterfeit coin
Sol) the minimum number of wieghtings needed is just 5.as shown below
(1) 80->30-30
(2) 15-15
(3) 7-7
(4) 3-3
(5) 1-1

42) 2 oranges, 3 bananas and 4 apples cost Rs.15. 3 oranges, 2 bananas, and 1 apple costs Rs 10. What is the cost of 3 oranges, 3 bananas and 3 apples?
3x+2y+z=10 adding
x+y+z=5 that is for 1 orange, 1 bannana and 1 apple requires 5Rs.
so for 3 orange, 3 bannana and 3 apple requires 15Rs.
i.e. 3x+3y+3z=15

43) In 8*8 chess board what is the total number of squares refers
Sol) odele discovered that there are 204 squares on the board We found that you would add the different squares - 1 + 4 + 9 + 16+ 25 + 36 + 49 + 64.
Also in 3*3 tic tac toe board what is the total no of squares
Ans 14 ie 9+4(bigger ones)+1 (biggest one)
If you ger 100*100 board just use the formula
the formula for the sum of the first n perfect squares is
n x (n + 1) x (2n + 1)
if in this formula if you put n=8 you get your answer 204

44) One fast typist type some matter in 2hr and another slow typist type the same matter in 3hr. If both do combinely in how much time they will finish.
Sol) Faster one can do 1/2 of work in one hourslower one can do 1/3 of work in one hourboth they do (1/2+1/3=5/6) th work in one hour.so work will b finished in 6/5=1.2 hour i e 1 hour 12 min.

45) If Rs20/- is available to pay for typing a research report & typist A produces 42 pages and typist B produces 28 pages. How much should typist A receive?
Here is the answer Find of 42 % of 20 rs with respect to 70 (i.e 28 + 42) ==> (42 * 20 )/70 ==> 12 Rs

46) An officer kept files on his table at various times in the order 1,2,3,4,5,6. Typist can take file from top whenever she has time and type it.What order she cann t type.?

47) In some game 139 members have participated every time one fellow will get bye what is the number of matches to choose the champion to be held?
the answer is 138 matches
Sol) since one player gets a bye in each round,he will reach the finals of the tournament without playing a match.
therefore 137 matches should be played to detemine the second finalist from the remaining 138 players(excluding the 1st player)
therefore to determine the winner 138 matches shd be played.

48) One rectangular plate with length 8inches, breadth 11 inches and 2 inches thickness is there. What is the length of the circular rod with diameter 8 inches and equal to volume of rectangular plate?
Sol) Vol. of rect. plate= 8*11*2=176
area of rod=(22/7)*(8/2)*(8/2)=(352/7)
vol. of rod=area*length=vol. of plate
so length of rod= vol of plate/area=176/(352/7)=3.5

49) One tank will fill in 6 minutes at the rate of 3cu ft /min, length of tank is 4 ft and the width is 1/2 of length, what is the depth of the tank?
3 ft 7.5 inches

50) A man has to get air-mail. He starts to go to airport on his motorbike. Plane comes early and the mail is sent by a horse-cart. The man meets the cart in the middle after half an hour. He takes the mail and returns back, by doing so, he saves twenty minutes. How early did the plane arrive?
ans:10min:::assume he started at 1:00,so at 1:30 he met cart. He returned home at 2:00.so it took him 1 hour for the total jorney.by doing this he saved 20 min.so the actual time if the plane is not late is 1 hour and 20 min.so the actual time of plane is at 1:40.The cart travelled a time of 10 min before it met him.so the plane is 10 min early.

51) Ram singh goes to his office in the city every day from his suburban house. His driver Mangaram drops him at the railway station in the morning and picks him up in the evening. Every evening Ram singh reaches the station at 5 o'clock. Mangaram also reaches at the same time. One day Ram singh started early from his office and came to the station at 4 o'clock. Not wanting to wait for the car he starts walking home. Mangaram starts at normal time, picks him up on the way and takes him back house, half an hour early. How much time did Ram singh walked?

52) 2 trees are there. One grows at 3/5 of the other. In 4 years total growth of the trees is 8 ft. what growth will smaller tree have in 2 years.
ans: 1.5 mt 4 (x+(3/5)x)=88x/5=2x=5/4 after 2 years x=(3/5)*(5/4)*2 =1.5

53) There is a six digit code. Its first two digits, multiplied by 3 gives all ones. And the next two digits multiplied by 6 give all twos. Remaining two digits multiplied by 9 gives all threes. Then what is the code?
sol) Assume the digit xx xx xx (six digits)
First Two digit xx * 3=111
( first two digits of 1 is not divisible by 3 so we can use 111)
Second Two digit xx*6=222
( first two digits of 2 is not divisible by 6 so we can use 222)
Thrid Two digit xx*9=333
( first two digits of 3 is not divisible by 9 so we can use 333)

54) There are 4 balls and 4 boxes of colours yellow, pink, red and green. Red ball is in a box whose colour is same as that of the ball in a yellow box. Red box has green ball. In which box you find the yellow ball?
ans is green...
Sol) Yellow box can have either of pink/yellow balls.
if we put a yellow ball in "yellow" box then it wud imply that "yellow" is also the colour of the box which has the red ball(becoz acordin 2 d question,d box of the red ball n the ball in the yellow box have same colour)
thus this possibility is ruled out...
therefore the ball in yellow box must be pink,hence the colour of box containin red ball is also pink....
=>the box colour left out is "green",,,which is alloted to the only box left,,,the one which has yellow ball..

55) A bag contains 20 yellow balls, 10 green balls, 5 white balls, 8 black balls, and 1 red ball. How many minimum balls one should pick out so that to make sure the he gets at least 2 balls of same color.
Ans:he should pick 6 ball totally.
Sol) Suppose he picks 5 balls of all different colours then when he picks up the sixth one, it must match any on of the previously drawn ball colour.
thus he must pick 6 balls

56) What is the number of zeros at the end of the product of the numbers from 1 to 100
Sol) For every 5 in unit palce one zero is added
so between 1 to 100 there are 10 nos like 5,15,25,..,95 which has 5 in unit place.
Similarly for every no divisible by 10 one zero is added in the answer so between 1 to 100 11 zeros are added
for 25,50,75 3 extra zeros are added
so total no of zeros are 10+11+3=24

57) 10 Digit number has its first digit equals to the numbers of 1's, second digit equals to the numbers of 2's, 3rd digit equals to the numbers of 3's .4th equals number of 4's..till 9th digit equals to the numbers of 9's and 10th digit equals to the number of 0's. what is the number?.(6marks)
2---shows that two 1's in the ans
1---shows that one 2 in ans
0---shows no 3 in the ans
0---shows no 4 in the ans
0---shows no 5 in the ans
1---shows one 6 in the ans
0---shows no 7 in the ans
0---shows no 8 in the ans
0---shows no 9 in the ans
6---shows six 0's in the ans

58) There are two numbers in the ratio 8:9. if the smaller of the two numbers is increased by 12 and the larger number is reduced by 19 thee the ratio of the two numbers is 5:9. Find the larger number?
sol) 8x:9x initialy
8x+ 12 : 9x - 19 = 5x:9x
8x+12 = 5x
-> x = 4
9x = 36 not sure about the answer ..

59) There are three different boxes A, B and C. Difference between weights of A and B is 3 kgs. And between B and C is 5 kgs. Then what is the maximum sum of the differences of all possible combinations when two boxes are taken each time
A-B = 3
B-c = 5
a-c = 8
so sum of diff = 8+3+5 = 16 kgs

60) A and B are shooters and having their exam. A and B fall short of 10 and 2 shots respectively to the qualifying mark. If each of them fired atleast one shot and even by adding their total score together, they fall short of the qualifying mark, what is the qualifying mark?
ans is 11
coz each had atleast 1 shot done so 10 + 1 = 11
n 9 + 2 = 11
so d ans is 11
Answered By StudyChaCha Member
Reply With Quote

Reply to this Question / Ask Another Question
Your Username: Click here to log in


All times are GMT +6.5. The time now is 08:34 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0 PL2

1 2 3 4 5 6 7 8