TCS C Language Questions for Interviews

Tata Consultancy Services (TCS) is an Indian multinational information technology (IT) services and consulting company headquartered in Mumbai, India. It is a subsidiary of the Tata Group and operates in 149 locations across 46 countries. TCS is one of the largest providers of IT services, digital and business solutions, and consulting services in the world.

TCS has a diversified portfolio of services that cater to a wide range of industries, including banking, financial services, insurance, healthcare, retail, manufacturing, and more. The company offers a range of services, including digital transformation, consulting, application development, maintenance, and management, infrastructure management, and engineering and industrial services. TCS also provides a suite of next-generation services, such as cloud computing, artificial intelligence, and the Internet of Things (IoT), to help its clients stay ahead in a rapidly changing technological landscape.

One of TCS’ key differentiators is its focus on innovation and delivering cutting-edge solutions to its clients. The company has a robust research and development program, which is focused on developing new technologies and solutions that can help its clients stay ahead of the curve. TCS also invests heavily in training and development for its employees, ensuring that they have the skills and knowledge necessary to provide the best possible services to its clients.
In terms of financial performance, TCS has consistently delivered strong results, with revenue and profits growing at a steady pace over the years. The company has a strong balance sheet and a well-established business model, which has helped it weather economic downturns and remain profitable even during challenging times.

TCS is a leader in the IT services and consulting industry, delivering cutting-edge solutions and services to a wide range of industries around the world. With a strong focus on innovation, employee training and development, and corporate responsibility, TCS is well-positioned for continued success in the future.

TCS Recruitment Process

The TCS Recruitment process contains four interview rounds we will have a brief discussion of all of them in this section of the blog.

Interview Rounds

We will discuss each of the four rounds here.

  1. TCS NQT: This is the first round in the section of the candidate. It contains questions on various topics and domains like, Numerical Ability, Verbal Ability, Programming Logic, Reasoning Ability, and Coding questions. Clearing this test is one of the most difficult parts of the whole interview experience.

    • Numerical Ability: This section evaluates a candidate’s numerical aptitude, including Number Systems, Arithmetic, Elementary Statistics, and Data Interpretation.
    • Verbal Ability: This component evaluates reading comprehension and English grammatical usage.
    • Reasoning Ability: This component assesses a variety of reasoning skills, including the capacity to recognize mathematical and linguistic patterns, solve problems, analyze figurative and factual material, make decisions, use propositional reasoning, and use visual-spatial reasoning.
  2. Technical Round: Make every effort to get ready for this step of the recruiting process since it is the most difficult. Your technical expertise, biography, and key projects will be the main topics of discussion during the whole interview process. The face-to-face technical phase of the TCS interview comprises of questions aimed at determining the candidate’s proficiency with object-oriented programming concepts, database management systems, operating systems, networking, and a programming language of your choosing. There is a good likelihood that you may be required to write some code on paper.

  3. Managerial Round: In this round the group of senior members of the company sit at the panel and they review your thinking style and ask questions based on your behavior and will see your reactions and the way of approach in difficult scenarios.

  4. HR Round: Along with the typical HR inquiries about your skills and shortcomings, motivations for applying to the firm, reasons why you should be recruited, etc., you may anticipate inquiries about your job history, schooling, extracurricular activities, and family history. They can also inquire about TCS, including its founding date, goals, core principles, organizational structure, and other details. The majority of applicants think the HR interview is straightforward, but bear in mind that, even if you’ve passed all other tests, a subpar HR interview might prevent you from getting the job (aptitude test, technical round, etc.). The objective is to keep a cheerful and assured demeanor. Remember to smile during interviews—they might be lengthy and boring!

TCS C Language Questions: Fundamentals

In this section, we will see some of the TCS C Language Questions which are not related to coding but related to the fundamentals of c language.

1. Name all the types of recursion present in C language.
There are mainly six types of recursions:
Yes, these are also some of the different types of recursion.

  • Linear Recursion: A linear recursion is a type of recursion where a function calls itself only once. In linear recursion, the problem size is reduced by a constant amount at each step.
  • Tail Recursion: Tail recursion is a type of recursion where the function calls itself as the very last thing it does before returning. This is considered to be more efficient than regular recursion, as the compiler can optimize it into a loop.
  • Binary Recursion: Binary recursion is a type of recursion where a function calls two instances of itself to solve a problem. In binary recursion, the problem size is reduced by half at each step.
  • Exponential Recursion: Exponential recursion is a type of recursion where the problem size is reduced by a constant factor of less than one at each step.
  • Nested Recursion: Nested recursion is a type of recursion where a function calls another function that calls the original function. In nested recursion, the problem size is reduced at each step by a constant amount.
  • Mutual Recursion: Mutual recursion is a type of recursion where two or more functions call each other in a cyclic manner to solve a problem. Mutual recursion is used to solve problems that can be split into two or more parts, each of which can be solved by a different function.

2. Explain the difference between Interpreter and Compiler.
A compiler and an interpreter are two different approaches to executing code written in the C programming language.

  • Compiler: A compiler is a program that takes in source code written in a high-level programming language and converts it into machine code that can be executed by a computer. In the case of C, the compiler generates machine code for a specific architecture and operating system, and this machine code is saved to disk as an executable file. The compiler performs all the necessary syntax and semantic checks before generating the machine code.
  • Interpreter: An interpreter, on the other hand, does not generate machine code. Instead, it reads and executes the code line by line, translating each statement into machine code on the fly. This means that an interpreter does not need to write any files to disk, and it can be used to execute code immediately, which can be useful for debugging and testing purposes. However, this also means that interpreted code typically runs slower than code that has been compiled, since the overhead of translating each statement into machine code on the fly is relatively high.

3. What do you understand by the scope of a variable?
The scope of a variable refers to the region of a program where the variable is defined and can be accessed or used. In other words, it defines the visibility and accessibility of a variable within a program.

There are two main types of scope: global scope and local scope. A variable declared outside of all functions has a global scope and is accessible from anywhere in the program. On the other hand, a variable declared inside a function has a local scope and is only accessible within that function.

It’s important to understand the scope of a variable because it affects how a variable can be used and manipulated within a program. For example, if a variable with the same name is declared in both a global scope and a local scope, the local scope will take precedence and shadow the global scope. The value of the global scope variable will not be accessible or affected within the local scope.

4. What do you understand by enumeration?
Enumeration is a programming concept that refers to a named collection of related values that represent distinct elements of a data type. In other words, an enumeration is a set of named constants that represent unique values.

Enumerations are typically defined using a specific syntax in programming languages, such as the enum keyword in C, C++, and Java, or the Enum keyword in Python. Each enumerated value is given a name and a value, and these values can be used in place of literal values in the code.

The primary advantage of using enumerations is that they can make the code more readable and maintainable. For example, instead of using magic numbers or string literals to represent specific values, an enumeration can be used to provide meaningful names for these values. This can make the code easier to understand and less prone to errors, since the intent of the code is made clearer.

5. What is the main difference between Java and C?
Java and C are both programming languages, but they have some significant differences that set them apart. Here are some of the main differences between Java and C:

  • Object-Oriented Programming: Java is an object-oriented programming language, while C is a procedural language. This means that in Java, programs are organized around objects and classes, while in C, programs are structured around functions and procedural statements.
  • Memory Management: Java has automatic memory management, also known as garbage collection, while C requires manual memory management. In Java, the programmer does not need to worry about freeing memory, as the garbage collector automatically takes care of this. In C, the programmer must explicitly allocate and deallocate memory using functions like malloc and free.
  • Platform Independence: Java is platform-independent, meaning that Java code can run on any operating system or device that has a Java Virtual Machine (JVM) installed. C, on the other hand, is not platform-independent and must be recompiled for each platform it is run on.

6. Explain some of the use cases of data structures in real-life scenarios.
There are many use cases for data structures some of them are explained below:

  • Databases: Databases use data structures such as arrays, linked lists, trees, and hash tables to store and retrieve data efficiently.
  • Web Browsers: Web browsers use data structures such as trees and hash tables to efficiently store and manage the elements of a web page, including the HTML, CSS, and JavaScript files.
  • Graphs: Graphs are a type of data structure that are used to represent relationships between objects. They are used in a variety of applications, including social networks, recommendation systems, and routing algorithms.
  • Maps and Navigation: Maps and navigation systems use data structures such as trees and graphs to efficiently store and manage geographical information, such as roads, buildings, and landmarks.
  • File Systems: File systems use data structures such as trees and hash tables to efficiently store and manage files on a disk.

7. What is the difference between arrays and structures?
Arrays and structures are both data structures that can be used to store and organize data in a program, but they have some key differences.

  • Definition: An array is a collection of elements that are of the same data type and are stored in contiguous memory locations. A structure, on the other hand, is a collection of elements that can be of different data types and are stored in separate memory locations.
  • Accessibility: In an array, elements are accessed by their index, which is an integer value that specifies the position of the element in the array. In a structure, elements are accessed by their field name, which is a unique identifier for each element in the structure.
  • Flexibility: Arrays are less flexible than structures because all elements in an array must be of the same data type. Structures, on the other hand, can contain elements of different data types, making them more flexible and better suited for representing complex data.
  • Size: The size of an array is fixed, meaning that the number of elements in the array cannot change after it has been declared. The size of a structure, on the other hand, is dynamic, meaning that new elements can be added or removed from the structure at any time.
  • Memory usage: Arrays are stored in contiguous memory locations, which makes accessing elements in an array very fast and efficient. Structures, on the other hand, are stored in separate memory locations, which can lead to fragmentation and slow down access times.

8. Among C and C++ in which language you can use the already written code and how?
You can use existing code in both C and C++, but the way that you reuse the code will depend on the language you’re using.

C: In C, you can use existing code by including header files and linking object files together. You can write header files that define the prototypes of functions that you want to reuse, and then include those header files in your source code. You can also create object files that contain compiled versions of your code, and link those object files together with your main program.

C++: In C++, you can use existing code in much the same way as you can in C, but you also have additional options. For example, you can reuse code in C++ by creating classes and objects. You can write classes that encapsulate your code, and then create objects that use that code. Additionally, you can reuse code in C++ by creating templates and using inheritance. Templates allow you to write generic code that can work with different types, and inheritance allows you to create new classes that inherit the properties and behavior of existing classes.

Both C and C++ provide powerful tools for reusing code, and the choice of which language you use will depend on the specific requirements of your project.

9. What is bubble and insertion sort?
Bubble Sort and Insertion Sort are two algorithms for sorting data in an array or list.

Bubble Sort: Bubble Sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order. The algorithm gets its name from the way smaller elements "bubble" to the top of the list. The algorithm continues this process until the list is sorted. Bubble Sort has a time complexity of O(n^2), which makes it inefficient for large lists, but it is easy to understand and implement.

Insertion Sort: Insertion Sort is a simple sorting algorithm that builds the final sorted array one item at a time. It is much less efficient than Bubble Sort, with a time complexity of O(n^2), but it has the advantage of being more efficient than Bubble Sort for smaller lists and partially sorted arrays. In Insertion Sort, the algorithm starts with an empty left-side sub-list and moves elements from the right-side sub-list to the left-side sub-list, one at a time.

10. With reference to C language explain the command line argument.
In the C programming language, command line arguments are a way for a program to accept input from the user at the command line when the program is run. Command line arguments are passed to the program as an array of strings, with each string representing a separate argument.

11. What is the difference between pass-by-value and pass-by-reference?
Here is the explanation of both.
In "pass-by-value," a copy of the argument’s value is passed to the function. The function operates on this copy, and any changes made to the argument within the function have no effect outside of it. In other words, the original argument is not affected by the changes made within the function. This is the default behavior in many programming languages, including C and Java.

In "pass-by-reference," a reference to the argument (i.e., its memory address) is passed to the function. This allows the function to directly modify the original argument. Any changes made to the argument within the function are reflected outside of it. This behavior is supported in many programming languages, including C++ and Python, using pointers or references.

12. What is a pointer with respect to C language?
A pointer is a variable in the C programming language that stores the memory address of another variable. The memory address stored by a pointer is used to access the value stored in the variable pointed to. Pointers are a powerful feature in C, as they allow you to manipulate data stored in memory directly, rather than just through the values of variables.

A pointer variable is declared using the * operator, followed by the type of the variable being pointed to.

13. Differentiate between void pointer and null pointer.
In the C programming language, there are two types of pointers that have a special meaning: the void pointer and the null pointer.

A "void pointer" is a pointer that can point to any type of object, including objects of any data type. It is declared using the keyword void as the data type, and it is often used as a generic pointer type when the type of the object being pointed to is not known or needs to be ignored.

14. In C what are conditional Statements?
In C, conditional statements are used to make decisions based on certain conditions. They allow you to execute different pieces of code depending on whether a certain condition is true or false. There are three types of conditional statements in C: the if statement, the if-else statement, and the switch statement.

15. In C explain memory allocation.
Memory allocation in C refers to the process of assigning blocks of memory dynamically at runtime to store data for a program. In C, you can allocate memory dynamically using two functions from the standard library: malloc and calloc.

The malloc function (short for "memory allocation") is used to allocate a block of memory of a specified size. It takes one argument, which is the size in bytes of the memory block to be allocated. It returns a pointer to the first byte of the newly allocated memory block, or NULL if the allocation fails.
The calloc function (short for "contiguous allocation") is similar to malloc, but it initializes the memory block to zero before returning a pointer to it. It takes two arguments: the number of elements to allocate and the size of each element.
After you have dynamically allocated memory, you are responsible for freeing it when you are done with it, using the free function. Failure to free dynamically allocated memory can result in memory leaks, which can lead to a program running out of memory.

16. What is a debugger in C language?
A debugger in C is a tool that allows you to inspect and control the execution of a C program so that you can identify and fix errors (also known as bugs) in your code. A debugger provides several key features, such as:

  • Breakpoints: You can set breakpoints in your code, which cause the debugger to stop the program at that point so that you can inspect the state of the program and variables.
  • Step execution: You can step through your code line by line so that you can observe how the program behaves and what values variables are assigned.
  • Watch variables: You can add variables to a watch list so that the debugger will display their values as the program runs.
  • Stack trace: The debugger provides a stack trace, which shows the sequence of function calls that led to the current location in the code. This can be helpful in understanding the flow of execution and locating the source of an error.
  • Modify variables: You can modify the values of variables while the program is stopped, which can be useful for testing and debugging purposes.

17. Explain Memory Alignment.
Memory alignment in C refers to the way data is stored in memory. The process of aligning data in memory is done to optimize memory access speed and reduce memory waste.

Memory alignment means ensuring that the starting address of a data structure is a multiple of a memory alignment boundary, which is a power of two. For example, on a system with a 32-bit word size and an alignment boundary of 4 bytes, an object’s address would be a multiple of 4.

In C, data structures like structures, arrays, and unions can be aligned to specific memory boundaries by using data alignment attributes such as #pragma pack or attribute((aligned(n))), where n is the desired alignment size in bytes.

By default, the compiler will try to align data structures to their natural alignment boundaries, which is the size of their largest data type. For example, if a structure contains a double type, which requires 8-byte alignment on most systems, the compiler will align the structure to an 8-byte boundary.

Proper memory alignment is important for performance, especially when working with large amounts of data, as misaligned memory access can result in slow performance or even crashes.

18. What do you understand by static identifier?
In the C programming language, the static identifier is a keyword that can be used to declare variables, functions, or objects with static storage duration.

A variable declared with static has a fixed storage location in memory and retains its value between function calls. This means that the value of a static variable is preserved across multiple invocations of the function in which it is declared, while non-static (or "automatic") variables are destroyed and re-created each time the function is called.

A static function is a function that can only be called within the same source file in which it is defined. It is not accessible from other files, making it a type of internal linkage. This can be useful for encapsulating implementation details or creating utility functions that are only needed within a specific file.

In the case of objects, the static keyword can be used to declare static class members in C++. These are members that are shared by all objects of a class, as opposed to instance members, which are unique to each object.

19. What are loops in C language?
Loops in C are constructs that allow you to repeatedly execute a block of code a certain number of times or until a specific condition is met. They are a fundamental building block for writing efficient and flexible code. There are two main types of loops in C: for loops, while loops, and do while loops.

20. Difference between struct and enum.
struct and enum are two different constructs in C that serve different purposes.

A struct (structure) is a user-defined data type that allows you to group together variables of different data types under a single name. It provides a way to store multiple pieces of data in a single object, making it easier to manage and organize data in your program.

TCS C Language: Coding Questions

In this section, we will discuss TCS C Language: Coding Questions. We will discuss some of the coding questions in C language asked in TCS Interview.

1. Write a program in the C language of swapping two numbers by using a third number.

#include <stdio.h> 
int main()
int a, b, temp; 
printf("Enter two integers\n");
scanf("%d%d", &a, &b);
printf("Before SwappingnFirst variable = %dnSecond variable = %d\n", a, b);
temp = a;
a = b;
b = temp;
printf("After SwappingnFirst variable = %dnSecond variable = %d\n", a, b);
return 0;


5 8


Enter two integers
Before SwappingnFirst variable = 5nSecond variable = 8
After SwappingnFirst variable = 8nSecond variable = 5

2. Given an array containing only 0’s and 1’s in random order arrange all the 0’s and 1’s together in a single scan of the array.

#include <stdio.h> 
int main()
int a, b, temp; 
printf("Enter two integers\n");
scanf("%d%d", &a, &b);
printf("Before SwappingnFirst variable = %dnSecond variable = %d\n", a, b);
temp = a;
a = b;
b = temp;
printf("After SwappingnFirst variable = %dnSecond variable = %d\n", a, b);
return 0;


Array after segregation is 0 0 0 0 0 1 1 1 1 1 1

3. Write a program to find whether a given year is a leap year or not.

#include <stdio.h>
#include <stdbool.h>

bool checkYear(int year)
    if (year % 400 == 0)
        return true;

    if (year % 100 == 0)
        return false;

    if (year % 4 == 0)
        return true;
    return false;

int main()
    int year = 2200;

    checkYear(year)? printf("Leap Year"):
                printf("Not a Leap Year");
    return 0;


Not a Leap Year

4. Find whether a given array is a subset of another array or not.

#include <stdbool.h>
#include <stdio.h>
void quickSort(int* arr, int si, int ei);
int binarySearch(int arr[], int low, int high, int x);

bool isSubset(int arr1[], int arr2[], int m, int n)
    int i = 0;

    quickSort(arr1, 0, m - 1);
    for (i = 0; i < n; i++) {
        if (binarySearch(arr1, 0, m - 1, arr2[i]) == -1)
            return 0;

    return 1;

int binarySearch(int arr[], int low, int high, int x)
    if (high >= low) {
        int mid = (low + high) / 2;

        if ((mid == 0 || x > arr[mid - 1])
            && (arr[mid] == x))
            return mid;
        else if (x > arr[mid])
            return binarySearch(arr, (mid + 1), high, x);
            return binarySearch(arr, low, (mid - 1), x);
    return -1;

void exchange(int* a, int* b)
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;

int partition(int A[], int si, int ei)
    int x = A[ei];
    int i = (si - 1);
    int j;

    for (j = si; j <= ei - 1; j++) {
        if (A[j] <= x) {
            exchange(&A[i], &A[j]);
    exchange(&A[i + 1], &A[ei]);
    return (i + 1);

void quickSort(int A[], int si, int ei)
    int pi;
    if (si < ei) {
        pi = partition(A, si, ei);
        quickSort(A, si, pi - 1);
        quickSort(A, pi + 1, ei);

int main()
    int arr1[] = { 12, 1, 15, 21, 3, 7 };
    int arr2[] = { 12, 3, 7, 1 };

    int m = sizeof(arr1) / sizeof(arr1[0]);
    int n = sizeof(arr2) / sizeof(arr2[0]);

    if (isSubset(arr1, arr2, m, n))
        printf("arr2[] is subset of arr1[] ");
        printf("arr2[] is not a subset of arr1[] ");

    return 0;


arr2[] is subset of arr1[]

5. Reverse a string or array.

void rvereseArray(int arr[], int start, int end)
    int temp;
    while (start < end)
        temp = arr[start];
        arr[start] = arr[end];
        arr[end] = temp;
void printArray(int arr[], int size)
int i;
for (i=0; i < size; i++)
    printf("%d ", arr[i]);

int main()
    int arr[] = {4, 2, 55, 3, 5, 6};
    int n = sizeof(arr) / sizeof(arr[0]);
    printArray(arr, n);
    rvereseArray(arr, 0, n-1);
    printf("Reversed array is \n");
    printArray(arr, n);
    return 0;


4 2 55 3 5 6 
Reversed array is 
6 5 3 55 2 4

Frequently Asked Questions

1. What is a dynamic memory allocation in C?
Dynamic memory allocation in C allows you to allocate memory at runtime, rather than during compile time. This is done using functions such as malloc() and calloc().

2. What are the preprocessor directives in C?
The preprocessor directives in C are commands that are processed by the preprocessor before the source code is compiled. Examples include #define and #include.

3. What are the control structures in C?
The control structures in C include if-else statements, loops (for, while, and do-while), and switch statements.

4. What is a function in C?
A function in C is a group of statements that perform a specific task.

Leave a Reply

Your email address will not be published. Required fields are marked *