C examples for Language Basics:scanf
When to use & with scanf
#include <stdio.h> int main(void){ int age; // w w w.j a v a 2 s . c om float assets; char pet[30]; // string printf("Enter your age, assets, and favorite pet.\n"); scanf("%d %f", &age, &assets); // use the & here scanf("%s", pet); // no & for char array printf("%d $%.2f %s\n", age, assets, pet); return 0; }