# 500+ Latest TCS NQT Programming Questions and Answers 2021 – 2022

Find the Latest TCS NQT Programming Questions and Answers. There are a total of 10 questions asked and the time is 15 mins given for you to solve. In TCS NQT Programming Logic the difficulty level is very much high as compared to other sections of the TCS NQT test. Kindly check all the questions for better preparation.

Here, you will find all the similar types of previous year questions based on the TCS NQT Syllabus and all the basic details for the Programming questions asked in the TCS NQT exam.

 TCS NQT Programming Test For Number of Questions 10 Questions Time Limit 15 Mins Difficulty High
IMPORTANT NOTE:
1. There will be no negative marking.
2. TCS NQT is adaptive this year.
3. You will not get any extra rough paper in the exam as a calculator and Rough Paper will be available on your Desktop Screen. You are not allowed to move your eyes down while giving the examination.

TCS NQT Programming Logic section has a cut-off of 6 to 7 questions. Moreover, this section has NO negative marking.

## TCS NQT Programming Syllabus

The following topics are asked –

• Data Types in TCS MCQ c questions
• Functions and Scope
• Recursion and Iteration
• Questions on File Handling
• Questions on Array
• Questions on Variables and Registers
• TCS Questions on Loops
• TCS Questions on Command Line Arguments

#### Most Asked TCS Questions in C MCQ Sections

• TCS Questions Misc
TCS Computer Science Papers – C Language Part 2
• TCS Questions on OOPS
• Input-Output Questions
• Stacks and Queue
• Trees
• Graphs
• Dynamic Programming and Greedy
• Hashing
• Searching and Sorting
• Time Complexity

## TCS NQT Programming Questions and Answers

1. Is there any difference between the following declarations?
1 : extern int fun();
2 : int fun();

a.    Both are identical
b.    No difference, except extern int fun(); is probably in another file
c.    int fun(); is overrided with extern int fun();
d.    None of these

b.    No difference, except extern int fun(); is probably in another file
Explanation
extern int fun(); declaration in C is to indicate the existence of a global function and it is defined externally to the current module or in another file.
int fun(); declaration in C is to indicate the existence of a function inside the current module or in the same file.

2. Which of the fplowing statements should be used to obtain a remainder after dividing 3.14 by 2.1?

a.    rem = 3.14 % 2.1;
b.    rem = modf(3.14, 2.1);
c.    rem = fmod(3.14, 2.1);
d.    Remainder cannot be obtain in floating point division

c.    rem = fmod(3.14, 2.1);
Explanation
fmod(x,y) – Calculates x modulo y, the remainder of x/y. This function is the same as the modulus operator. But fmod() performs floating point divisions.

3. In C, if you pass an array as an argument to a function, what actually gets passed?

a.    Value of elements in array
b.    Base address of the array
c.    Address of the last element of array
d.    First element of the array

b.    Base address of the array
Explanation
The statement ‘b’ is correct. When we pass an array as a function argument, the base address of the array will be passed.

4. Select the missing statement?
#include<stdio.h>
long int fact(int n);
int main()
{
\\missing statement
}
long int fact(int n)
{
if(n>=1)
return n*fact(n-1);
else
return 1;
}

a.    printf(“%ld\n”,fact(5));
b.    printf(“%d\n”,fact(5));
c.    printf(“%u\n”,fact(5));
d.    printf(“%ll\n”,fact(5));

a.    printf(“%ld\n”,fact(5));

5. Which of the below function is NOT declared in math.h ?

a.    acos()
b.    exp()
c.    pow()
d.    and()

d.    and()

6. While declaring parameters for main, the second parameter argv should be declared as

a.    char * argv[] b.    char argv
c.    char ** argv[] d.    char argv[]

a.    char * argv[]

7. Predict the output of the following code:

main()
{
int var=20; // scope of the local variable is within function or block printf(“%d,”,var); //outer block
{
int var=30; //Inner block
printf(“%d”,var);
}
}

a.    Error
b.    20,20
c.    20,30
d.    Garbage value

c.    20,30

8. Predict the output of following code:

main()
{
int var=20; // scope of the local variable is within function or block printf(“%d,”,var); //outer block
{
int var=30; //Inner block
printf(“%d,”,var);
}
printf(“%d”,var); //again in outer block
}

a.    Error
b.    20,20,20
c.    20,30,20
d.    Garbage value

c.    20,30,20

9. If a function’s return type is not explicitly defined then it’s default to ______ (In C).

a.    void
b.    float
c.    Error
d.    int

d.    int

10. How many times loop will executed?
#include<stdio.h>
int main()
{
int x,y;
for(x=5;x>=1;x–)
{
for(y=1;y<=x;y++)
printf(“%d\n”,y);
}
}

a.    11
b.    14
c.    15
d.    10

c.    15

## TCS NQT Programming logic questions

11. Which of the following indicate the end of file ?

a.    feof()
b.    EOF
c.    Both feof() and EOF
d.    None of the mentioned

c.    Both feof() and EOF

12. How many times hello will print ?
#include<stdio.h>
int main(void)
{
int i;
for(i=0;i<5;i++);
printf(“hello”);
}

a.    5
b.    Runtime error
c.    Compilation error
d.    1

d.    1

13. Which of the following uses structure?

b.    Binary Tree
c.    Array of structures
d.    All of these

d.    All of these

14. Strings are character arrays. The last index of it contains the null-terminated character

a.    \t
b.    \n
c.    \1
d.    \0

d.    \0

15. How many times loop will executed ?
#include<stdio.h>
int main()
{
int i;
for(i=0;i<5;i++)
{
printf(“Hello\n”);
}
}

a.    2
b.    3
c.    1
d.    5

d.    5

16. What is the similarity between enum and struct ?

a.    nothing in common
b.    can assign new values
c.    can create new data types
d.    they are same

c.    can create new data types

17. The pre-order traversal sequence of a binary search tree is 40, 30, 20, 25, 35, 33, 49, 45, 52. What is a possible post-order traversal sequence of the same tree?

a.    25, 20, 33, 35, 30, 45, 52, 49, 40
b.    45, 52, 49, 40, 25, 20, 33, 35, 30
c.    33, 35, 30, 45, 52, 49, 40, 25, 20
d.    30, 45, 52, 49, 40, 25, 20, 33, 35

a.    25, 20, 33, 35, 30, 45, 52, 49, 40

18. Consider the following recursive function that takes two arguments.

unsigned int rec(unisgned int k, unsigned int m) {

if (k>0) return (k>m + rec{k/m, m}};

else return 0;

}

What is the value returned by rec9789, 10)?

a.    19
b.    40
c.    24
d.    36

c.    24

19. What is the Output of this program?

#include<stdio.h>

int main()

{

int N=10;

int sortedInputs[]={2,4, 7, 13, 17, 18, 21, 24, 26, 31};

printf(“%d”, foo(sortedInputs, N});

return 0,

}

int foo(int sortedInputs[], int N)

{

int low=0, high=N-1, lowSum=0, highSum=0;

while(high-low>0)

{

if(lowSum<highSum)

lowSum+= sortedInputs[low++];

else

highSum+=sortedInputs[high–];

}

return low;

}

a.    6
b.    9
c.    5
d.    11

a.    6

20. Guess the output:
main()
{
printf(“%d”,​sizeof(‘a’));
//same as → sizeof(97)
}

a.    1 or 3
b.    2 or 4 —
c.    Garbage value
d.    ASCII value of a

b.    2 or 4 —
Explanation
sizeof takes ascii value of character and determines number of bytes required by it. Ascii is number, Number is of type int. so integer requires either 2 in 16 or 4 in 32 bit machine

## Programming logic questions for TCS NQT

21. Which of the following does not require to include math.h header file?

a.    rand()
b.    sqrt()
c.    pow()
d.    sinh()

a.    rand()

22. What is a step-by-step procedure used to solve a problem called?

a.    application program
b.    algorithm
c.    operating system
d.    all of these

b.    algorithm

23. A memory leak happens when?

a.    when realloc()  is called  on a pointer that is not allocated
b.    a program allocated memory in Stack
c.    a program allocated memory in heap but forget to delete it
d.    when an using pointer is freed using free function

c.    a program allocated memory in heap but forget to delete it
Explanation
memory leak happens when program allocated memory in heap but forget to delete it

24. What is the purpose of ftell?

a.    To get the current file name
b.    To get the current file position
c.    To get the current file attributes
d.    To get the current file status

b.    To get the current file position
Explanation
Ftell() is used to find out the current position of file pointer in the file with respect to starting of the file

## TCS NQT Programming MCQ questions

25. Where the local variable are stored?

a.    OS
b.    Stack
c.    Disk
d.    None of these

b.    Stack
Explanation
The local variable are stored in Stack

26. What is recursion?

a.    A function calls repeatedly
b.    A function calls another function repeatedly
c.    Looping
d.    A function calls itself repeatedly

d.    A function calls itself repeatedly
Explanation
In recursion, function calls itself repeatedly

27. Which of this is used to skip one iteration:

a.    continue
b.    break
c.    goto
d.    return

a.    continue

28. What is the output of the following pseudo code ?
Int a = 456, b, c, d = 10;
b = a / d;
c = a – b;
print c

a.    410.4
b.    411
c.    411.4
d.    None of these

b.    411

29. Which of the below function is NOT declared in string.h?

a.    strcpy()
b.    strlen()
c.    strptr()
d.    strupr()

c.    strptr()
Explanation
strptr() is NOT declared

30. What is the output of the below  mentioned program?

#include<stdio.h>

#define square(P) P x P

void main()

{

Int i;

i = 64/ square(4);

Printf(“%d”, i);

Return 0;

}

a.    16
b.    54
c.    4
d.    Compiler error

c.    4

For More Questions Get TCS NQT Premium Preparation Material

Expect 60%-70% similar question in TCS NQT Exam

This Product Includes all the questions asked in TCS NQT

• Coding Question
• Numerical Ability
• Programming logic
• Verbal Ability
• Reasoning ability
• Sample Papers
• Quantitative Aptitude

Complimentary Bonus

• 600+ Technical Programming and Coding Questions
• TCS HR interview handwritten notes