

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Solution (a) #include "stdafx.h" #include<stdio.h> int swap1(int a, int b); int main(int agrc, char *argv[]) { int a=5,b=6; printf ("before swaping"); printf("\n a=%d",a); printf("\n b=%d",b); swap1(a, b); printf("\n After swapping"); printf("\n a=%d",a); printf("\n b=%d",b); return 0; } int swap1(int a, int b) { int c=0; c=a; a=b; b=c; return; }
Solution (b) #include "stdafx.h" #include<stdio.h> int swap1(int &a, int &b); int main(int agrc, char *argv[]) { int a=5,b=6; printf ("before swaping"); printf("\n a=%d",a); printf("\n b=%d",b); swap1(&a, &b); printf("\n After swapping"); printf("\n a=%d",a); printf("\n b=%d",b); return 0; } int swap1(int *a, int b) { int c=0; c=a; a=b; *b=c; return; } TASK # Make a program that swaps two strings of character type by calling a function swap1. Strings carry the names of the students then pass them to a function by reference. TASK# Make a program that swaps two structures of students then pass there values to the function by reference.. Struct student { int id=10; char name[ ]; }