All mock tests are FREE till 31 December — register to save your progress
Paper 2 CS · UNIT 03

Programming Languages and Computer Graphics – Previous Year Questions

229 questions from past UGC NET Paper 2 – Computer Science papers, each with the correct answer. Open any question for its explanation.

  1. Consider the following C program:#include<stdio.h> int main() { int x[] = {2,4,6,8,10}; int a, b = 0, *y = x + 4; for (a = 0; a < 5; a++) { b = b + (*y - a) - *(y - a); } printf("%d\n", b); return 0; } What will be the…
    Answer: D. 10 Paper 2 CS · June 2024 Re-Exam
  2. Which of the following are TRUE about constructors in C++? (A) A constructor can be overloaded. (B) A constructor does not have a return type. (C) A constructor must be declared as a friend function. (D) A constructor i…
    Answer: D. (A), (B) Only Paper 2 CS · June 2024 Re-Exam
  3. What is the output of the following program?#include<stdio.h> void f1(char *x, char *y) { char *t1; t1 = x; x = y; y = t1; } void f2(char **x, char **y) { char *t1; t1 = *x; *x = *y; *y = t1; } int main() { char *a = "O…
    Answer: A. ONE TWO TWO ONE Paper 2 CS · June 2024 Re-Exam
  4. Which of the following C++ statements correctly declares an abstract class?
    Answer: A. class A { virtual void show() = 0; }; Paper 2 CS · June 2024 Re-Exam
  5. Consider the following C++ program:#include<iostream> using namespace std; void swap(int &x, int &y) { int temp = x; x = y; y = temp; } int main() { int a = 5, b = 10; swap(a, b); swap(a, b); cout << a << " " << b; retu…
    Answer: A. 5 10 Paper 2 CS · June 2024 Re-Exam
  6. What is the output of the code given below?#include<iostream> using namespace std; class Base { public: Base() { cout << "Base Const"; } virtual ~Base() { cout << "Base dest"; } }; class Derived : public Base { public:…
    Answer: A. Base Const Derived Const Derived dest Base dest Paper 2 CS · June 2024 Re-Exam
  7. Consider the following C code:#include<stdio.h> int temp = 0; int fun(int x, int y) { int z; temp++; if (y == 3) return (x*x*x); else { z = fun(x, y/3); return (z*z*z); } } int main() { fun(4, 81); printf("%d", temp); }…
    Answer: B. 4 Paper 2 CS · June 2024 Re-Exam
  8. Match List I with List IIList I List II (A) HTML (I) Allows for dynamic and interactive web pages. (B) DHTML (II) Defines the structure of web pages. (C) XML (III) Object-oriented programming language for web applicatio…
    Answer: C. (A)-(II), (B)-(I), (C)-(IV), (D)-(III) Paper 2 CS · June 2024 Re-Exam
  9. Arrange the following steps of file handling in C in the correct order: (A) Close the file (B) Read from or write to the file (C) Open the file (D) Check for error Choose the correct answer from the options given below:
    Answer: C. (C), (D), (B), (A) Paper 2 CS · June 2024 Re-Exam
  10. What will be the output of the following C code?#include<stdio.h> void main() { int arr[5] = {10,20,30,40,50}; int *p = (int*)(&arr + 1); printf("%d %d", *(arr+1), *(p-1)); }
    Answer: B. 20 50 Paper 2 CS · June 2024 Re-Exam
  11. Find the output of the following code:#include<stdio.h> void main() { int arr[] = {1, 2, 3, 4, 5}; int *p = arr; printf("%d", *p++); printf("%d", *(p+1)); }
    Answer: B. 1, 3 Paper 2 CS · June 2024 Re-Exam
  12. Consider a triangle PQR with coordinates P(0,0), Q(2,2) and R(10,4). If this triangle is to be magnified to four times its size while keeping R(10,4) fixed, then the coordinates of the magnified triangle are:
    Answer: B. P(−30,−12), Q(−22,−4) and R(10,4) Paper 2 CS · December 2023
  13. Which of the following statements is TRUE?
    Answer: C. We can never build an object from a class containing a pure virtual function Paper 2 CS · December 2023
  14. What is the output of the following program?#include<stdio.h> int main() { int i = 3; while (i--) { int i = 10; i--; printf("%d", i); } printf("%d", i); }
    Answer: C. 999-1 Paper 2 CS · December 2023
  15. The hue of a colour is related to its:
    Answer: D. Wavelength Paper 2 CS · December 2023
  16. What is the output of the following program?#include <stdio.h> #define SQR(x) (x*x) int main() { int a, b = 3; a = SQR(b+2); printf("%d", a); return 0; }
    Answer: B. 11 Paper 2 CS · December 2023
  17. Consider the three points P1(1, 2, 0), P2(3, 6, 20) and P3(2, 4, 6) and a viewpoint C(0, 0, −10). Choose the correct options. (A) P1 obscures P2 if viewed from C. (B) P2 obscures P1 if viewed from C. (C) P3 does not obs…
    Answer: B. (A), (C) and (D) Only Paper 2 CS · December 2023
  18. Which of the statements are CORRECT? (A) Constructors are invoked automatically when objects are created. (B) Constructors do not have return types, not even void, and therefore cannot return values. (C) Constructors ca…
    Answer: B. (A), (B) and (C) Only Paper 2 CS · December 2023
  19. Match List I with List IIList I List II (a) Bresenham (I) Hidden surface removal (b) Cohen-Sutherland algorithm (II) Line drawing (c) Sutherland-Hodgeman algorithm (III) Line clipping (d) Z-Buffer algorithm (IV) Polygon…
    Answer: C. (a)-(II), (b)-(III), (c)-(IV), (d)-(I) Paper 2 CS · December 2023
  20. Consider the following code segment:int arr[] = {0,1,2,3,4}; int i = 1, *ptr; ptr = arr + 2; Arrange the following printf statements in increasing order of their output: (a) printf("%d", ptr[i]); (b) printf("%d", ptr[i+…
    Answer: B. (c), (d), (a), (b) Paper 2 CS · December 2023
  21. Statement (I): A friend function and the member functions of a friend class can directly access private and protected data. Statement (II): A friend function can access private data through the member functions of the b…
    Answer: A. Both Statement I and Statement II are correct Paper 2 CS · December 2023
  22. Match List I with List IIList I List II A. Bezier curves I. 3-D objects that have translational/rotational symmetry B. B-Splines II. Fractal geometry C. Sweep representations III. Bias and tension D. Natural objects IV.…
    Answer: C. A-IV, B-III, C-I, D-II Paper 2 CS · June 2023
  23. What will be the output of the following code?#include <stdio.h> int main() { int a, b, c; a = 0x10; b = 010; c = a + b; printf("%d", c); return 0; }
    Answer: B. 24 Paper 2 CS · June 2023
  24. A three-dimensional array in C++ is declared as int A[a][b][c]. Array elements are stored in row-major order and indexing begins from 0. The address of the element A[r][s][t], in terms of the word length w of an integer…
    Answer: B. &A[0][0][0] + w(b·c·r + c·s + t) Paper 2 CS · June 2023
  25. What is the output of the following code?main() { struct s1 { char *z; int i; struct s1 *p; }; static struct s1 a[] = { {"Nagpur", 1, a+1}, {"Raipur", 2, a+2}, {"Kanpur", 3, a} }; struct s1 *ptr = a; printf("%s %s %s\n"…
    Answer: B. Nagpur Nagpur Nagpur Paper 2 CS · June 2023
  26. The Sutherland-Hodgeman method is used on
    Answer: C. Convex polygons Paper 2 CS · June 2023
  27. What is x in the following program?#include <stdio.h> int main() { typedef int (*(*arrfptr[3])())[10]; arrfptr x; return 0; }
    Answer: C. x is an array of three function pointers Paper 2 CS · June 2023
  28. How will you free the memory allocated by the following program?#include <stdio.h> #include <stdlib.h> #define MAXROW 3 #define MAXCOL 4 int main() { int **p, i, j; p = (int **) malloc(MAXROW * sizeof(int*)); return 0; }
    Answer: D. free(p); Paper 2 CS · June 2023
  29. The clipping process in computer graphics is used for
    Answer: D. Removing objects and lines (outside the window) Paper 2 CS · June 2023
  30. Consider the rectangle with vertices (0, 0), (0, 2), (3, 0), (3, 2). It is scaled by 2 along the x-axis and 3 along the y-axis. The new coordinates of the rectangle are
    Answer: C. (0,0), (6,0), (0,6), (6,6) Paper 2 CS · June 2023