Question

2 write a void function that accepts two integer pointers and swaps the two integers pointed to by the pointers write the complete function including the function header (15 pts)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Swap function

/*Function Declaration*/

void swap(int* , int*);

/*Function Definition*/

void swap(int *a, int *b){

   int temp;
   temp = *a;
   *a = *b;
   *b = temp;
}

Explanation:

In the above code snippet,

The return type is void and the swap function accepts two integer pointers, *a and *b.

Temperory variable 'temp' is used to swap the integers pointed by pointers.

Program.c

#include<stdio.h>
void swap(int* , int*);
void swap(int *a, int *b){
  
   int temp;
   temp = *a;
   *a = *b;
   *b = temp;
}

void main(){
  
   int value = 2, list = 8;
   int i;
   printf("\nBefore swap\n\n%d : %d\n",value,list);
  
   swap(&value,&list);
  
   printf("\nAfter swap\n\n%d : %d\n",value,list);
}

//Output

Add a comment
Know the answer?
Add Answer to:
Write a void function that accepts two integer pointers and swaps the two integers pointed to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C program to add and subtract any two given integer numbers using pointers

    1- Write a C program to add and subtract any two given integer numbers using pointers.  2- Write a C program to find the factorial using a function and pointers.  3- Write a C program to find the square of an Integer number using a function and pointers.  4- Write a C program to find the area and perimeter of a rectangle using a function and pointers.  5- Write a C program to find the larger of two integers numbers using...

  • C++ Programming 1. Write a function (header and body) that accepts an integer as an argument...

    C++ Programming 1. Write a function (header and body) that accepts an integer as an argument and returns that number squared. 2. Write the code that will fill an integer array named multiples with 10 integers from 5 to 50 that are multiples of five. (This should NOT be in the form of an initialization statement.) 3. Write the code that will display the contents of the integer array named multiples. Recall: the size of the array is 10. 4....

  • Function name: triangular Parameters: integer Returns: a list Description: Write a function called triangular that accepts...

    Function name: triangular Parameters: integer Returns: a list Description: Write a function called triangular that accepts one integer parameter that returns a list with the same number of terms as the value of the parameter. If the parameter is zero or a negative number, you should return an empty list A triangular number is the sum of a positive integer and all the integers before it. The series is as follows: 1, 3, 6, 10, 15, 21,

  • Assignment: Write a C function that accepts the pointer to a matrix of integer numbers (i.e....

    Assignment: Write a C function that accepts the pointer to a matrix of integer numbers (i.e. a two-dimensional array), number of rows and number of columns as input and prints the matrix after rotating it 90 degrees clockwise. Example: void rotate-matrix (int* matrix, int row, int column) Inputs: row 4, column-6 and the pointer to the matrix below: 2 3 6 5 8 0 Output:

  • c++ write a boolean function that accepts two integer arrays of size 10 as input parameters,...

    c++ write a boolean function that accepts two integer arrays of size 10 as input parameters, the function should return true if there are any similar values between the two arrays and shall return false if not, if there are similar values, print out on screen

  • Function with Pointer (C++) 1. The function should be named "myFunction" which takes two pointers to...

    Function with Pointer (C++) 1. The function should be named "myFunction" which takes two pointers to chars and returns void (nothing). 2. The value pointed in the first argument should be copied into the value of the second pointer (and the second to the first). 3. The pointer itself is not copied, just the char it points to. Thanks in advance!

  • Python problem QUESTION 48 Write a function named was that accepts two integer values as arquments...

    Python problem QUESTION 48 Write a function named was that accepts two integer values as arquments and returns the wake that is greater of the two for example, if 7 and 12 are passed as arguments the function should return 12. If the arguments are equal the function should return zero. TTTA 3112) T V 2

  • I am supposed to a pseudocode function named max that accepts two integer values as arguments...

    I am supposed to a pseudocode function named max that accepts two integer values as arguments and returns the value that is greater of the two. Use the function in a program that prompts the user to enter two integer values. The program should display the value that is greater of the two. Is everything correct and complete? //Pseudocode //This function takes two integers as parameters: x and y Begin : Max(x,y) If(x>y) then MAX=x Else MAX=y End if Return...

  • Write a complete program that: 1) declares two local integers x and y 2) defines a...

    Write a complete program that: 1) declares two local integers x and y 2) defines a global structure containing two pointers (xptr,yptr) and an integer (z) 3) Declares a variable (mst) by the type of previous structure 4) requests the values of x and y from the user using only one scanf statement 5) sets the first pointer in the struct to point to x 6) sets the second pointer in the struct to point to y 7) uses the...

  • 2. Write a Marie program that accepts two positive (inputs) two integers and outputs the sum...

    2. Write a Marie program that accepts two positive (inputs) two integers and outputs the sum of both of the integers and all the numbers in between Write a Marie program that determines the largest of a series of positive integers provided by a user. The user will enter a -1 when she is finished. Up to 10 numbers will be provided by the user. Write a Marie program that accepts two positive integers, multiples them by repeated addition, and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT