C Tutorial/Data Type/Double
Get size and address for a double
<source lang="cpp">#include<stdio.h> int main(void) {
double d = 4.0; double e = 5.0; double f = 6.0; printf("\n\nA variable of type double occupies %d bytes.", sizeof(double)); printf("\nHere are the addresses of some variables of type double:"); printf("\nThe address of d is: %p The address of e is: %p", &d, &e); printf("\nThe address of f is: %p\n", &f); return 0;
}</source>
A variable of type double occupies 8 bytes. Here are the addresses of some variables of type double: The address of d is: 9a378 The address of e is: 9a370 The address of f is: 9a368
Use sscanf to get and then double a number from the user
<source lang="cpp">#include <stdio.h>
int main() { char line[100]; int value; printf("Enter a value: "); fgets(line, sizeof(line), stdin); sscanf(line, "%d", &value); printf("Twice %d is %d\n", value, value * 2); return (0); }</source>
Enter a value: 123 Twice 123 is 246