Get free ebooK with 50 must do coding Question for Product Based Companies solved
Fill the details & get ebook over email
Thank You!
We have sent the Ebook on 50 Must Do Coding Questions for Product Based Companies Solved over your email. All the best!

TCS C Language Questions for Interviews

Last Updated on June 13, 2023 by Ankit Kochar

Tata Consultancy Services (TCS) is a global leader in IT services, consulting, and business solutions. It is part of the Tata Group, one of India’s largest and most respected conglomerates. Founded in 1968, TCS has grown to become one of the largest IT services companies in the world, with a strong presence in over 46 countries and a diverse range of clients across various industries.

TCS offers a wide range of services and solutions, including application development and maintenance, infrastructure services, consulting, digital transformation, and business process outsourcing. The company leverages its deep industry expertise, cutting-edge technology capabilities, and a global delivery model to deliver value and innovation to its clients.

With a strong focus on customer satisfaction and business excellence, TCS has consistently been recognized for its achievements. The company has received numerous accolades and awards for its performance, corporate governance, sustainability efforts, and social responsibility initiatives. TCS has also been consistently ranked as one of the top employers and most admired companies in the IT industry.

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;
}

Input

5 8

Output

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;
}

Output

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;
}

Output

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);
        else
            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) {
            i++;
            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[] ");
    else
        printf("arr2[] is not a subset of arr1[] ");

    return 0;
}

Output

arr2[] is subset of arr1[]

5. Reverse a string or array.

#include<stdio.h>
void rvereseArray(int arr[], int start, int end)
{
    int temp;
    while (start < end)
    {
        temp = arr[start];
        arr[start] = arr[end];
        arr[end] = temp;
        start++;
        end--;
    }
}	
void printArray(int arr[], int size)
{
int i;
for (i=0; i < size; i++)
    printf("%d ", arr[i]);

printf("\n");
}
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;
}

Output

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

Conclusion:

Preparing for a job interview at Tata Consultancy Services (TCS) or any organization that emphasizes C programming skills requires a thorough understanding of the language and its concepts. In this article, we explored common C language questions frequently asked during TCS interviews, covering both basic and advanced topics. By familiarizing yourself with these questions and practicing your problem-solving skills, you can increase your chances of success and impress interviewers with your C language proficiency.

Remember, the goal of these interview questions is not just to assess your knowledge of C programming but also to evaluate your problem-solving approach, logical thinking, and ability to write clean and efficient code. It is crucial to practice coding exercises, review C language fundamentals, and understand advanced concepts like memory allocation, file handling, and structures.

Frequently Asked Questions for TCS C Language Questions for Interviews

1. What are some common C language questions asked in TCS interviews?

  • Explain the difference between an array and a pointer.
  • Describe the concept of a structure in C.
  • How does memory allocation work in C?
  • What is the difference between "const" and "volatile" in C?
  • Explain the use of the "static" keyword in C.

2. How can I prepare for C language questions in TCS interviews?

  • Review C language fundamentals such as variables, data types, operators, control structures, and functions.
  • Practice solving coding problems related to arrays, strings, pointers, and structures.
  • Understand memory management concepts, including dynamic memory allocation and deallocation.
  • Familiarize yourself with common library functions and their usage in C.
  • Stay updated on the latest developments and features in C programming.

3. Are there any specific coding exercises or programs I should practice?

  • Practice programs related to sorting algorithms, such as bubble sort, insertion sort, and quicksort.
  • Solve problems involving string manipulation, such as string reversal, string concatenation, and palindrome detection.
  • Implement data structures like linked lists, stacks, and queues in C.
  • Work on programs that involve file handling, such as reading from and writing to files.
  • Practice coding exercises that test your understanding of recursion and bitwise operations.

4. How important is it to understand memory management in C for TCS interviews?

  • Understanding memory management in C is crucial for TCS interviews, as it demonstrates your knowledge of how memory is allocated and deallocated in the language.
  • Be familiar with concepts such as stack memory, heap memory, dynamic memory allocation using functions like malloc() and free(), and the potential for memory leaks or segmentation faults.

5. Should I focus on theoretical concepts or practical coding skills for C language questions in TCS interviews?

  • TCS interviews typically assess both theoretical understanding and practical coding skills.

  • It’s important to have a solid grasp of C language concepts, data structures, and algorithms, as well as the ability to apply them to solve real-world problems through coding exercises or program implementation.
    6. How can I showcase my C language skills effectively during the interview?

  • Clearly explain your thought process while solving coding problems.

  • Write clean and readable code, paying attention to naming conventions and proper indentation.

  • Test your code thoroughly to identify and fix any errors or bugs.

  • Be prepared to discuss any projects or experiences where you have applied your C programming skills.

Leave a Reply

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