Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include void bad_swap(char, char); int main() { char a,b; printf(Enter two characters : ); scanf(%c %c, &a, &b); printf( ); bad_swap(a, b); return 0; }

 image text in transcribed
#include  void bad_swap(char, char); int main() { char a,b; printf("Enter two characters : "); scanf("%c %c", &a, &b); printf(" "); bad_swap(a, b); return 0; } void bad_swap(char a, char b) { char temp = b; b = a; a = temp; }
Problem 1 : The problem_1.c file contains the code for a swap function called bad_swap. Check why the swap function does not work. A) Write a swap function (good_swap) that can swap two character elements using pointers. [5] B) In the main function declare two character variables then print them and their addresses. Now use these variables as parameters and apply the bad_swap and print the results(value of variables and addresses). Do the same with the good_swap and print the results. [5] C) Write a function "reverse" that takes in a word of three letters as user input and reverses it (Swap the first and the last element). [5] Enter two characters : A B Variable var_1 = A has been stored in address = 0060FEEB Variable var_2 = B has been stored in address = 0060FEEA After bad swap (without pointers): var_1 = A, address = 0060FEEB var_2 = B, address = 0060FEEA After good swap (with pointers): var_1 = B, address 0060FEEB var_2 = A, address 0060FEEA Enter a 3 letter word to reverse : BAD Reversed string = DAB execution time : 9.011 s Process returned 0 (0x0) Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago