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

Do you know how to declare an int?

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;
}
commented: LOL - you are evit vegaseat! :-) +12

@vegaseat Thank you for the Code .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.