0% found this document useful (0 votes)
2 views

TCS_Ninja_Interview_Preparation

The document provides a comprehensive guide for TCS Ninja interview preparation, focusing on technical questions related to Python and C. It includes key features, data types, memory management, and coding examples for both languages. Additionally, it covers concepts such as shallow and deep copies in Python, as well as pointers and memory allocation in C.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

TCS_Ninja_Interview_Preparation

The document provides a comprehensive guide for TCS Ninja interview preparation, focusing on technical questions related to Python and C. It includes key features, data types, memory management, and coding examples for both languages. Additionally, it covers concepts such as shallow and deep copies in Python, as well as pointers and memory allocation in C.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

TCS Ninja Interview Preparation: Python and C Technical Questions

1. Python Questions

Basic Python Concepts:

1. What are Python's key features?

- High-level, interpreted, dynamically typed, and object-oriented.

- Extensive libraries (NumPy, Pandas, etc.).

- Supports multiple programming paradigms (procedural, functional, OOP).

2. What are Python's data types?

- Basic: int, float, complex, str, bool

- Collections: list, tuple, set, dict

3. How is memory managed in Python?

- Python uses automatic garbage collection via reference counting and cyclic garbage collection.

Python Coding:

4. Write a Python program to check if a number is prime.

```python

def is_prime(n):

if n <= 1:

return False
for i in range(2, int(n**0.5) + 1):

if n % i == 0:

return False

return True

num = 29

print(f"{num} is prime: {is_prime(num)}")

```

5. How do you reverse a list in Python?

```python

my_list = [1, 2, 3, 4, 5]

reversed_list = my_list[::-1]

print(reversed_list) # Output: [5, 4, 3, 2, 1]

```

6. What is the difference between a shallow copy and a deep copy?

- Shallow Copy: Copies the object but references nested objects.

```python

import copy

list1 = [[1, 2], [3, 4]]

shallow_copy = copy.copy(list1)

shallow_copy[0][0] = 99

print(list1) # [[99, 2], [3, 4]]

```

- Deep Copy: Copies the object and all nested objects.

```python
deep_copy = copy.deepcopy(list1)

deep_copy[0][0] = 42

print(list1) # [[99, 2], [3, 4]]

```

2. C Questions

C Basics:

1. What are the key features of C?

- Low-level memory access (pointers).

- Simple and efficient.

- Procedural programming paradigm.

2. What are the differences between malloc() and calloc()?

- malloc(size): Allocates a block of memory, uninitialized.

- calloc(n, size): Allocates memory for n elements, initializes to zero.

3. What is a pointer in C?

- A pointer is a variable that stores the memory address of another variable.

```c

int a = 10;

int *ptr = &a;

printf("Value of a: %d", *ptr); // Outputs 10

```
C Coding:

4. Write a program to reverse a string in C.

```c

#include <stdio.h>

#include <string.h>

void reverseString(char str[]) {

int n = strlen(str);

for (int i = 0; i < n / 2; i++) {

char temp = str[i];

str[i] = str[n - i - 1];

str[n - i - 1] = temp;

int main() {

char str[] = "Hello";

reverseString(str);

printf("Reversed: %s", str);

return 0;

```

5. Write a program to find the factorial of a number using recursion.

```c
#include <stdio.h>

int factorial(int n) {

if (n <= 1) return 1;

return n * factorial(n - 1);

int main() {

int num = 5;

printf("Factorial of %d: %d", num, factorial(num));

return 0;

```

You might also like