Write a code snippet to declare and accept an integer and calculate the cube value of the integer. The integer should be passed by reference to a function cube(). The function would calculate the result of cubing the integer.

The function prototype to be used is: void cube (int *p);

Sample input-output
Please enter an integer: 2
The cube of integer 2 is 8

4 Years
Discussion Span
Last Post by Daisy_1

A mild hint to help you along ...

// FuncByRef2.c
// pass function arguments by reference using pointers

#include <stdio.h>

void swap(int *x, int *y)
  int temp = *x;
  *x = *y;
  *y = temp;

int main()
  int x = 6, y = 10;

  printf("Before swap(), x = %d and y = %d\n\n", x, y);
  swap(&x, &y);
  printf("After swap(), x = %d and y = %d\n\n", x, y);

  getchar();  // console wait
  return 0;
Votes + Comments
LOL - you are evit vegaseat! :-)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.