Aspire Faculty ID #17578 · Topic: UGC NET Computer Science August 2024 (Paper II) · Just now
UGC NET Computer Science August 2024 (Paper II)

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?

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

Previous 10 Questions — UGC NET Computer Science August 2024 (Paper II)

Nearest first
1
How does a relational database ensure data integrity?
Topic: UGC NET Computer Science August 2024 (Paper II)
2
40 software professionals were interviewed for a job.25 knew PYTHON, 20 knew JAVA and 7 knew neither language.How many …
Topic: UGC NET Computer Science August 2024 (Paper II)
3
Match List – I with List – II.&nbsp;List – I&nbsp;List – II&nbsp;(A) Natural language processing&nbsp;(I) A method of t…
Topic: UGC NET Computer Science August 2024 (Paper II)
4
Match List – I with List – II.&nbsp;List – I (Counter)&nbsp;List – II (uses/working)&nbsp;(A) N-bit Ring Counter&nbsp;(…
Topic: UGC NET Computer Science August 2024 (Paper II)
5
A CPU has a 5-stage pipeline with the following stages: Fetch (F), Decode (D), Execute (E), Memory (M) and Write-back (…
Topic: UGC NET Computer Science August 2024 (Paper II)
6
A vector processor with 16 lanes can perform an operation on 1024 elements in which each operation takes 5 clock cycles…
Topic: UGC NET Computer Science August 2024 (Paper II)
7
In Software configuration management, what is the primary purpose of version control?
Topic: UGC NET Computer Science August 2024 (Paper II)
8
(A) In IPv4 addressing, a block of address can be define as $x.y.z.t/n$ in which $x,y,z,t$ define one of the address an…
Topic: UGC NET Computer Science August 2024 (Paper II)
9
Which of the following statements are TRUE about Privileged Instructions?(A) It can only be executed by the Operating S…
Topic: UGC NET Computer Science August 2024 (Paper II)
10
Arrange the following stages of a Turing Machine (TM) operation in the correct order as they occur during computation.(…
Topic: UGC NET Computer Science August 2024 (Paper II)

Next 10 Questions — UGC NET Computer Science August 2024 (Paper II)

Ascending by ID
1
Read the below passage and answer the questions.Artificial Neural Networks (ANNs) are computational models inspired by …
Topic: UGC NET Computer Science August 2024 (Paper II)
2
Read the below passage and answer the questions.Artificial Neural Networks (ANNs) are computational models inspired by …
Topic: UGC NET Computer Science August 2024 (Paper II)
3
Read the below passage and answer the questions.Artificial Neural Networks (ANNs) are computational models inspired by …
Topic: UGC NET Computer Science August 2024 (Paper II)
4
Read the below passage and answer the questions.Artificial Neural Networks (ANNs) are computational models inspired by …
Topic: UGC NET Computer Science August 2024 (Paper II)
5
Read the below passage and answer the questions.Artificial Neural Networks (ANNs) are computational models inspired by …
Topic: UGC NET Computer Science August 2024 (Paper II)
6
The Banker’s Algorithm is a critical deadlock avoidance method used in operating systems. It is designed to ensure that…
Topic: UGC NET Computer Science August 2024 (Paper II)
7
The Banker’s Algorithm is a critical deadlock avoidance method used in operating systems. It is designed to ensure that…
Topic: UGC NET Computer Science August 2024 (Paper II)
8
The Banker’s Algorithm is a critical deadlock avoidance method used in operating systems. It is designed to ensure that…
Topic: UGC NET Computer Science August 2024 (Paper II)
9
The Banker’s Algorithm is a critical deadlock avoidance method used in operating systems. It is designed to ensure that…
Topic: UGC NET Computer Science August 2024 (Paper II)
10
The Banker’s Algorithm is a critical deadlock avoidance method used in operating systems. It is designed to ensure that…
Topic: UGC NET Computer Science August 2024 (Paper II)
Ask Your Question or Put Your Review.

loading...