Application-Layer-Protocol
November 28, 2023
Question 2599 – Data-Structures
November 28, 2023
Application-Layer-Protocol
November 28, 2023
Question 2599 – Data-Structures
November 28, 2023

Question 11189 – Programming

Consider the following C program:

#include <stdio.h>
typedef struct 
{
    char *a;
    char *b;
} t;
void f1(t s);
void f2(t *p);
main()
{
    static t s = {"A", "B"};
    printf ("%s %sn", s.a, s.b);
    f1(s);
    printf ("%s %sn", s.a, s.b);
    f2(&s);
}
void f1(t s)
{
    s.a = "U";
    s.b = "V";
    printf ("%s %sn", s.a, s.b);
    return;
}
void f2(t *p)
{
    p -> a  = "V";
    p -> b = "W";
    printf("%s %sn", p -> a, p -> b);
    return;
} 

What is the output generated by the program?

Correct Answer: B

Question 6 Explanation: 
→ First print AB.
→ f1 is call by value. The changes applicable only for local from f1. UV is printed.
→ Back in main( ), AB is printed.
→ Then in f2, VW is printed.
Hence, answer is (B).
A
AB
UV
VW
VW
B
AB
UV
AB
VW
C
AB
UV
UV
VW
D
AB
UV
VW
UV
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!