A Variable Is A Named Memory Location in - The Contents of A Variable Can Change, Thus - User Defined
A Variable Is A Named Memory Location in - The Contents of A Variable Can Change, Thus - User Defined
A variable is a named memory location in which data of a certain type can be stored. The contents of a variable can change, thus the name. User defined variables must be declared before they can be used in a program. It is during the declaration phase that the actual memory for the variable is reserved.
The declaration of variables is done after the opening brace of main(). main( ) { int sum; The basic format for declaring variables is data_type var, var, ;
where data_type is one of the four basic types, an integer, character, float, or double type. Examples are int i,j,k; float length,height; char midinit;
Initializing Variables
C Variables may be initialized with a value when they are declared. Consider the following declaration, which declares an integer variable count which is initialized to 10. int count = 10;
EXERSICE
Based on previous example, initializing three fixed variable used in Electrical Engineering. For example, one coulomb of charges equal to 6.241 x 10 power 18 electrons. You may search in IE. [ 10 minutes]
Basic Input
An integer called pin is defined. A prompt to enter in a number is then printed with the first printf statement. The scanf routine, which accepts the response, has a control string and an address list. In the control string, the format specifier %d shows what data type is expected. The &pin argument specifies the memory location of the variable the input will be placed in.
After the scanf routine completes, the variable pin will be initialized with the input integer. This is confirmed with the second printf statement. The & character has a very special meaning in C. It is the address operator. (Much more with & when we get to pointers)
Quiz 3