Application-Layer-Protocol
November 28, 2023Question 2599 – Data-Structures
November 28, 2023Question 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).
→ 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).
AB
UV
VW
VW
UV
VW
VW
AB
UV
AB
VW
UV
AB
VW
AB
UV
UV
VW
UV
UV
VW
AB
UV
VW
UV
UV
VW
UV
Subscribe
Login
0 Comments