Initializing Numeric Variables getch() scanf() #define, When any variable is declared, the compiler is instructed to set aside storage space for the variable. However, the value stored in that space, the value of the variable, is not defined. It might be zero, or it might be some random "garbage" value.

Data Recovery PRO DATA DOCTOR

Home | Order Online | Downloads | Contact Us | Software Knowledgebase

it | es | pt | fr | de | jp | kr | cn | ru | nl | gr


Initializing Numeric Variables

When any variable is declared, the compiler is instructed to set aside storage space for the variable. However, the value stored in that space, the value of the variable, is not defined. It might be zero, or it might be some random "garbage" value. Before using a variable, you should always initialize it to a known value. Let us take this example:

int count; /* Set aside storage space for count */
count = 0; /* Store 0 in count */

This statement uses the equal sign (=), which is C's assignment operator. You can also initialize a variable when it's declared. To do so, follow the variable name in the declaration statement with an equal sign and the desired initial value:

int count = 0;
double rate = 0.01, complexity = 28.5;

Be careful not to initialize a variable with a value outside the allowed range. Here are two examples of out-of-range initializations:
int amount = 100000;
unsigned int length = -2500;

The C compiler does not catch such errors. Your program may compile and link, but you may get unexpected results when the program is run.

Let us take the following example to calculate the total number of sectors in a Disk:

// Model Program To Calculate Sectors in A Disk //

#include<stdio.h>
#define SECTOR_PER_SIDE 63
#define SIDE_PER_CYLINDER 254

void main()
{

int cylinder=0;

clrscr();
printf("Enter The No. of Cylinders in the Disk \n\n\t");
scanf("%d",&cylinder); // Get the value from the user //

printf("\n\n\t Total Number of Sectors in the disk = %ld", (long)SECTOR_PER_SIDE*SIDE_PER_CYLINDER* cylinder);
getch();
}

The output of the program is as follows:

Enter The No. of Cylinders in the Disk
1024
Total Number of Sectors in the disk = 16386048

In this example we see three new things to learn. #define is used to use symbolic constants in the program or in some cases to save time by defining long words in small symbols.

Here we have defined the number of sectors per side that is 63 as SECTOR_PER_SIDE to make the program easy to understand. The same case is true for #define SIDE_PER_CYLINDER 254. scanf() is used to get the input from the user.

Here we are taking the number of cylinders as input from the user. * is used to multiply two or more value as shown in the example.

getch() function basically gets a single character input from the keyboard. By typing getch(); here we stop the screen until any key is hit from the keyboard.

Sample Chapters from book DATA RECOVERY WITH AND WITHOUT PROGRAMMING by Author Tarun Tyagi
Data Recovery with & without Programming


Publishers of the Book
Number of Pages
ISBN
Price of the Book


BPB Publications, New Delhi, India
540
81-7656-922-4
$69.00 (Including Shipping Charges, Cost of Book and Other expenses, Free Source Code CD included with the Book)





Buy Data recovery Book

Previous page

page 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20

 
 

page 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37

 
 

page 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54

 
 

page 55 | 56 | 57 | 58 | 59 | 60

Next page

© Copyright 2002-2005 DataDoctor.Biz

Home | Contact us | Downloads | Services | Terms and conditions | Site map

Website Data Recovery | recuperación de Datos | Récupération de données | Datenrettung | Recupero dati | データ復旧 | 데이터 복구 | 数据恢复 | Восстановление данных | De terugwinning van gegevens | Ανάκτηση δεδομένων
Sitemap Site map1 2 3 4 | Spanish1 2 3 | French1 2 3 | German1 2 3 | Italian1 2 3 | Portuguese1 2 3 | Japanese1 2 3 | Korean1 2 3 | Chinese1 2 3 | Russian1 2 3 | Dutch1 2 3 | Greek1 2 3
Data Recovery Book English | Spanish | French | German | Italian | Portuguese | Japanese | Korean | Chinese | Russian | Dutch | Greek