Crack TCS Technical Interview Questions: A Series - Part 3

1

 

TCS Technical Interview Questions

TCS Technical Interview Questions

21) What is an array?

An array is a collection of similar elements. For an array, the necessary condition is that the data type of all the elements in the array must be same. The declaration of an array in C++ is as follows:

int a[10];

This defines an array whose name is a and has ten elements from index 0-9

22) Given an array of 1s and 0s arrange the 1s together and 0s together in a single scan of the array. Optimize the boundary conditions.

1.      #include<stdio.h>  

2.     #include<conio.h>  

3.     void main()  

4.     {  

5.     int A[10]={'0','1','0','1','0','0','0','1','0','1','0','0'};  

6.     int x=0,y=A.length-1;  

7.     while(x  

8.     x++;  

9.     else if(A[y])  

10.  y--;  

11.  if(A[x] && !A[y])//here we are checking that stating index is having 1 and last index having 0 than swap values  

12.  A[x]=0,A[y]=1;  

13.  }  

14.  getch();  

15.  }  

23) Define Data Abstraction. What are their importance?

Abstraction is process of recognizing and focusing on essential characteristics of a situation or object and leaving/filtering out the unwanted components of that situation or object.

Abstraction is the basis for software development. It's through this concept we define the essential aspects of a system. The process of identifying and designing the ideas for a given system is called Modeling ( objectmodeling).

Three levels of data abstraction are:

  1. Logical level: Information stored in the database. e.g., Database administrator
  2. Physical level: Where data is stored physically in the database.
  3. View level: End users always work on view level. If any amendment is made it may be saved by another name.

24) Write a function to swap two numbers without using a temporary variable.

1.     void swap(int &i, int &j)  

2.     {  

3.     i=i+j;  

4.     j=i-j;  

5.     i=i-j;  

6.     }  

 

25) Memory Allocation in C/C++

The calloc() function allocates a memory area; the length will be the product of its parameters (it has two settings). calloc fills the memory with ZERO's and returns a pointer to the first byte. If that fails to locate enough space, it returns a NULL pointer.

A malloc() function allocates a memory area; length will be the value entered as parameter. (it has one parameter). It does not initialize memory area

The free() function is used to free the allocated memory(allocated through the calloc and malloc), in other words, this used release the allocated memory

new also used to allocate memory on the heap and initialize the memory using constructor

delete also used release memory allocated by new operator

26) Write output of the program?

1.     int i=10;  

2.     printf("%d%d%d",i,++i,i++);  

Answer= 10 12 12

27) what is virtual function and pure virtual function?

Virtual function:- To achieve polymorphism, function in base class is declared as virtual. By state virtual, we make a base class pointer to execute the purpose of any derived class depends on the content of pointer (any acquired class address).

Pure Virtual Function:- This is the function used in base class, and its definition has to be provided in derived class, In other pure virtual function has no definition in the base is declared as :

1.     virtual void fun()=0;  

It means that this function is not going to do anything, In case of pure virtual function derived function has to

implement a pure virtual function or redeclare it as a pure virtual function

28) What are WPF and WCF?

WPF/WCF application, need in .NET 3.0 Framework. These application will cover the following concepts:

WCF(Windows Communication Foundation)

  • The new service orientated attributes
  • The use of interfaces
  • The use of callbacks
  • Asynchronous delegates
  • Creating the proxy

WPF( Windows Presentation Foundation )

  • Styles
  • Templates
  • Animations
  • Databinding

29) Write a program in C to swap two numbers without help of a third variable.

1.       /* 

2.          * C++ program to swap two numbers without using a temporary variable 

3.         */  

4.         #include<iostream>  

5.         using namespace std;  

6.         

7.        /* Function for swapping the values */  

8.         void swap(int &a, int &b)  

9.       {  

10.          b = a + b;  

11.         a = b - a;  

12.          b = b - a;  

13.      }  

14.      int main()  

15.      {  

16.      int a, b;  

17.        

18.  cout << "Enter two numbers to be swapped : ";  

19.  cin >> a >> b;  

20.  swap(a, b);  

21.  cout << "The two numbers after swapping become :" << endl;  

22.  cout << "Value of a : " << a << endl;  

23.  cout << "Value of b : " << b << endl;  

24.  }  

30) What will be output of the following code?

1.      // file name: Main.java  

2.        

3.     class Complex {  

4.         private double  re, im;           

5.        

6.         public Complex(double re, double it) {  

7.             this.re = re;  

8.             this.im = im;  

9.         }  

10.  }  

11.      

12.  // Driver class to test the Complex level  

13.  public class Main {  

14.      public static void main(String[] args) {  

15.          Complex c1 = new Complex(1015);  

16.          System.out.println(c1);  

17.      }  

18.  }  

Post a Comment

1Comments
Post a Comment