Qus : 2
UGC NET Computer Science PYQ
4
What is the output of following code?
main()
{
static float a[] = {13.24, 1.5, 4.5, 5.4, 3.5}
float *j, *k;
j = a;
k = a + 4
j = j * 2;
k = k/2;
printf("% f% f", *j, *k);
}
1
13.25, 4.5 2
1.5, 3.5 3
13.24, 1.5, 4.5, 5.4, 3.5 4
Illegal use of pointer in main function Go to Discussion
UGC NET Computer Science UGC NET PYQ
UGC NET Computer Science UGC NET Computer Science June 2023 (Paper II) PYQ
Solution In C, pointer multiplication and pointer division are not allowed.
Here,
j = j * 2;
and
k = k / 2;
are invalid operations.
Qus : 4
UGC NET Computer Science PYQ
3
Consider the following C-code fragment running on a $32$-bit x86 machine:
typedef struct {
union {
unsigned char a;
unsigned short b;
} U;
unsigned char c;
} S;
S B[10];
S *p = address of B[4];
S *q = address of B[5];
p->U.b = 0x1234;
If $M$ is the value of $q-p$ and $N$ is the value of address of $(p->c)$ minus address of $p$, then $(M,N)$ is:
1
$(1,1)$ 2
$(3,2)$ 3
$(1,2)$ 4
$(4,4)$ Go to Discussion
UGC NET Computer Science UGC NET PYQ
UGC NET Computer Science UGC NET Computer Science June 2019 (Paper II) PYQ
Solution Given that structure $S$ takes $32$ bits.
So,
$32\text{ bits}=4\text{ bytes}$
Now,
$p$ points to $B[4]$
$q$ points to $B[5]$
Since $p$ and $q$ are pointers of type $S$, pointer subtraction gives the difference in number of structures.
So,
$q-p=1$
Therefore,
$M=1$
Now, union $U$ contains $unsigned\ char\ a$ and $unsigned\ short\ b$.
Size of union $U$ is $2$ bytes.
After union $U$, variable $c$ is stored.
So, offset of $c$ from the beginning of structure is $2$ bytes.
Therefore,
$N=2$
Hence,
$(M,N)=(1,2)$
Qus : 7
UGC NET Computer Science PYQ
4
Consider the following C++ function $f()$:
unsigned int f(unsigned int n) {
unsigned int b = 0;
while (n) {
b = b + (n bitwise AND 1);
n = n shifted right by 1;
}
return b;
}
The function $f()$ returns the integer that represents the $P$ in the binary representation of positive integer $n$, where $P$ is:
1
Number of $0$'s 2
Number of bits 3
Number of consecutive $1$'s 4
Number of $1$'s Go to Discussion
UGC NET Computer Science UGC NET PYQ
UGC NET Computer Science UGC NET Computer Science June 2019 (Paper II) PYQ
Solution The expression $n$ bitwise AND $1$ checks the last bit of $n$.
If the last bit is $1$, then $b$ increases by $1$.
After that, $n$ is shifted right by one bit.
So, the loop checks each bit of $n$ one by one.
Therefore, $b$ counts the total number of $1$'s in the binary representation of $n$.
Qus : 9
UGC NET Computer Science PYQ
2
Given
int arr[3][4][2] =
{
{{2,4},{7,8},{3,4},{5,6}},
{{7,6},{3,4},{5,3},{2,3}},
{{8,9},{7,2},{3,4},{5,1}}
};
Which one of the following can be used to refer to element 1 in the above 3-d array?
1
$arr[3][4][2]$ 2
$*(*(*(arr+2)+3)+1)$
3
$*(arr+2)+*(arr+3)+*(arr+1)$ 4
$arr[2][3][2]$ Go to Discussion
UGC NET Computer Science UGC NET PYQ
UGC NET Computer Science UGC NET Computer Science Dec 2022 Shift I (Paper II) PYQ
Solution In C language, array indexing starts from $0$.
The element $1$ is present at:
$arr[2][3][1]$
Now,
$arr+2$ points to the third $2$-D block.
$*(arr+2)$ gives $arr[2]$.
$*(arr+2)+3$ points to $arr[2][3]$.
$*(*(arr+2)+3)$ gives $arr[2][3]$.
$*(*(arr+2)+3)+1$ points to $arr[2][3][1]$.
Therefore,
$*(*(*(arr+2)+3)+1)=arr[2][3][1]=1$
Qus : 10
UGC NET Computer Science PYQ
1
What is the output of following C program?
#include <stdio.h>
main()
{
int i, j, x = 0;
for (i = 0; i < 5; ++i)
for (j = 0; j < i; ++j)
{
x += (i + j - 1);
break;
}
printf("%d", x);
}
1
6 2
5 3
4 4
3 Go to Discussion
UGC NET Computer Science UGC NET PYQ
UGC NET Computer Science UGC NET Computer Science Dec 2019 (Paper II) PYQ
Solution Outer loop runs for:
$i=0,1,2,3,4$
Inner loop runs only when $j<i$.
But inside inner loop, there is a $break$ statement, so inner loop executes only one time for each valid value of $i$.
For $i=0$:
$j<0$ is false, so inner loop does not execute.
For $i=1$:
$x=x+(1+0-1)=0+0=0$
For $i=2$:
$x=x+(2+0-1)=0+1=1$
For $i=3$:
$x=x+(3+0-1)=1+2=3$
For $i=4$:
$x=x+(4+0-1)=3+3=6$
So, final value of $x$ is:
$x=6$
Qus : 11
UGC NET Computer Science PYQ
2
Which of the following statements about pointers in C are TRUE.
(A) Pointers can be used to access array elements
(B) Pointers can store the address of another pointer
(C) Pointers are automatically dereferenced in expression
(D) Pointers cannot be used to access structure members
Choose the correct answer from the options given below :
1
(A) and (C) Only 2
(A) and (B) Only 3
(B) and (C) Only 4
(C) and (D) Only Go to Discussion
UGC NET Computer Science UGC NET PYQ
UGC NET Computer Science UGC NET Computer Science August 2024 (Paper II) PYQ
Solution (A) True — pointers can access array elements because arrays and pointers are closely related in C.
(B) True — a pointer can store the address of another pointer (pointer to pointer).
(C) False — pointers are not automatically dereferenced, we must use *.
(D) False — pointers can access structure members using ->.
Thus correct statements are A and B.
Qus : 14
UGC NET Computer Science PYQ
4
Of the following, which is NOT a logical error?
1
Using the $'='$ instead of $'===' $ to determine if two values are equal 2
Divide by zero 3
Failing to initialize counter and total variables before the body of loop 4
Using commas instead of two required semicolon in a for loop header Go to Discussion
UGC NET Computer Science UGC NET PYQ
UGC NET Computer Science UGC NET Computer Science Sep 2022 (Paper II) PYQ
Solution A logical error means the program runs, but it gives wrong output because the logic is incorrect. Now check each option. Option (a): Using $'='$ instead of $'===' $ for comparison is a logical error. Because $'='$ is used for assignment, while $'===' $ is used for strict comparison. So, this may give wrong result. Option (b): Divide by zero is generally considered a run-time error. The program may stop during execution. Option (c): Failing to initialize counter and total variables before loop execution is a logical error. Because the program may use garbage or incorrect values and produce wrong output. Option (d): Using commas instead of required semicolons in a for loop header is a syntax error. The program will not compile or run properly. Since the question asks which is NOT a logical error, the best answer is syntax error.
Qus : 15
UGC NET Computer Science PYQ
3
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 :
1
(A), (C), (D), (B)
2
(D), (B), (C), (A) 3
(C), (D), (B), (A) 4
(B), (D), (A), (C) Go to Discussion
UGC NET Computer Science UGC NET PYQ
UGC NET Computer Science UGC NET Computer Science August 2024 (Paper II) PYQ
Solution Correct file handling sequence in C:
Open file
Check for error
Read / Write
Close file
Thus order:
(C) → (D) → (B) → (A)
Qus : 16
UGC NET Computer Science PYQ
2
What does the following function $f()$ in C return? int f(unsigned int N) { unsigned int counter = 0; while (N > 0) { counter += N & 1; N = N >> 1; } return counter == 1; }
1
$1$ if $N$ is odd, otherwise $0$ 2
$1$ if $N$ is a power of $2$, otherwise $0$ 3
$1$ if the binary representation of $N$ is all $1$'s, otherwise $0$ 4
$1$ if the binary representation of $N$ has any $1$'s, otherwise $0$ Go to Discussion
UGC NET Computer Science UGC NET PYQ
UGC NET Computer Science UGC NET Computer Science Nov 2021 (Paper II) PYQ
Solution Given function takes an unsigned integer $N$. Inside the function: $counter=0$ Now the loop runs while: $N>0$ In each iteration: $counter += N\ \&\ 1$ Here, $N\ \&\ 1$ checks the last bit of $N$. If the last bit is $1$, then $counter$ increases by $1$. If the last bit is $0$, then $counter$ does not increase. After that: $N=N>>1$ This shifts the bits of $N$ one position to the right. So, the loop checks all bits of $N$ one by one. Therefore, $counter$ stores the number of $1$ bits in the binary representation of $N$. Finally, the function returns: $counter==1$ This condition is true only when the binary representation of $N$ contains exactly one $1$. A number which has exactly one $1$ in binary form is a power of $2$. For example: $2=(10)_2$ $4=(100)_2$ $8=(1000)_2$ So, the function returns $1$ if $N$ is a power of $2$, otherwise it returns $0$.
Qus : 19
UGC NET Computer Science PYQ
3
Which of the following are legal statements in C programming language?
(a) int *P = &44;
(b) int *P = &r;
(c) int P = &a;
(d) int P = a;
1
(a) and (b) 2
(b) and (c) 3
(b) and (d) 4
(a) and (d) Go to Discussion
UGC NET Computer Science UGC NET PYQ
UGC NET Computer Science UGC NET Computer Science Dec 2019 (Paper II) PYQ
Solution Statement (a) is not legal because we cannot take the address of a constant value like $44$.
Statement (b) is legal because if $r$ is an integer variable, then &r gives its address and it can be stored in an integer pointer.
Statement (c) is not legal because &a gives address, but $P$ is declared as normal integer, not pointer.
Statement (d) is legal because if $a$ is an integer variable, then its value can be assigned to integer variable $P$.
So, legal statements are:
(b) and (d)
Qus : 21
UGC NET Computer Science PYQ
1
Consider the operators used in C programming given below:
A. &&
B. +=
C. >>
D. >=
E. ?:
Choose among the following the correct order of precedence of the operators given above (higher to lower):
1
C, D, E, B, A 2
C, A, D, E, B 3
C, D, A, E, B 4
D, C, A, B, E Go to Discussion
UGC NET Computer Science UGC NET PYQ
UGC NET Computer Science UGC NET Computer Science 26 June 2025 (Paper II) PYQ
Solution Operator precedence (highest → lowest) is:
>> (shift) → >= (relational) → ?: (ternary) → += (assignment) → && (logical AND).
Qus : 22
UGC NET Computer Science PYQ
2
#include<stdio.h>
void main()
{
int arr[]={1, 2, 3, 4, 5};
int *p = arr;
printf("%d", *p++);
printf("%d", *(p+1));
} Find the output of the above code?
1
1 , 2 2
1, 3 3
2, 3 4
1 , 4 Go to Discussion
UGC NET Computer Science UGC NET PYQ
UGC NET Computer Science UGC NET Computer Science August 2024 (Paper II) PYQ
Solution Initial:
arr = {1,2,3,4,5}
p → arr[0]
First statement:
*p++
Post-increment
Value printed = *p = 1
Then pointer moves to next element.
Now:
p → arr[1]
Second statement:
*(p+1)
p+1 → arr[2]
Value = 3
Output:
1 3
Qus : 24
UGC NET Computer Science PYQ
1
Consider the following code :
#include<stdio.h>
void f1(char *x, char *y) {
char *t;
t = x;
x = y;
y = t;
}
void f2(char **x, char **y) {
char *t;
t = *x;
*x = *y;
*y = t;
}
int main()
{
char *a = "ONE", *b = "TWO";
f1(a, b);
printf("%s %s", a, b);
f2(&a, &b);
printf("%s %s", a, b);
return 0;
} What will be the output of the above code?
1
ONE TWO TWO ONE 2
TWO ONE ONE TWO 3
ONE TWO ONE TWO 4
TWO ONE TWO ONE Go to Discussion
UGC NET Computer Science UGC NET PYQ
UGC NET Computer Science UGC NET Computer Science August 2024 (Paper II) PYQ
Solution Initial values
a = "ONE"
b = "TWO"
Step 1: f1(a, b)
Function parameters are passed by value.
Inside f1 the pointers swap locally:
x ↔ y
But original variables a and b do not change.
So after f1:
a = ONE
b = TWO
First printf prints:
ONE TWO
Step 2: f2(&a, &b)
Now addresses of pointers are passed.
Inside f2:
t = *x
*x = *y
*y = t
This swaps actual pointers a and b.
After swap:
a = TWO
b = ONE
Second printf prints:
TWO ONE
Qus : 25
UGC NET Computer Science PYQ
2
Consider the following conditional code, which returns Boolean values
if $((x>25) \land (y>100))$
return $false$;
else if $((x \le 25) \land (y \le 100))$
return $true$;
else if $((x>25) \land (y \le 100))$
return $false$;
else
return $true$;
Simplify it by filling in the following blank with a single Boolean expression without changing the behaviour of the conditional code.
if $($ ________ $)$
return $true$;
else
return $false$;
1
$x>25$ 2
$x \le 25$ 3
$y>100$ 4
$y \le 100$ Go to Discussion
UGC NET Computer Science UGC NET PYQ
UGC NET Computer Science UGC NET Computer Science Dec 2022 Shift II (Paper II) PYQ
Solution Given code returns $false$ when:
$((x>25) \land (y>100))$
or
$((x>25) \land (y \le 100))$
So,
$false = (x>25)$
Therefore, the code returns $true$ when:
$x \le 25$
Hence, the required Boolean expression is:
$x \le 25$
Qus : 30
UGC NET Computer Science PYQ
4
What would be the equivalent pointer expression for referring the array element ar[m][n][o]?
*(*(*(ar) + m + n) + o)
(*(*(*(ar + m) + n) + o))
(*(*(ar + m) + n) + o)
*(*(*(ar + m) + n) + o)
1
1 2
2 3
3 4
4 Go to Discussion
UGC NET Computer Science UGC NET PYQ
UGC NET Computer Science UGC NET Computer Science 26 June 2025 (Paper II) PYQ
Solution
Consider ar as a 3-dimensional array declared as:
data_type ar[a][b][c];
Here, the array element ar[m][n][o] can be represented in pointer form as:
*(*(*(ar + m) + n) + o)
Step-by-step understanding:
ar is a pointer to the first 2D array ar[0].
ar + m moves the pointer to the mth 2D array → ar[m].
*(ar + m) gives the address of the first 1D array inside ar[m].
*(ar + m) + n moves to the nth 1D array → ar[m][n].
*(*(ar + m) + n) gives the address of the first element of that 1D array.
*(*(*(ar + m) + n) + o) finally gives the element ar[m][n][o].
✅ Final Answer: *(*(*(ar + m) + n) + o)
Qus : 32
UGC NET Computer Science PYQ
2
Arrange the following in correct order, so that they can follow a proper run time environment :
A. Programming statement
B. Compilation
C. Memory allocation
D. Type of variable
E. Memory deallocation
1
A, B, C, D, E 2
A, B, D, C, E 3
B, A, D, C, E 4
C, D, B, E, A Go to Discussion
UGC NET Computer Science UGC NET PYQ
UGC NET Computer Science UGC NET Computer Science June 2024 (Paper II) PYQ
Solution The correct execution flow in a programming environment is:
Programming statement (A) – Program is written.
Compilation (B) – Code is compiled to machine/intermediate code.
Type of variable (D) – Variables are recognized with their types.
Memory allocation (C) – Memory is allocated during execution.
Memory deallocation (E) – Memory is released after execution.
Thus the correct order is:
Qus : 34
UGC NET Computer Science PYQ
3
Suppose you are compiling on a machine with $1$-byte chars, $2$-byte shorts, $4$-byte ints, and $8$-byte doubles, and with alignment rules that require the address of every primitive data element to be an integer multiple of the element's size. Suppose further that the compiler is not permitted to reorder fields; padding is used to ensure alignment. How much space will be consumed by the following array? struct { short s; char c; short t; char d; double r; int i; } A[10];
1
$150$ bytes 2
$320$ bytes 3
$240$ bytes 4
$200$ bytes Go to Discussion
UGC NET Computer Science UGC NET PYQ
UGC NET Computer Science UGC NET Computer Science Nov 2020 (Paper II) PYQ
Solution $short\ s$: starts at offset $0$, size $2$, next offset $2$ $char\ c$: starts at offset $2$, size $1$, next offset $3$ $short\ t$: needs multiple of $2$, so $1$ byte padding, starts at offset $4$, next offset $6$ $char\ d$: starts at offset $6$, size $1$, next offset $7$ $double\ r$: needs multiple of $8$, so $1$ byte padding, starts at offset $8$, next offset $16$ $int\ i$: needs multiple of $4$, starts at offset $16$, next offset $20$ Struct size must be multiple of maximum alignment $8$. So, $20$ is padded to $24$ bytes. For $A[10]$: $10\times24=240$ bytes
Qus : 35
UGC NET Computer Science PYQ
2
What is the output of 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", a[0].z, ptr -> z, a[2].p -> z);
}
1
Nagpur Raipur Kanpur 2
Nagpur Nagpur Nagpur 3
Kanpur Kanpur Kanpur 4
Error
Go to Discussion
UGC NET Computer Science UGC NET PYQ
UGC NET Computer Science UGC NET Computer Science June 2023 (Paper II) PYQ
Solution a[0].z = Nagpur
ptr = a, so ptr -> z = a[0].z = Nagpur
a[2].p = a, so a[2].p -> z = a[0].z = Nagpur
Final Answer: (b) Nagpur Nagpur Nagpur
Qus : 36
UGC NET Computer Science PYQ
1
Consider the following recursive Java function $f$ that takes two long arguments and returns a float value: public static float f(long m, long n) { float result = (float)m / (float)n; if (m < 0 || n < 0) return 0.0f; else result -= f(m * 2, n * 3); return result; } Which of the following real values best approximates the value of $f(1,3)$?
1
0.2 2
0.4 3
0.6 4
0.8 Go to Discussion
UGC NET Computer Science UGC NET PYQ
UGC NET Computer Science UGC NET Computer Science Nov 2020 (Paper II) PYQ
Solution $f(1,3)=\frac{1}{3}-f(2,9)$ $=\frac{1}{3}-\frac{2}{9}+\frac{4}{27}-\frac{8}{81}+\cdots$ This is a geometric series with first term $\frac{1}{3}$ and common ratio $-\frac{2}{3}$. Sum: $\frac{\frac{1}{3}}{1-(-\frac{2}{3})}=\frac{\frac{1}{3}}{\frac{5}{3}}=\frac{1}{5}=0.2$
Qus : 38
UGC NET Computer Science PYQ
4
In what sequence the initialization, testing and execution of body is done while using do-while loop?
I. Commenting
II. Execution of the body
III. Initialisation
IV. Testing the condition
Choose the correct answer from the following:
1
IV, II, III 2
IV, III, II 3
III, I, II 4
III, II, IV Go to Discussion
UGC NET Computer Science UGC NET PYQ
UGC NET Computer Science UGC NET Computer Science Dec 2022 Shift II (Paper II) PYQ
Solution In a do-while loop, initialization is done first.
Then the loop body executes at least once.
After executing the body, the condition is tested.
So, correct order is:
Initialisation → Execution of the body → Testing the condition
That is:
III, II, IV
[{"qus_id":"14531","year":"2025"},{"qus_id":"14991","year":"2025"},{"qus_id":"14995","year":"2025"},{"qus_id":"15022","year":"2025"},{"qus_id":"15025","year":"2025"},{"qus_id":"15029","year":"2025"},{"qus_id":"17385","year":"2024"},{"qus_id":"17455","year":"2024"},{"qus_id":"17501","year":"2024"},{"qus_id":"17510","year":"2024"},{"qus_id":"17516","year":"2024"},{"qus_id":"17530","year":"2024"},{"qus_id":"17537","year":"2024"},{"qus_id":"17541","year":"2024"},{"qus_id":"17558","year":"2024"},{"qus_id":"17560","year":"2024"},{"qus_id":"17578","year":"2024"},{"qus_id":"18409","year":"2023"},{"qus_id":"18410","year":"2023"},{"qus_id":"18414","year":"2023"},{"qus_id":"18436","year":"2023"},{"qus_id":"18467","year":"2023"},{"qus_id":"18508","year":"2022"},{"qus_id":"18602","year":"2020"},{"qus_id":"18608","year":"2020"},{"qus_id":"18676","year":"2022"},{"qus_id":"18729","year":"2022"},{"qus_id":"18730","year":"2022"},{"qus_id":"18806","year":"2022"},{"qus_id":"18812","year":"2021"},{"qus_id":"18921","year":"2020"},{"qus_id":"18922","year":"2020"},{"qus_id":"18919","year":"2020"},{"qus_id":"19024","year":"2019"},{"qus_id":"19082","year":"2019"},{"qus_id":"19239","year":"2019"},{"qus_id":"19240","year":"2019"},{"qus_id":"19242","year":"2019"}]