input.c 416 B

123456789101112131415
  1. // input.c -- when to use &
  2. #include <stdio.h>
  3. int main(void)
  4. {
  5. int age; // variable
  6. float assets; // variable
  7. char pet[30]; // string
  8. printf("Enter your age, assets, and favorite pet.\n");
  9. scanf("%d %f", &age, &assets); // use the & here
  10. scanf("%s", pet); // no & for char array
  11. printf("%d $%.2f %s\n", age, assets, pet);
  12. return 0;
  13. }