A. Changed within function. B. Assigned an integer value. C. None of these D. Passed to a function as argument. ","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603878919872","position":2,"url":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603878919872","name":"2. Which of the following uses structure?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":" A. Linked Lists B. Array of structures C. All of these D. Binary Tree ","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603879000453","position":3,"url":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603879000453","name":"3. Strings are character arrays. The last index of it contains the null-terminated character","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":" A. \\t B. \\1 C. \\0 D. \\n ","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603879039077","position":4,"url":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603879039077","name":"4. Which of the following is a collection of different data types?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":" A. String B. Structure C. Array D. Files ","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603879096606","position":5,"url":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603879096606","name":"5. What function should be used to free the memory allocated by calloc() ?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":" A. free(); B. malloc(variable_name, 0) C. dealloc(); D. memalloc(variable_name, 0) ","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603879492832","position":6,"url":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603879492832","name":"6. In the standard library of C programming language, which of the following header file is designed for basic mathematical operations?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":" A. conio.h B. stdio.h C. math.h D. Dos.h ","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603879534987","position":7,"url":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603879534987","name":"7. int **ptr; is?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":" A. Pointer to integer B. None of these C. Pointer to pointer D. Invalid declaration ","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603879584272","position":8,"url":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603879584272","name":"8. Which of the following special symbol allowed in a variable name?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":" A. (underscore) B. - (hyphen) C. | (pipeline) D. * (asterisk) ","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603879650338","position":9,"url":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603879650338","name":"9. All keywords in C are in","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":" A. Uppercase letters B. None of these C. Lowercase letters D. Camel Case letters ","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603879698076","position":10,"url":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603879698076","name":"10. Which of the following statements about stdout and stderr are true?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":" 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. ","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603879987831","position":11,"url":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603879987831","name":"11. Given the below statements about C programming language:","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":" 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. ","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603880136282","position":12,"url":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603880136282","name":"12. If a function is defined as static, it means","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":" 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 ","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603880194935","position":13,"url":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603880194935","name":"13. Comment on the below while statement= while (0 == 0) { }","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"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) {} ","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603880286378","position":14,"url":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603880286378","name":"14. What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":" 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. ","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603880336022","position":15,"url":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603880336022","name":"15. What does the following declaration mean? int (*ptr)[10];","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":" 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 ","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603880403625","position":16,"url":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603880403625","name":"16. In C, if you pass an array as an argument to a function, what actually gets passed?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":" 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. ","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603880449075","position":17,"url":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603880449075","name":"17. Is there any difference int the following declarations? int fun(int arr[]); int fun(int arr[2]);","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":" 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. ","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603880517489","position":18,"url":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603880517489","name":"18. Are the expressions arr and &arr same for an array of 10 integers?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"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. ","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603880564450","position":19,"url":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603880564450","name":"19. Which of the fplowing statements should be used to obtain a remainder after dividing 3.14 by 2.1?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":" 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. ","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603880635008","position":20,"url":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603880635008","name":"20. Is there any difference between following declarations? 1 : extern int fun(); 2 : int fun();","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":" 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. ","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603880813688","position":21,"url":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603880813688","name":"21. What could be the output for following? main() { int a= - - 2; printf(“%d”,a); }","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":" A. 2 B.-2 C. 1 D. Error
--2 is incorrect, // Invalid because lvalue is required to increment ","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603880901481","position":22,"url":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603880901481","name":"22. Predict the output of following code: main() { int i=-1; -i; //No change in value of i printf(“%d,%d”,i,-i); }","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":" A. -1, 1 B. -1, -1 C. 1, 1 D. 0, 1 ","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603880988498","position":23,"url":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603880988498","name":"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); } }","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":" A. Error B. 20,30 C. 20,20 D. Garbage value ","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603881066941","position":24,"url":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603881066941","name":"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 }","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":" A. Error B. 20,30,20 C. 20,20,20 D. Garbage value ","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603881183223","position":25,"url":"https://jobs.cybertecz.in/tcs-nqt-programming-questions-tcs-coding-questions-2021-tcs-coding-questions-2020/#faq-question-1603881183223","name":"25. Predict the output of following code: main() { int i=10; printf(“%d,%d”,++i,++i); }","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":" A. 11,12 B. 12,11 C. 10,11 D. 11,10 ","inLanguage":"en-US"},"inLanguage":"en-US"}]}
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
TCS NQT 2020 Coding Questions With Answers | TCS NQT Programming Logic Questions: Click here
For TCS NQT 2021 Interview Questions, English and Programming Set 1: Click here
For TCS NQT 2021 Interview Questions, English and Programming Set 2: Click here