Dillon Richardson Dillon Richardson - 1 month ago 7
C Question

can't change value of variable unless you do the command strcpy

I am reading the "C programming book" and I understand how this program functions, but, I don't understand one thing.

I don't understand how fahr is functioning as a variable.
does fahr have two values or one? Cause I thought once you write a value for a variable you can't change it unless you do the command strcpy. Maybe I am wrong, can some one help me clarify?


#include <stdio.h>
#include <stdlib.h>

int main()
float fahr, celsius;
int lower,upper, step;

lower = 0;
upper = 700;
step = 2;

fahr = lower;
while (fahr <= upper) {
celsius = (5.0/9.0) * (fahr-32.0);
printf("%3.0f \t %6.1f\n", fahr, celsius);
fahr = fahr + step;


When you declare a variable for example float fahr you define a memory space in which will be saved the number that you give to your variable. The content of the the variable fahr can change with an assignment expression such as float = lower where now the content of fahr is the same with the content of lower variable .You can assign values to a variable as many times you want. Assigning a value to a variable has nothing to do with strcpy .strcpy is a function that copies one string to another for example:

char src[40];

 strcpy(src, "This is a sentence ");