> TCS NQT Programming Questions | TCS Coding Questions 2021 | TCS Coding Questions 2020

TCS NQT Programming Questions | TCS Coding Questions 2021 | TCS Coding Questions 2020

 


TCS NQT Programming Questions | TCS Coding Questions 2021 | TCS Coding Questions 2020

In this article TCS NQT Programming Questions you will get all the sample and frequently asked questions, which will help you in attending TCS NQT exam.

1. A pointer variable can be


A. Changed within function.
B. Assigned an integer value.
C. None of these
D. Passed to a function as argument.

2. Which of the following uses structure?


A. Linked Lists
B. Array of structures
C. All of these
D. Binary Tree

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


A. \t
B. \1
C. \0
D. \n

4. Which of the following is a collection of different data types?


A. String
B. Structure
C. Array
D. Files

5. What function should be used to free the memory allocated by calloc() ?


A. free();
B. malloc(variable_name, 0)
C. dealloc();
D. memalloc(variable_name, 0)

6. In the standard library of C programming language, which of the following header file is designed for basic mathematical operations?


A. conio.h
B. stdio.h
C. math.h
D. Dos.h

7. int **ptr; is?


A. Pointer to integer
B. None of these
C. Pointer to pointer
D. Invalid declaration

8. Which of the following special symbol allowed in a variable name?


A. (underscore)
B. – (hyphen)
C. | (pipeline)
D. * (asterisk)

9. All keywords in C are in


A. Uppercase letters
B. None of these
C. Lowercase letters
D. Camel Case letters

10. Which of the following statements about stdout and stderr are true?


A. They both are the same
B. Run time errors are automatically displayed in stderr
C. Both are connected to the screen by default.
D. stdout is line buffered but stderr is unbuffered.

11. Given the below statements about C programming language:


1. main() function should always be the first function present in a C program file
2) all the elements of an union share their memory location
3) A void pointer can hold address of any type and can be typcasted to any type
4) A static variable hold random junk value if it is not initialised

Which of the above are correct statements?

A) 2,3
B) 1,2
C) 1,2,3
D) 1,2,3,4

Explanations
In a file you can write a function before main() – False
all the elements of an union share their memory location – True.
A void pointer can hold address of any type and can be typcasted to any type – True
Static value – False as value is 0

In C, if an object that has static storage duration is not initialized explicitly, then:
— if it has pointer type, it is initialized to a NULL pointer;
— if it has arithmetic type, it is initialized to (positive or unsigned) zero;
— if it is an aggregate, every member is initialized (recursively) according to these rules; — if it is a union, the first named member is initialized (recursively) according to these rules.

12. If a function is defined as static, it means


A) The value returned by the function does not change
B) all the variable declared inside the function automatically will be assigned initial value of zero
C) It should be called only within the same source code / program file.
D) None of the other choices as it is wrong to add static prefix to a function

Access to static functions is restricted to the file where they are declared. Therefore, when we want to restrict access to functions, we make them static

13. Comment on the below while statement=
while (0 == 0) { }

A) It has syntax error as there are no statements within braces {}
B) It will run forever
C) It compares 0 with 0 and since they are equal it will exit the loop immediately
D) It has syntax error as the same number is being compared with itself

while( 0==0) {} is equivalent to while(1) {}

14. What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array?


A. The element will be set to 0.
B. The compiler would report an error.
C. The program may crash if some important data gets overwritten.
D. The array size would appropriately grow.

Explanation:
If the index of the array size is exceeded, the program will crash. Hence “option c” is the correct answer. But the modern compilers will take care of this kind of errors.

15. What does the following declaration mean?
int (*ptr)[10];


A. ptr is array of pointers to 10 integers
B. ptr is a pointer to an array of 10 integers
C. ptr is an array of 10 integers
D .ptr is an pointer to array

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


A. Value of elements in array
B. First element of the array
C. Base address of the array
D. Address of the last element of array

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

17. Is there any difference int the following declarations?
int fun(int arr[]);
int fun(int arr[2]);


A. Yes
B. No

Explanation:
No, both the statements are same. It is the prototype for the function fun() that accepts one integer array as an parameter and returns an integer value.

18. Are the expressions arr and &arr same for an array of 10 integers?

A. Yes
B. No

Explanation:
Both mean two different things. arr gives the address of the first int, whereas the &arr gives the address of array of ints.

19. 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

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.

20. Is there any difference between 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

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.

21. What could be the output for following?
main()
{
int a= – – 2;
printf(“%d”,a);
}


A. 2
B.-2
C. 1
D. Error

–2 is incorrect, // Invalid because lvalue is required to increment

22. Predict the output of following code:

main()
{
int i=-1;
-i; //No change in value of i
printf(“%d,%d”,i,-i);
}


A. -1, 1
B. -1, -1
C. 1, 1
D. 0, 1

23. 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);
}
}


A. Error
B. 20,30
C. 20,20
D. Garbage value

24. 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,30,20
C. 20,20,20
D. Garbage value

25. Predict the output of following code:

main()
{
int i=10;
printf(“%d,%d”,++i,++i);
}


A. 11,12
B. 12,11
C. 10,11
D. 11,10

Post a Comment

0 Comments