TGPSC HMWSSB Manager Programming in C, C++ & Java previous year questions with answers
Every Programming in C, C++ & Java question asked in the TGPSC HMWSSB Manager (Engineering) papers on this site, grouped by topic. Answers come from TSPSC's final key; each has a short explanation (free here for a sample, all of them in the practice app).
Practise Programming in C, C++ & Java onlineC Programming
Consider the following sequence of C language statements.
typedef int * IntegerPointer IntegerPointer A,B; A= (IntegerPointer) malloc(sizeof(int)); B= (IntegerPointer) malloc(sizeof(int)); *A = 5; *B = 17; free (A); A=B; free (B);
The above situation wherein A contains a pointer pointing to the location that B's pointer used to point to is known as
- dangling pointer
- side effect
- null pointer
- free pointer
Show answer
Answer: (1) dangling pointer
Explanation: open it in the practice app. It needs the ₹149 All-in-One Pass: one payment for every exam on the site.
What is the output of following C language code?
#include <stdio.h> int main ( ) { static int i = 1; tun (i); tun (i); tun (i); printf("%d", i); } tun (int i) { i++; }- 1
- 2
- 3
- 4
Show answer
Answer: (1) 1
Explanation: open it in the practice app. It needs the ₹149 All-in-One Pass: one payment for every exam on the site.
Consider the following C program:
main() { int x=5; printf("%d,%d,%d\n",x,x<<2,x>>2); }What could be the output of the above program?
- 5,20,5
- 4,4,1
- 5,20,1
- 20,20,5
Show answer
Answer: (3) 5,20,1
Explanation: open it in the practice app. It needs the ₹149 All-in-One Pass: one payment for every exam on the site.
According to the precedence defined in the C language, arrange the operators ., ||, <, = in the ascending order of precedence.
- ., ||, <, =
- =, <, ||, .
- =, ||, <, .
- <, ||, =, .
Show answer
Answer: (3) =, ||, <, .
Explanation: open it in the practice app. It needs the ₹149 All-in-One Pass: one payment for every exam on the site.
What is the output of the following programming C language code?
for (i=1;i<5;++i) if(i==3) continue; else printf("%d", i);- 1 2 4 5
- 1 2 4
- 2 4 5
- 3 3 3
Show answer
Answer: (2) 1 2 4
Explanation: open it in the practice app. It needs the ₹149 All-in-One Pass: one payment for every exam on the site.
If n has the value 3, then the statement a[++n]=n++ results in _____
- a[5]=3
- a[5]=4
- a[4]=4
- a[4]=3
Show answer
Answer: (1) a[5]=3
Explanation: open it in the practice app. It needs the ₹149 All-in-One Pass: one payment for every exam on the site.
Aliasing in the context of programming languages refers to
- Multiple variables having the same memory location
- Multiple variables having the same value
- Multiple variables having the same identifier
- Multiple use of the same variable
Show answer
Answer: (1) Multiple variables having the same memory location
Explanation: open it in the practice app. It needs the ₹149 All-in-One Pass: one payment for every exam on the site.
Consider the following C program
int x; main() { int x=0; { int x=10; x++; change_x(x); x++; modify_x(); printf("%d ",x); } x++; change_x(x); printf("%d ",x); modify_x(); printf("%d\n",x); } modify_x() { return (x+=10); } change_x() { return(x+=1); }What would be the output of the above program?
- 23 14 24
- 23 1 1
- 13 1 1
- 12 1 1
Show answer
Answer: (4) 12 1 1
Explanation: open it in the practice app. It needs the ₹149 All-in-One Pass: one payment for every exam on the site.
Consider the following C declaration
int (*f)();
Which of the following statements correctly interprets the above declaration?
- f is a function which returns an integer
- f is a function which returns a pointer to an integer
- f is a function to pointer which returns an integer
- f is pointer to a function which returns an integer
Show answer
Answer: (4) f is pointer to a function which returns an integer
Explanation: open it in the practice app. It needs the ₹149 All-in-One Pass: one payment for every exam on the site.
Object-Oriented Programming
Which one of the following statements is correct?
- Abstraction is the classification of objects, grouped according to their significant similarities
- Abstraction is the classification of objects, grouped according to their significant differences
- Abstraction is the classification of objects, grouped according to their names
- Abstraction is hiding information inside a class so that it can only be known in an abstract manner
Show answer
Answer: (4) Abstraction is hiding information inside a class so that it can only be known in an abstract manner
Explanation: open it in the practice app. It needs the ₹149 All-in-One Pass: one payment for every exam on the site.