Exercise 2: Write, compile and execute the program below. Explain why the function swap does not work properly. Using pointers, change the program to make the function swap to work properly. Code: #include #include void swap (int a, int b); int main() int c = 10, d = 25; printf("\nBefore calling the function swap, c=%d and d=%d", c, d); Swap (c, d); printf("\nAfter calling the function swap, c=%d and d=%d\n", c, d); return 0; void swap(int a, int b) { int temp; temp - a; a = b; temp;

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section7.4: Arrays As Arguments
Problem 5E
icon
Related questions
Topic Video
Question

By using C language and pointers

Exercise 2:
Write, compile and execute the program below. Explain why the function swap does not
work properly. Using pointers, change the program to make the function swap to work
properly.
Code:
#include <stdio.h>
#include <stdlib.h>
void swap (int a, int b);
int main()
{
int c = 10, d = 25;
printf("\nBefore calling the function swap, c=%d and d=%d", c, d);
swap (c,d);
printf("\nAfter calling the function swap, c=%d and d=%d\n", c, d);
return 0;
void swap (int a, int b)
{
int temp;
temp = a;
a = b;
b = temp;
Transcribed Image Text:Exercise 2: Write, compile and execute the program below. Explain why the function swap does not work properly. Using pointers, change the program to make the function swap to work properly. Code: #include <stdio.h> #include <stdlib.h> void swap (int a, int b); int main() { int c = 10, d = 25; printf("\nBefore calling the function swap, c=%d and d=%d", c, d); swap (c,d); printf("\nAfter calling the function swap, c=%d and d=%d\n", c, d); return 0; void swap (int a, int b) { int temp; temp = a; a = b; b = temp;
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Instruction Format
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning